function main_window (_url)
{
    var myWindow = window.open (_url, Math.round(Math.random()*10000), "location=0,resizable=yes,scrollbars=yes,status=0,width=700,height=650,left=0, top=0,screenX=0,screenY=0");
    if (navigator.appName=='Netscape') { myWindow.focus(); }
}

function main_window_mini (_url)
{
    _name = Math.round(Math.random()*10000);
    var myWindow = window.open (_url, _name, "location=0,resizable=yes,scrollbars=yes,status=0,width=500,height=320,left=30, top=30,screenX=30,screenY=30");
    if (navigator.appName=='Netscape') { myWindow.focus(); }
}

function sure()
{
    return confirm("Are you sure?");
}

function editArticle(id)
{
    main_window('/admin/edit_article.php/'+id);
}

function copyData(object)
{
    var sform = document.regform;
    if (object.checked)
    {
        sform.mail_address.value = sform.address.value;
        sform.mail_city.value = sform.city.value;
        sform.mail_state.value = sform.state.value;
        sform.mail_zip.value = sform.zip.value;
        sform.mail_country.value = sform.country.value;
    }
}

function checkVote()
{
    var sform = document.voteform;
    var flag = 1;
    for (i=0;i<document.voteform.rate.length;i++)
    {
        if (document.voteform.rate[i].checked)
        {
            flag = 0;
            break;
        }
    }
    if (flag)
    {
        alert("Please, choose a number");
        return false;
    }
}

function rateArticle(id)
{
    main_window_mini('/article_rate.php/'+id);
}

function viewRate(id)
{
     openWin(_tbase + '/admin/view_rate.php/category_'+id, 300, 200);
}

function copySubject(ssubject, dsubject, sid, did)
{
    dsubject.value = 'Re: '+ssubject.value;
    did.value = sid.value;
}

function viewComment(id)
{
    main_window('/admin/view_comment.php/article_'+id);
}

function editComment(id)
{
    openWin(_tbase + 'admin/edit_comment.php/comment_'+id, 600, 470);
	return false;
}

function viewVersion(id)
{
    main_window_mini('/admin/view_version.php/'+id);
}

function checkCompareVersions(art_id)
{
    var compareform = document.compareform;
    var version1;
    var version2;
    var count = 0;
    for (var i=0;i<compareform.elements['version'].length;i++)
    {
        if (compareform.elements['version'][i].checked)
        {
            count ++;
            if (!version1)
            {
                version1 = compareform.elements['version'][i].value;
            }
            else
            {
                if (!version2)
                {
                    version2 = compareform.elements['version'][i].value;
                }
            }
        }
    }
    if (count != 2)
    {
        alert("You must select to two versions to compare");
        return false;
    }
    var _name = Math.round(Math.random()*10000);
    var myWindow = window.open ('', _name, "location=0,resizable=yes,scrollbars=no,status=0,width=1000,height=700,left=0, top=0,screenX=0,screenY=0");
    compareform.target = _name;
    compareform.action = "/admin/view_compare.php/article_" + art_id + "/v1_" + version1 + "/v2_" + version2;
    myWindow.focus();
    compareform.submit();
    return false;
}

function fillCompare()
{
    var obj1 = document.getElementById("ver1");
    var obj2 = document.getElementById("ver2");
    obj1.innerHTML = document.getElementById('content1').value;
    obj2.innerHTML = document.getElementById('content2').value;
}

function syncWindow2()
{
    document.getElementById("ver2").scrollTop = document.getElementById("ver1").scrollTop;
    document.getElementById("ver2").scrollLeft = document.getElementById("ver1").scrollLeft;
}

function syncWindow()
{
    document.getElementById("ver1").scrollTop = document.getElementById("ver2").scrollTop;
    document.getElementById("ver1").scrollLeft = document.getElementById("ver2").scrollLeft;
}

function viewMessage(id)
{
    main_window_mini('/author/view_message.php/'+id);
}

function viewMessageAdmin(id)
{
    main_window_mini('/admin/view_message.php/'+id);
}

function replyMessage(id, msg)
{
    var sform = document.commform;
    sform.message_id.value = id;
    sform.subject.value='Re: '+msg;
    sform.subject.focus();
}

function replyMessageAdmin(id)
{
    main_window('/admin/view_author_com.php/'+id);
}

function viewGroup(nGroupId)
{
    pageUrl = base + 'view_group.php/group_' + nGroupId;
    name = 'group_' + nGroupId;
    var myWindow = window.open (pageUrl, 'name', 'location=0,resizable=yes,scrollbars=yes,status=0,width=500,height=500,left=30, top=30,screenX=30,screenY=30');
    if (navigator.appName=='Netscape') { myWindow.focus(); }
}

