var winScroller;
window.addEvent("domready", function(){
        winScroller = new Fx.Scroll(window, { duration: 1500 });
});

var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}
function myXMLHttpRequest() {
  var xmlhttplocal;
  try {
    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
    xmlhttplocal=false;
  }
 }

if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
 try {
  var xmlhttplocal = new XMLHttpRequest();
 } catch (e) {
  var xmlhttplocal=false;
  alert('couldn\'t create xmlhttp object');
 }
}
return(xmlhttplocal);
}

function getContent(id) {
	
    var element = document.getElementById('mcontent');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?id='+id);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function getContentInto(id, div) {
	
    var element = document.getElementById(div);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?div='+div+'&iid='+id);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);

}

function getArticleComments(id) {
	
    var element = document.getElementById('articlecomments-'+id);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?articlecomments='+id);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function getLucky() {
	
    var element = document.getElementById('mcontent');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?lucky=1');
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function editPref() {
	
    var element = document.getElementById('editpref');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?editpref=1');
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function setPref(div, sigdiv,field, val) {
	
    var element = document.getElementById(div);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?setpref='+field+'&prefval='+val+'&resdiv='+sigdiv);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function replyComment(replycommentid, replydiscid, replycachekey) {

    var element = document.getElementById('replyblockdiv-'+replycommentid);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';

    xmlhttp.open('get', '/x.php?replycommentid='+replycommentid+'&replydiscid='+replydiscid+'&replycachekey='+replycachekey);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);

}

function replyDisc(replydiscid,replycachekey) {
	
    var element = document.getElementById('replyblockdiv');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';

//    winScroller.toElement($('imgnavblock'));
    $('replyblocklink').removeProperties('href', 'onclick');
    $('replyblocklink').setStyle("opacity", 0.3);

    xmlhttp.open('get', '/x.php?replydiscid='+replydiscid+'&replycachekey='+replycachekey);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function subComment(commentid) {

    if ($('commentreply-txt-'+commentid).value.length > 0) {
      $('commentreply-submit-'+commentid).onclick='';
      if (commentid) {
        $("commentreply-link-"+commentid).set('html', '');
      } else { 
        
      }
      txt = encodeURIComponent($('commentreply-txt-'+commentid).value);
      sig = encodeURIComponent($('commentreply-sig-'+commentid).value);
      discid = encodeURIComponent($('commentreply-discid-'+commentid).value);
      cache = encodeURIComponent($('commentreply-cache-'+commentid).value);
      xmlhttp.open('post', '/x.php');
      xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      xmlhttp.onreadystatechange = handleResponse;
      xmlhttp.send('subcommentid='+commentid+'&subcommentsig='+sig+'&subcommenttxt='+txt+'&subcommentdiscid='+discid+'&subcommentcache='+cache);
   }

}

function delComment(commentid) {

    cache = encodeURIComponent($('commentid-cache-'+commentid).value);	
    var element = document.getElementById('commentid-'+commentid);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?delcommentid='+commentid+'&subcommentcache='+cache);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function approveComment(commentid) {

    cache = encodeURIComponent($('commentid-cache-'+commentid).value);	
    var element = document.getElementById('commentid-'+commentid);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?approvecommentid='+commentid+'&subcommentcache='+cache);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function getGalb(Galb) {

    var element = document.getElementById('womanclasslistint');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
    xmlhttp.open('get', '/x.php?galb='+Galb);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function getGalp(p,o) {

    var element = document.getElementById('womanclasslistint');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
    xmlhttp.open('get', '/x.php?galp='+p+'&browseoffset='+o);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function ratedby(id) {

    var element = document.getElementById('replyblockdiv');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
    xmlhttp.open('get', '/x.php?imgratedby='+id);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function slatedby(id) {

    var element = document.getElementById('replyblockdiv');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
    xmlhttp.open('get', '/x.php?imgslatedby='+id);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function register(id) {
    var username = encodeURIComponent( $('registerusername-'+id).value );
    var email = encodeURIComponent( $('registeremail-'+id).value );
    var password = encodeURIComponent( $('registerpassword-'+id).value );
    var element = document.getElementById('registerdiv-'+id);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
    xmlhttp.open('get', '/x.php?registerusername='+username+'&regid='+id+'&registeremail='+email+'&password='+password);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
}

function preregister(id) {
    var username = encodeURIComponent( $('registerusername-'+id).value );
    var element = document.getElementById('registerdiv-'+id);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
    xmlhttp.open('get', '/x.php?chkusername='+username+'&chkusernameid='+id);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
}

function login(id) {

    var username = encodeURIComponent( $('loginusername-'+id).value );
    var password = encodeURIComponent( $('loginpassword-'+id).value );
    var element = document.getElementById('loginbox-'+id);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';

    xmlhttp.open('get', '/x.php?loginattempt=1&loginid='+id+'&username='+username+'&password='+password);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function loginregister() {

    var element = document.getElementById('loginregister');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
    element.style.display = '';

    xmlhttp.open('get', '/x.php?ajaxlogin=1');
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function imgvote(imgid, score) {
    var element = document.getElementById('voteid-'+imgid);
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
    xmlhttp.open('get', '/x.php?imgvoteid='+imgid+'&imgvotescore='+score);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);

}

function getGalun() {

    var element = document.getElementById('womanclasslistint');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?galun=1');
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function getCal(y, m, d) {
	
    var element = document.getElementById('sidebarcal');
    element.innerHTML = '<div class="loading"><small>please wait, calendar loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?calday='+d+'&calmon='+m+'&calyr='+y);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function saveComment(scoreid, scorepic, scorewoman, scorecomment, scorename) {
	
    var element = document.getElementById('commentblock-'+scoreid);
    element.innerHTML = '<div class="loading"><small>please wait, calendar loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?scoreid='+escape(scoreid)+'&scorepic='+escape(scorepic)+'&scorewoman='+escape(scorewoman)+'&scorecomment='+escape(scorecomment)+'&scorename='+escape(scorename));
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function getDate(str) {
	
    var element = document.getElementById('mcontent');
    element.innerHTML = '<div class="loading"><small>please wait, content loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
	
    xmlhttp.open('get', '/x.php?daycontent='+str);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function handleResponse() {
	if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
		        var response = xmlhttp.responseText;
		        var update = new Array();
		        if(response.indexOf('|%CAYOS%|') != -1) {
		  		update = response.split('|%CAYOS%|');
                                if (update.length >= 2) {
					if (update[2]=='after') {
						var myEl  = new Element('div');
						myEl.set('html',update[1]);
  						myEl.inject($(update[0]), 'after');
						myEl.highlight('#FBEC5D');
					} else {
  						$(update[0]).set('html',update[1]);
						$(update[0]).highlight('#FBEC5D');
					}
					doDivJS();
					if(typeof pageTracker == 'object') { 
						pageTracker._trackPageview("/ajax-request-x.php");
					}
				}
      			}
		}
	}
}

function changeText( div2show, text ) {

    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"

    if (DOM) {
        var viewer = document.getElementById(div2show)
        viewer.innerHTML=text;
    }
    else if(IE) {
        document.all[div2show].innerHTML=text;
    }
}

function changeImage(id, osrc, owidth, oheight) {

  if (document.images[id]) {
    document.images[id].src='/images/site/spacer.gif';
    document.images[id].src=osrc;
    document.images[id].width=owidth;
    document.images[id].height=oheight; 
  }

}

function preregisterchk(id) {
  
  if ($('registerusername-'+id).value.length<5) {
    $('registersubmit-'+id).value='Too Short';
    $('registersubmit-'+id).removeEvents('click');
    $('registersubmit-'+id).addEvent('click', function() { return false; } );
    $('registersubmit-'+id).setProperty('disabled');
    return;
  }

  $('registersubmit-'+id).removeProperties('disabled');
  $('registersubmit-'+id).value='Check';
  $('registersubmit-'+id).removeEvents('click');
  $('registersubmit-'+id).addEvent('click', function() { preregister(id); return false; } );

}

function registerchk(id) {

  if ($('registeremail-'+id).value.length<5) {
    $('registersubmit-'+id).value='Email Too Short';
    $('registersubmit-'+id).removeEvents('click');
    $('registersubmit-'+id).addEvent('click', function() { return false; } );
    return;
  }

  if ( ($('registeremail-'+id).value.indexOf('@')<1 ) || ($('registeremail-'+id).value.indexOf('.')<2) ) {
    $('registersubmit-'+id).value='Email Too Odd';
    $('registersubmit-'+id).removeEvents('click');
    $('registersubmit-'+id).addEvent('click', function() { return false; } );
    return;
  }
 
  if ($('registerpassword-'+id).value.length<5) {
    $('registersubmit-'+id).value='Password Too Short';
    $('registersubmit-'+id).removeEvents('click');
    $('registersubmit-'+id).addEvent('click', function() { return false; } );
    return;
  }

  $('registersubmit-'+id).removeProperties('disabled');
  $('registersubmit-'+id).value='Register';
  $('registersubmit-'+id).removeEvents('click');
  $('registersubmit-'+id).addEvent('click', function() { register(id); return false; } );

}


function addLoadEvent(func) {	
  window.addEvent('domready', func);
}

function HeadlineTabs(newTab) {

  tabClear();
  tabCurrent = newTab;

  if (document.getElementById) {
    document.getElementById(newTab).style.display = "inline";
    return false;
  } else if (document.all) {
    document.all[newTab].style.display = "inline";
    return false;
  } else {
    return true;
  }

}

function tabClear() {
  if (tabCheck()) {
    if (document.getElementById) {
      document.getElementById(tabCurrent).style.display = "none";
    }
    else if (document.all) {
      document.all[tabCurrent].style.display = "none";
    }
    delete tabCurrent;
  }
}

function tabCheck() {
  if (typeof tabCurrent != "undefined") {
    return true;
  } else {
    return false;
  }
}

function addRowInnerHTML(tblId) {
  if (rowcount<25) {

    var tblBody = document.getElementById(tblId).tBodies[0];
    var rowshift = rowcount*5;

    var newRow = tblBody.insertRow(rowshift);
    var newCell0 = newRow.insertCell(0);
    newCell0.align='right';
    newCell0.innerHTML = '<font size=-1>Image File:</font>';
    var newCell1 = newRow.insertCell(1);
    newCell1.innerHTML = '<input name="userfile'+rowcount+'" type="file" style="font-size: 10px;" />';

    var newRow = tblBody.insertRow(rowshift+1);
    var newCell0 = newRow.insertCell(0);
    newCell0.align='right';
    newCell0.innerHTML = '<font size=-1>Link Target:</font>';
    var newCell1 = newRow.insertCell(1);
    newCell1.innerHTML = '<input name="targeturl'+rowcount+'" type="text" size=50 maxlength=200 style="font-size: 10px;" />';

    var newRow = tblBody.insertRow(rowshift+2);
    var newCell0 = newRow.insertCell(0);
    newCell0.align='right';
    newCell0.innerHTML = '<font size=-1>Img Title:</font>';
    var newCell1 = newRow.insertCell(1);
    newCell1.innerHTML = '<input name="imgtitle'+rowcount+'" type="text" size=50 maxlength=200 style="font-size: 10px;" />';

    var newRow = tblBody.insertRow(rowshift+3);
    var newCell0 = newRow.insertCell(0);
    newCell0.align='right';
    newCell0.innerHTML = '<font size=-1>Img Alt Text:</font>';
    var newCell1 = newRow.insertCell(1);
    newCell1.innerHTML = '<input name="imgalt'+rowcount+'" type="text" size=50 maxlength=200 style="font-size: 10px;" />';

    var newRow = tblBody.insertRow(rowshift+4);
    var newCell0 = newRow.insertCell(0);
    newCell0.colSpan = 2;
    newCell0.height = 3;
    newCell0.style.backgroundColor = '#ecf8ff';
    newCell0.innerHTML = "<img src='/images/site/spacer.gif' height=2>";

    rowcount++;
  } else {
    alert("Max number of rows reached!");
  }
}

function imgchange(id) {
  i = document.getElementById('addtopad'+id);
  i.style.display='none';
  i = document.getElementById('showhtml'+id);
  i.style.display='none';
  i = document.getElementById('save'+id);
  i.style.fontWeight = 'bold';
  i.style.fontSize = '12px';
  i = document.getElementById('htmlrow'+id);
  i.style.display='none';
}

function clearpad() {
  var pad = document.getElementById('scratchpad');
  pad.value = '';
  updatepad();
}

function updatepad() {
  var pad = document.getElementById('scratchpad');
  var preview = document.getElementById('scratchpadpreview');
  preview.innerHTML = pad.value;
  doDivJS();
}

function addtopad(id) {
  if (!padstatus) {
    padstatus=1;
    clearpad();
  }
  var pad = document.getElementById('scratchpad');
  var code = document.getElementById(id);
  pad.value = pad.value+id.value;
  updatepad();
} 

function offdisplay(id) {
  subject = document.getElementById(id);
  subject.style.display='none';
}

function ondisplay(id) {
  subject = document.getElementById(id);
  subject.style.display='';
}

function flipdisplay(id) {

  subject = document.getElementById(id);
  if (subject.style.display=='none') {
    subject.style.display='';
  } else {
    subject.style.display='none';
  }

}

function saveform(id, targeturl, imgtitle, imgtemplate, imgtargetclicks, imgalt, imgnewwindow, imgborder, imgspacing, imgtype) {

  if (targeturl==undefined) { targeturl="" };
  if (imgtitle==undefined) { imgtitle="" };
  if (imgtemplate==undefined) { imgtemplate="" };
  if (imgtargetclicks ==undefined) { imgtargetclicks ="" };
  if (imgalt==undefined) { imgalt="" };
  if (imgnewwindow==undefined) { imgnewwindow="" };
  if (imgborder==undefined) { imgborder="" };
  if (imgspacing==undefined) { imgspacing="" };

  var element = document.getElementById('fileuploadimage-'+id);
  element.innerHTML = '<div class="loading"><small>please wait, loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
  xmlhttp.open('get', '/x.php?updateimage='+escape(id)+'&targeturl='+escape(targeturl)+'&imgtitle='+escape(imgtitle)+'&imgtargetclicks='+escape(imgtargetclicks)+'&imgtemplate='+escape(imgtemplate)+'&imgalt='+escape(imgalt)+'&imgnewwindow='+escape(imgnewwindow)+'&imgborder='+escape(imgborder)+'&imgspacing='+escape(imgspacing)+'&imgtype='+escape(imgtype));
  xmlhttp.onreadystatechange = handleResponse;
  xmlhttp.send(null);

}

function deleteform(id) {

  var element = document.getElementById('fileuploadimage-'+id);
  element.innerHTML = '<div class="loading"><small>please wait, loading...<br><br><img src="/images/site/loading.gif" width=32 height=32><br><br></div>';
  xmlhttp.open('get', '/x.php?deleteimage='+escape(id));
  xmlhttp.onreadystatechange = handleResponse;
  xmlhttp.send(null);

}

image1 = new Image();
image1.src="/images/site/loading.gif";

function doDivJS() {
  if (!document.getElementsByTagName) return false;
  var divs = document.getElementsByTagName("div");
  for (var i=0; i < divs.length; i++) {
    if (divs[i].className.match("divjs")) {
      divs[i].className = "divdone";
      divs[i].innerHTML = (eval(divs[i].getAttribute('js')) || '') ;
    }
  }
}

function SimpleSwap(el,which){
        if (which) { el.origsrc = el.src };
        el.src=el.getAttribute(which||"origsrc");
}

function SimpleStyleSwap (el, over) { 
  $(el).addEvents({
    mouseover : function(){ this.addClass(over); },
    mouseout : function(){ this.removeClass(over); }
  });
};

addLoadEvent(doDivJS);

window.addEvent('domready', function(){
  $$('.magicunderline').each( function(el){
    el.addEvents({
      'mouseenter': function() { this.morph({ 'border-color': '#000000' }) },
      'mouseleave': function() { this.morph({ 'border-color': '#F0FFDD' }) }
    });
  });
});
