//$Id: grupthink.js 4583 2010-09-03 07:35:44Z ssundheim $

var fadeballot;
var pollid;
var fullboxID;
var onfeatureID = 1;

function changeText(containerID, txt) {
    var newSpan = document.createElement("span");
    var newText = document.createTextNode(txt);
    newSpan.appendChild(newText);
    var spanElm = document.getElementById(containerID).firstChild;
    document.getElementById(containerID).replaceChild(newSpan, spanElm);
}


function htmlEntityDecode(str) {
	var ta = document.createElement("textarea");
	ta.innerHTML = str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
	return ta.value;
}


function viewanyway(answerID) {
  
  answersummary = 'answersummary' + answerID
  votebutton = 'votebutton_spot' + answerID;
  answerimage = 'answerimage' + answerID;
  message_more = 'showmore' + answerID;
  message_less = 'showless' + answerID;
  
  toggleme(answersummary); 
  toggleme(votebutton,0); 
  toggleme(answerimage, 0);
  toggleme(message_more, 0);
  toggleme(message_less, 0);
  
}


function gotopage(pagenum) {
	document.samesearch.page.value = pagenum;
	document.samesearch.submit();
}
	
function sortme(column) {
	if (column == 'voters') {
		if (document.samesearch.sortby.value == 'num_voters') { 
			// They clicked what it was already sorted by so we'll change direction
			if (document.samesearch.sortdir.value == 'DESC') {
				document.samesearch.sortdir.value = 'ASC';
			} else {
				document.samesearch.sortdir.value = 'DESC';
			}
		}
		else 
		{
			document.samesearch.sortby.value = 'num_voters';
			document.samesearch.sortdir.value = 'DESC';
		}
   	} else {
		if (document.samesearch.sortby.value == 'topic_date') { 
			// they clicked the same sortby, lets change dir
			if (document.samesearch.sortdir.value == 'DESC') {
				document.samesearch.sortdir.value = 'ASC';
			} else {
				document.samesearch.sortdir.value = 'DESC';
			}
		} else {
			document.samesearch.sortby.value = 'topic_date';
			document.samesearch.sortdir.value = 'DESC';
		}
	}
	document.samesearch.submit();
}

function speak (id, what) {
	var element = document.getElementById(id);
	element.innerHTML = 'Clicked ' + what;
}

function showBallotError(input, results, success) {
    alert(results[0].getElementsByTagName('errortext')[0].firstChild.data);

	// If they also told us to reload the ballot, then we are going to
	if (results[0].getElementsByTagName('ballotreload')[0].firstChild.data == 'reload') {	
		var topicID = results[0].getElementsByTagName('topicid')[0].firstChild.data;
		var userConfirmReload = confirm('Would you like us to try and reload your ballot for you? Select "OK" to reload or "Cancel" to return to the page.');
		if (userConfirmReload) {
			reloadBallot(topicID);
		}
	}
}
	
function showcommentform(form_element, input_element) {
  	toggleme(form_element); 
  
  	if(document.getElementById(form_element).style.display != 'none' && document.getElementById(form_element) != null) { 
		// if comment form is visible, put focus on input field 
		document.getElementById(input_element).focus(); 
	}
}

function storeanswerdatainsession() {
	var desc = encodeURI(document.answers.description.value);
	var topicid = document.answers.topicid.value;
	var postString = 'desc=' + desc + '&topicid=' +topicid;
	var postURI = '/ajaxserver/ainfosession.php5';

	// now prevent IE caching
	var d = new Date();
	var t = d.getTime();
	postString += '&TIME=' + t;

	loadXMLDocPost(postURI, postString);
}