function rateArticle(nArticleId)
{
    pageUrl = base + 'article_rate.php/article_' + nArticleId;
    name = 'rating_' + nArticleId;
    var myWindow = window.open (pageUrl, 'rate'+nArticleId, 'location=0,resizable=yes,scrollbars=yes,status=0,width=500,height=200,left=30, top=30,screenX=30,screenY=30');
    if (navigator.appName=='Netscape') { myWindow.focus(); }
}

function addEditor()
{
    pageUrl = base + 'add_editor.php';
    var myWindow = window.open (pageUrl, 'new_editor', 'location=0,resizable=yes,scrollbars=yes,status=0,width=800,height=600,left=30, top=30,screenX=30,screenY=30');
    if (navigator.appName=='Netscape') { myWindow.focus(); }
}

function youasure()
{
	return confirm('Are you sure?');
}

function openimage(imagetitle, image, w, h)
{
    if (!w){w=200};
    if (!h){h=300};
    if (w>800) {w=800};
    if (h>600) {h=600};
	w = w+40;
	h = h+80;
    var win1 = open("", "_blank", "toolbar=0,status=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width="+w+",height="+h);
    win1.document.open();
    win1.document.write("<html><head><title>"+imagetitle+"</title><link rel=stylesheet href=css/style.css></head>\n");
    win1.document.write("<body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0><table width=100% height=100% cellpadding=0 cellspacing=5>\n");
    win1.document.write("<tr><td align=center><img src='"+image+"' border=0></td></tr>\n");
    win1.document.write("<tr><td align=center><a href=javascript:window.close()>Close the window</a></td></tr>\n");
    win1.document.write("</table></body></html>");
    return false;
}

function viewAuthor(id)
{
    openWin(_tbase + 'admin/view_author.php/author_' + id, 700, 680);
	return false;
}


function previewArticle(id)
{
    openWin(_tbase + 'admin/preview_article.php/article_' + id, 800, 700);
	return false;
}

function previewArticleRevision(id, rid)
{
    openWin(_tbase + 'admin/preview_article.php/article_' + id + '/revision_' + rid, 800, 700);
	return false;
}

function viewEditor(nEditorId)
{
    openWin(_tbase + 'admin/view_editor.php/editor_' + nEditorId, 700, 600);    
	return false;
}

function changeBio()
{
	openWin(_tbase + 'account/edit_bio.php', 450, 250);
	return false;
} 

function changeNewBioAdmin(id)
{
	openWin(_tbase + 'admin/edit_bio.php/action_newbio/author_' + id, 450, 250);
    return false;
}

function changeBioAdmin(id)
{
	openWin(_tbase + 'admin/edit_bio.php/action_bio/author_' + id, 450, 250);
	return false;
} 

function viewArticleList(id)
{
	openWin(_tbase + 'admin/view_article_list.php/category_' + id, 700, 400);
	return false;
}

function viewSubscriber(id)
{
	openWin(_tbase + 'admin/view_subscriber.php/subscriber_' + id, 400, 400);
	return false;
}

function viewComments(id)
{
	openWin(_tbase + 'admin/view_comment.php/article_' + id, 770, 400);
	return false;
}

function openWin (_url, width, height)
{
	_name = Math.round(Math.random()*10000);

    var myWindow = window.open (_url, _name, "location=0,resizable=yes,scrollbars=yes,status=0,width="+width+",height="+height+"");
    myWindow.focus();
}

function checkGroup(sArticles, sCreated, sRating, sBalance, sRate)
{
  var sGroupError = '';
  sMessage1  = 'Field "';
  sMessage2  = '" "from" must be less or equal field "to"' + "\n";

  if (document.getElementById('frm2').value > document.getElementById('to2').value && document.getElementById('to2').value != '')
  {
      sGroupError = sGroupError + sMessage1 + sArticles + sMessage2;
  }

  if (document.getElementById('frm3').value > document.getElementById('to3').value && document.getElementById('to3').value != '')
  {
      sGroupError = sGroupError + sMessage1 + sCreated + sMessage2;
  }

  if (document.getElementById('frm4').value > document.getElementById('to4').value && document.getElementById('to4').value != '')
  {
      sGroupError = sGroupError + sMessage1 + sRating + sMessage2;
  }

  if (document.getElementById('frm5').value > document.getElementById('to5').value && document.getElementById('to5').value != '')
  {
      sGroupError = sGroupError + sMessage1 + sBalance + sMessage2;
  }

  if (document.getElementById('frm6').value > document.getElementById('to6').value && document.getElementById('to6').value != '')
  {
      sGroupError = sGroupError + sMessage1 + sRate + sMessage2;
  }

  if (sGroupError.length != 0)
  {
      alert(sGroupError);
	  return true;
  }
  else
  {
      return false;;
  }
}