function storetopicdatainsession() {
	var tags = encodeURI(document.newquestion.tags.value);
	var megatagString = 'mega';
	var megatags = '';
	var topicForm = document.newquestion;
	var topicFormElements = topicForm.elements;
	for (ii=0; ii<=topicFormElements.length; ii++) {
		var topicElement = topicFormElements[ii];
		if (topicElement != null) {
			if (topicElement.type == 'checkbox') {
				if (topicElement.name.indexOf(megatagString) != -1) {
					if (topicElement.checked) {
						megatags += topicElement.value + ',';
					}
				}
			}
		}
	}

	var body = encodeURI(document.newquestion.description.value);
	var postString = 'tags=' + tags + '&body=' + body + '&megatags=' + megatags;
	var grupidElement = document.newquestion.grupid;
	if (grupidElement != null) {
		var grupid = grupidElement.value;
		postString += '&grupid=' + grupid;
		if (document.getElementById('privacytypewideopen').checked) {
			var grupprivacytype = 'wideopen';
		} else if (document.getElementById('privacytypepanel').checked) {
			var grupprivacytype = 'panel';
		} else {
			var grupprivacytype = 'privateroom';
		}
		postString += '&grupprivacytype=' + grupprivacytype;
		postString += '&publistperm=';
		if (document.getElementById('publistperm').checked) {
			postString += '1';
		} else {
			postString += '0';
		}
	}
	var postURI = '/ajaxserver/qinfoinsession.php5';

	// now prevent IE caching
	var d = new Date();
	var t = d.getTime();
	postString += '&TIME=' + t;

	loadXMLDocPost(postURI, postString);
}

function redirectToAsk(input, results, success) {
	grupid = results[0].getElementsByTagName('grupid')[0].firstChild.data;
	if (grupid != 0) {
		var uri = '/ask/?grupid=' + grupid;
	} else {
		var uri = '/ask/';
	}
	document.location = uri;
}

function redirectToAdd(input, results, success) {
	topicid = results[0].getElementsByTagName('topicid')[0].firstChild.data;
	var uri = '/answer/add.php5?topicid=' + topicid;
	document.location = uri;
}

//The AJAX call and response functions for next/prev topic filter
function setTopicFilter(topicid, filtertype, override) {
	var postString = 'topicid='+topicid+'&filtertype='+filtertype;
	if (override == 'False') {
		postString += '&override=false';
	}
	// now prevent IE caching   
	var d = new Date();
	var t = d.getTime();
	postString += '&amp;TIME=' + t;
	var postURI = '/ajaxserver/settopicfilter.php5';
	loadXMLDocPost(postURI, postString);
}


function setTopicFilterAnswer(topicid, filtertype) {
	var postString = 'answerid='+topicid+'&filtertype='+filtertype;
	// now prevent IE caching   
	var d = new Date();
	var t = d.getTime();
	postString += '&amp;TIME=' + t;
	var postURI = '/ajaxserver/settopicfilter.php5';
	loadXMLDocPost(postURI, postString);
}

function viewTopicFiltered(input, results, success) {
   newloc = "/topic/" + results[0].getElementsByTagName('topicid')[0].firstChild.data;
   document.location = newloc;
}

function viewTopicFilteredAnswer(input, results, success) {
   newloc = "/answer/" + results[0].getElementsByTagName('answerid')[0].firstChild.data;
   document.location = newloc;
}



function stripHTML(text) {
  var re= /<\S[^><]*>/g;
  return text.value.replace(re, "");
}

// For limiting the length on text areas
function checkinputlength(field, maxlimit) {
	if (field != null) {
		if (field.value.length > maxlimit) {
			field.value = field.value.substring(0, maxlimit);
			alert("Your input has been truncated. There is a " + maxlimit + " character limit on this field.");
		}
	}
}


// SHOW/HIDE Hint popup
function togglehintpop() {      
	//Functions that grab screen dimensions
   	var arrayPageSize = getPageSize(); 
	var arrayPageScroll = getPageScroll(); 
	
	//ID's for affected html elements	
	hintboxID = 'hintpop'; 
	
	hintbox = document.getElementById(hintboxID);
	if (hintbox != null) {
		hintbox.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 500) / 2) + 'px'); 
		hintbox.style.left = (((arrayPageSize[0] - 500) / 2) + 'px');
	}
	
	toggleme('opacitize', '0'); 
	
	//Wierd IE7 Bug: If height of opacitize div is over 4096, it won't accept an alpha transparency effect. Workaround:
	if (arrayPageSize[1] > 4096 && document.all) { 
		document.getElementById('opacitize').style.height = '4096px'; 
	}
	else //do the intended thing
	{
		document.getElementById('opacitize').style.height = (arrayPageSize[1] + 'px');     
	}
	
	//If IE, force alpha transparency using the "filter" property      
	if (document.all) { document.getElementById('opacitize').style.filter = "alpha(opacity=50)";}
	   
	toggleme(hintboxID);   
}

function closefull() {
	if (document.getElementById('linkaccountserror') == null) {
		toggleme('opacitize', '0');
		toggleme('fullimagebox');
		if (document.getElementById('fulllicensebox') != null && document.getElementById('fulllicensebox').style.display != 'none') {
			toggleme('fulllicensebox');
		}
		// Bug in IE6 where dropdown boxes show through
		var dropDowns = document.getElementsByTagName('select');
		for (var ii = 0; ii < dropDowns.length; ii++) {
			if (dropDowns[ii].style.display == 'none') {
				dropDowns[ii].style.display = '';
			} else {
				dropDowns[ii].style.display = 'none';
			}
		}
	}
}


// SHOW/HIDE Full-size image. Uses DOM to insert/replace the image in "fullimagebox" DIV
function togglefull(imgUrl) {      
	//Functions that grab screen dimensions
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	//ID's for affected html elements	
	fullboxID = 'fullimagebox';
	fulllnkID = 'fullimglnk';
	fullimgID = 'fullimg';

	fullbox = document.getElementById(fullboxID);
	fullbox.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 500) / 2) + 'px');
	fullbox.style.left = (((arrayPageSize[0] - 600) / 2) + 'px');

	toggleme('opacitize', '0');

	//Wierd IE7 Bug: If height of opacitize div is over 4096, it won't accept an alpha transparency effect. Workaround:
	if (arrayPageSize[1] > 4096 && document.all) { 
	document.getElementById('opacitize').style.height = '4096px'; 
	}
	else //do the intended thing
	{
	document.getElementById('opacitize').style.height = (arrayPageSize[1] + 'px');     
	}

	// Bug in IE6 where dropdown boxes show through
	var dropDowns = document.getElementsByTagName('select');
	for (var ii = 0; ii < dropDowns.length; ii++) {
		if (dropDowns[ii].style.display == 'none') {
			dropDowns[ii].style.display = '';
		} else {
			dropDowns[ii].style.display = 'none';
		}
	}

	//If IE, force alpha transparency using the "filter" property      
	if (document.all) { document.getElementById('opacitize').style.filter = 'alpha(opacity=50)';}

	toggleme(fullboxID);

	oldimgID = document.getElementById(fullimgID);
	var fullimage=document.createElement('img');	
	fullimage.onload = removebackground; //when image has loaded, change the class of div
	fullimage.src= imgUrl; 
	fullimage.id= fullimgID;
	document.getElementById(fulllnkID).replaceChild(fullimage,oldimgID);

	function removebackground() {
	fullbox.className='imageloaded';
	}
    
}

function closeVotingPopup(dontRemind) {
	if (document.getElementById('votingreminder') != null) {
		if (dontRemind == "never") {
			// Then we are going to start an ajax transaction
			var ajaxurl = '/ajaxserver/dontremindvotingpopup.php5';
			var postString = 'dontremind=1';
			
			// Prevent IE caching
			var d = new Date();
			var t = d.getTime();
			postString += '&TIME=' + t;
			loadXMLDocPost(ajaxurl, postString);
		} else {
			finishClosingVotingPopup();
		}
	}
}

function closeRankingPopup(dontRemind) {
	if (document.getElementById('rankingreminder') != null) {
		if (dontRemind == "never") {
			// Then we are going to start some AJAX action
			var ajaxurl = '/ajaxserver/dontremindrankingpopup.php5';
			var postString = 'dontremind=1';
			
			// Prevent IE caching
			var d = new Date();
			var t = d.getTime();
			postString += '&TIME=' + t;
			loadXMLDocPost(ajaxurl, postString);
		} else {
			finishClosingRankingPopup();
		}
	}
}

function finishClosingVotingPopup() {
	var votingReminder = document.getElementById('votingreminder');
	if (votingReminder != null) {
		hideme('votingreminder');
	}
}

function finishClosingRankingPopup() {
	var votingReminder = document.getElementById('rankingreminder');
	if (votingReminder != null) {
		hideme('rankingreminder');
	}
}

// SHOW/HIDE ITEMS

function delay() {
  return true;	
}

function toggleme(element,fade) //Set fade to 0 if you don't want the fade effect. Default is on.
{	
	// Make sure the element actually exists
	if (document.getElementById(element) != null) {
		if (document.getElementById(element).style.display == 'none') {
			fademein(element, fade);
		}  
		else 
		{
			// We are going to hide it
			document.getElementById(element).style.display = 'none'; 	   
		}
	}
}


function toggleme2(element) {
 
  if(document.getElementById(element).style.visibility =='hidden') {
	showme(element);
  }  else {
	document.getElementById(element).style.visibility ='hidden'; 	   
  }
}

function showme(element,fade) //Set fade to 0 if you don't want the fade effect. Default is on.
{ 
	if (document.getElementById(element) != null) {
		if( document.getElementById(element).style.display == 'none') {
			fademein(element, fade);
		}
		
		if (document.getElementById(element).style.visibility == 'hidden') {
			document.getElementById(element).style.visibility ='visible'; 
			document.getElementById(element).style.display ='none'; //Temporary kludge: doing this for JQuery's sake
			fademein(element, fade);
		}
	}
}

function hideme(elementID) {
  
  element = document.getElementById(elementID);
  
  if(element.style.display != 'none') {
	element.style.display ='none'; 
  }
}

// END SHOW/HIDE ITEMS

//GENERAL FADE EFFECTS FOR UNIQUE ELEMENTS
function fademein(element) {
   /*JQuery*/
   $('#'+element).fadeIn('slow', function(){
   });
}

function fademeout(element) {
   /*JQuery*/
   $('#'+element).fadeOut('slow', function(){
   });
}
//END GENERAL FADE EFFECTS


function el(name) {
  return document.getElementById( name );
}


function changedisplay(element,display) {
  if (display=='on') {  document.getElementById(element).style.display =''; } else { document.getElementById(element).style.display ='none';}
}


// Change style class on any object
function changeclass(id, newClass) {
	identity = document.getElementById(id);
	if (identity != null) {
		identity.className = newClass;
	}
}


// Toggle between two classes on an object. Third value (class2) is optional.
function toggleclass(id, class1, class2) {
	if (typeof class2 == 'undefined') {  
		class2 = '';
	}
	identity = document.getElementById(id);
	if (identity != null) {
		if (identity.className==class1) {
			identity.className=class2;
		} else {
			identity.className=class1; 
		}
	}
}	

/* Month and year values must be in two-digit format, eg "09" */
function chooseTime(beginMonth, beginYear) {
	document.getElementById('timelineFilterStart').value = beginMonth+'/'+beginYear;
	//alert(beginMonth + ' ' + beginYear);
	document.frmTimelineFilter.submit();
}	

//------------ ToolTip code ---------------------------//
var showTp = 0;

function showToolTip(id) {
   showTp = 1;
   var d = new Date();
   var t = d.getTime();
   var ajaxurl = '/ajaxserver/tooltips.php5?tooltip_id=' + id + '&time=' + t; 
   loadXMLDoc(ajaxurl);
}

function setToolTip(input, results, success) {
   if (success == 1) {
      var szText = results[0].getElementsByTagName('tooltip')[0].firstChild.data;
      if (showTp == 1)
         overlib(szText, LEFT);
   }
}

function getPolls( search, searchdisp, userid ) {
   document.mysearch.advsearchoptions.value = search;
   document.mysearch.searchtxt.value = searchdisp;
   if( document.mysearch.userid )
     document.mysearch.userid.value = userid;
   document.mysearch.submit();
}

function addToNotify(topicid) {
	var topicid = topicid;
	var postURI = '/ajaxserver/addtonotify.php5';
	
	// now prevent IE caching
	var d = new Date();
	var t = d.getTime();
	postString = 'topicid=' + topicid + '&TIME=' + t;

	// Now send the request away
	loadXMLDocPost(postURI, postString);
}

function addNotifyDone( input, results, success ) {
	var modmsg = document.getElementById( 'commentremovenotifymsg' );
	if (modmsg != null)
	modmsg.style.display = 'none';
	
	var modmsg = document.getElementById( 'commentnotifymsg' );
	if (modmsg != null)
	modmsg.style.display = 'none';
	
	var modmsg = document.getElementById( 'answernotifymsg' );
	if (modmsg != null)
	modmsg.style.display = '';
	
	var modmsg = document.getElementById( 'answerremovenotifymsg' );
	if (modmsg != null)
	modmsg.style.display = 'none';
	
	var notify = document.getElementById( 'notifymeanswers' );
	if (modmsg != null)
	notify.style.display = 'none';
	
	var notifyoff = document.getElementById( 'notifymeanswersoff' );
	if (modmsg != null)
	notifyoff.style.display = '';
}

function removeFromNotify(topicid) {
	var topicid = topicid;
	var postURI = '/ajaxserver/removefromnotify.php5';
	
	// now prevent IE caching
	var d = new Date();
	var t = d.getTime();
	postString = 'topicid=' + topicid + '&TIME=' + t;

	// Now send the request away
	loadXMLDocPost(postURI, postString);
}

function removeFromNotifyDone( input, results, success ) {
	var modmsg = document.getElementById( 'commentremovenotifymsg' );
	modmsg.style.display = 'none';
	
	var modmsg = document.getElementById( 'commentnotifymsg' );
	modmsg.style.display = 'none';
	
	var modmsg = document.getElementById( 'answerremovenotifymsg' );
	modmsg.style.display = '';
	
	var modmsg = document.getElementById( 'answernotifymsg' );
	modmsg.style.display = 'none';
	
	var notify = document.getElementById( 'notifymeanswers' );
	notify.style.display = '';
	
	var notifyoff = document.getElementById( 'notifymeanswersoff' );
	notifyoff.style.display = 'none';
}

function commentNotify(contentid, contenttype, remove) {
	var contentid = contentid;
	var contenttype = contenttype;
	var remove = remove;
	var postURI = '/ajaxserver/commentnotify.php5';
	
	// now prevent IE caching
	var d = new Date();
	var t = d.getTime();
	postString = 'contentid=' + contentid + '&contenttype=' + contenttype + '&remove=' + remove + '&TIME=' + t;

	// Now send the request away
	loadXMLDocPost(postURI, postString);
}

function commentNotifyDone( input, results, success ) {
  var removeaction = results[0].getElementsByTagName('actionremove')[0].firstChild.data;
  
  var modmsg = document.getElementById( 'answerremovenotifymsg' );
  if (modmsg != undefined)
     modmsg.style.display = 'none';
  var modmsg = document.getElementById( 'answernotifymsg' );
  if (modmsg != undefined)
     modmsg.style.display = 'none';
  
  if (removeaction == "0") // we removed the notification
  {
     var modmsg = document.getElementById( 'commentremovenotifymsg' );
     modmsg.style.display = 'none';
     var modmsg = document.getElementById( 'commentnotifymsg' );
     modmsg.style.display = '';
     var notify = document.getElementById( 'notifymecomment' );
     notify.style.display = 'none';
     var notifyoff = document.getElementById( 'notifymecommentoff' );
     notifyoff.style.display = '';
  } else {
     var modmsg = document.getElementById( 'commentremovenotifymsg' );
     modmsg.style.display = '';
     var modmsg = document.getElementById( 'commentnotifymsg' );
     modmsg.style.display = 'none';
     var notify = document.getElementById( 'notifymecomment' );
     notify.style.display = '';
     var notifyoff = document.getElementById( 'notifymecommentoff' );
     notifyoff.style.display = 'none';
  }
}

function modComment( id, mod ) {
  var ajaxurl = '/ajaxserver/modcomment.php5?id=' + id + '&mod=' + mod;
  loadXMLDoc(ajaxurl);
}

function modCommentDone( input, results, success ) {
  var id = results[0].getElementsByTagName('commentid')[0].firstChild.data;
  id = parseInt( id, 10 );
  var mod = results[0].getElementsByTagName('moderation')[0].firstChild.data;

  // first, turn them all on
  document.getElementById( 'modhelpful' + id ).className = '';
  document.getElementById( 'modunhelpful' + id ).className = '';
  document.getElementById( 'modinappropriate' + id ).className = '';

  // then, turn the selected one off
  document.getElementById( 'mod' + mod + id ).className = 'disabled';

  var modmsg = document.getElementById( 'commentmodmsg' + id );
  modmsg.style.display = '';
}

function modAnswer( id, mod, deleteme ) {
  var ajaxurl = '/ajaxserver/modanswer.php5?id=' + id + '&mod=' + mod;
  if (deleteme)
     ajaxurl += '&delete=1';
  // now prevent IE caching
   var d = new Date();
   var t = d.getTime();
   ajaxurl += '&TIME=' + t;
  loadXMLDoc(ajaxurl);
}

function modAnswerDone( input, results, success ) {
  var id = results[0].getElementsByTagName('answerid')[0].firstChild.data;
  id = parseInt( id, 10 );
  var mod = results[0].getElementsByTagName('moderation')[0].firstChild.data;
  var on = results[0].getElementsByTagName('on')[0].firstChild.data;

  // first, turn them all on
  //document.getElementById( 'modinappropriate' + id ).className = '';
  //document.getElementById( 'modadult' + id ).className = '';

  // then, turn the selected one off
  // document.getElementById( 'mod' + mod + id ).className = 'disabled';
  
  if (mod == 'adult') {
     var modadult = document.getElementById( 'modadult' + id);
     if (on == "1") {
        modadult.firstChild.data = 'Not Adult';
        modadulton = true;
     } else {
        modadult.firstChild.data = 'Adult';
        modadulton = false;
     }
  } else if (mod == 'inappropriate') {
     var modinap = document.getElementById( 'modinappropriate' + id);
     if (on == "1") {
        modinap.firstChild.data = 'Relevant';
        modinapon = true;
     } else {
        modinap.firstChild.data = 'Not Relevant';
        modinapon = false;
     }
  }

  var modmsg = document.getElementById( 'answermodmsg' + id );
  modmsg.style.display = '';
}

function modPoll( id, mod, deleteme ) {
  var ajaxurl = '/ajaxserver/modpoll.php5?id=' + id + '&mod=' + mod;
  if (deleteme)
     ajaxurl += "&delete=1";
  // now prevent IE caching
   var d = new Date();
   var t = d.getTime();
   ajaxurl += '&TIME=' + t;
  loadXMLDoc(ajaxurl);
}

function modPollDone( input, results, success ) {
  var id = results[0].getElementsByTagName('pollid')[0].firstChild.data;
  id = parseInt( id, 10 );
  var mod = results[0].getElementsByTagName('moderation')[0].firstChild.data;
  var on = results[0].getElementsByTagName('on')[0].firstChild.data;

  var pollmod = document.getElementById( 'pollmodadult' + id );
  if (on == "1") {
     pollmod.firstChild.data = "Not Adult";
     modadulton = true;
  } else {
     pollmod.firstChild.data = "Adult";
     modadulton = false;
  }

  var modmsg = document.getElementById( 'pollmodmsg' + id );
  modmsg.style.display = '';
}


function addToSessionAynom(key, value) {
  var ajaxurl = '/ajaxserver/addtosession.php5?key=' + key + '&value=' + value;
  // now prevent IE caching
   var d = new Date();
   var t = d.getTime();
   ajaxurl += '&TIME=' + t;
   loadAynomXMLDoc(ajaxurl);
}

function addToSession(key, value) {
  var ajaxurl = '/ajaxserver/addtosession.php5?key=' + key + '&value=' + value;
  // now prevent IE caching
   var d = new Date();
   var t = d.getTime();
   ajaxurl += '&TIME=' + t;
   loadXMLDoc(ajaxurl);
}

function genericAjaxSuccess( input, results, success ) {
  // call the overide function if it is defined
  if (self.genericOveride) 
     genericOveride();
}

function checkForCommentText(formElementId) {
	var formElementName = '#'+formElementId;
	if ($(formElementName).find('textarea').val().length <= 0) {
		if ($(formElementName).children(':first').attr('id') != 'error') {
			$(formElementName).prepend('<div id="error">You cannot propose a blank comment.</div>');
		} else {
			$(formElementName).children(':first').show();
		}
		$(formElementName).children(':first').delay(2000).fadeOut();
		return false;
	} else {
		return true;
	}
}

//-------------------Positioning -------------------------//

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//------------------End Positioning ----------------------//

		/*********************************************************************
		 * No onMouseOut event if the mouse pointer hovers a child element 
		 * *** Please do not remove this header. ***
		 * This code is working on my IE7, IE6, FireFox, Opera and Safari
		 * 
		 * Usage: 
		 * <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');"> 
		 *		So many childs 
		 *	</div>
		 *
		 * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
		**/
		function is_child_of(parent, child) {
			if( child != null ) {			
				while( child.parentNode ) {
					if( (child = child.parentNode) == parent ) {
						return true;
					}
				}
			}
			return false;
		}
		function fixOnMouseOut(element, event, JavaScript_code) {
			var current_mouse_target = null;
			if( event.toElement ) {				
				current_mouse_target 			 = event.toElement;
			} else if( event.relatedTarget ) {				
				current_mouse_target 			 = event.relatedTarget;
			}
			if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
				eval(JavaScript_code);
			}
		}
		/*********************************************************************/
