// $Header: /cvsroot/mavaradaneshnameh/mavara/lib/mavara-js.js,v 1.31.2.5 2004/07/22 16:42:34 teedog Exp $

// ***************** begin of queue ****************
// first-in/first-out queue
function Queue(Name) {
	this.Name = Name; // Makes it pretty when you print the contents
	this.Stack = new Array();
	this.Enqueue = function(Item) {
    	// Tack the new entry onto the end of the array
    	this.Stack[this.Stack.length] = Item;
    	return this;
	}
	this.Dequeue = function() {
		// Remove the first entry from the array and return it
		if(this.Stack.length > 0) {
			var Result = this.Stack[0];
			this.Stack = this.Stack.slice(1);
			return Result;
		}
		return null;
	}
	this.toString = function() {
		for(var x = 0, Result = this.Name + 'Queue Contents:n'; x < this.Stack.length; x++) {
      		Result += "t" + this.Stack[x];
		}
		return Result;
	}
}
// This object is used to store items that are going to be piled up on a queue
function QueuedHours(Point, Amount) {
	this.Point = Point;
	this.Amount = Amount;
	return this;
}
// ***************** end of queue ****************

// ***************** begin of AJAX ****************
function Ajax(actionURL, elementIDsArray, resultAreaId, idleMessage, methodType, forceScriptReexecution) {
	this.State = 'send';
	this.dumbRPC = false;
	this.actionURL = actionURL;
	this.elementIDsArray = elementIDsArray;
	this.resultAreaId = resultAreaId;
	this.idleMessage = idleMessage;
	this.methodType = methodType;
	this.forceScriptReexecution = forceScriptReexecution;
}

ajax = Ajax.prototype;
ajax.makeRequest = function(resultAreaId) {
	this.State = 'send';
	dumbRPC = 'undefined' == typeof(resultAreaId) || !resultAreaId;
	if('undefined' == typeof(this.idleMessage)) {
		this.idleMessage = '';
	}
	if('undefined' == typeof(this.forceScriptReexecution)) {
		this.forceScriptReexecution = false;
	}
	if(false === this.forceScriptReexecution && document.getElementById(resultAreaId) && '' != document.getElementById(resultAreaId).innerHTML.replace(/(\s+$)|(^\s+)/g, '')) {
		return -1; // Already done
	}
	this.methodType = 'undefined' == typeof(this.methodType) ? 'GET' : this.methodType.toUpperCase();
	if('GET' != this.methodType && 'POST' != this.methodType) {
		return -2; // Method not supported
	}
	for(var queryParamasArray = new Array('randomId=' + Math.random()), i = 0, j = queryParamasArray.length; i < this.elementIDsArray.length; ++i, ++j) {
		if(elementReference = document.getElementById(this.elementIDsArray[i])) {
			queryParamasArray[j] = elementReference.name + '=' + strip(elementReference.value);
		}
	}
	if(false === dumbRPC && document.getElementById(resultAreaId)) {
		document.getElementById(resultAreaId).innerHTML = this.idleMessage;
	}
	var http = this.getHTTPObject();
	if('GET' == this.methodType) {
		http.open('GET', this.actionURL + '?' + queryParamasArray.join('&'), true);
		http.onreadystatechange = function getBackResponse() { 
				if(4 == http.readyState) { 
					if(false === dumbRPC && document.getElementById(resultAreaId)) {
						document.getElementById(resultAreaId).innerHTML = http.responseText;
					}
					this.State = 'ready';
				} 
			};
		http.send(null); 
	} else {
		http.open('POST', this.actionURL, true);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		http.onreadystatechange = function getBackResponse() { 
				if(4 == http.readyState) { 
					if(false === dumbRPC && document.getElementById(resultAreaId)) {
						document.getElementById(resultAreaId).innerHTML = http.responseText; 
					}
					this.State = 'ready';
				} 
			};
		http.send(queryParamasArray.join('&')); 
	}
}

ajax.getHTTPObject = function () { 
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 && 'undefined' != typeof(XMLHttpRequest)) {
		try { 
			xmlhttp = new XMLHttpRequest(); 
		} catch (e) { 
			xmlhttp = false; 
		} 
	} 
	return xmlhttp; 
} 

//var http = getHTTPObject(); //We create the HTTP Object 
// ***************** end of AJAX ****************

function ajaxSyncRequest(actionURL, elementIDsArray, resultAreaId, idleMessage, methodType, forceScriptReexecution) {
	new Ajax(actionURL, elementIDsArray, resultAreaId, idleMessage, methodType, forceScriptReexecution).makeRequest(resultAreaId);
}

var queue = new Queue('Requests');
function asyncRequest(actionURL, elementIDsArray, resultAreaId, idleMessage, methodType, forceScriptReexecution) {
	queue.Enqueue(new Ajax(actionURL, elementIDsArray, resultAreaId, idleMessage, methodType, forceScriptReexecution));
}

function createIFrame(iframeID, resultAreaId, dumbRPC ,after_onload_callmethod) {
	var tempIFrame, iframe;
	if(!document.createElement) {
		return false;
	}
	try {
		tempIFrame = document.createElement('iframe');
		tempIFrame.setAttribute('id', iframeID);
		tempIFrame.style.border = tempIFrame.style.width = tempIFrame.style.height = '0px';
		if(false === dumbRPC) {
			tempIFrame.attachEvent('onload', 
				function() {
					if('undefined' != typeof(tempIFrame.readyState) && 'complete' == tempIFrame.readyState && resultAreaId) {
						if(tempIFrame.contentDocument) { // For NS6
							document.getElementById(resultAreaId).innerHTML = tempIFrame.contentDocument.body.innerHTML; 
						} else if(tempIFrame.contentWindow) { // For IE5.5 and IE6
							document.getElementById(resultAreaId).innerHTML = tempIFrame.contentWindow.document.body.innerHTML;
						} else if(tempIFrame.document) { // For IE5
							document.getElementById(resultAreaId).innerHTML = tempIFrame.document.body.innerHTML;
						} else {
							alert('Error: could not find IFRAME document');
							return false;
						}
						window.status = 'Done'; //Workaround for incorrect browser statusbar status
						if('undefined' != typeof(after_onload_callmethod) &&  false !== after_onload_callmethod){
							eval(after_onload_callmethod);
						}	
					}
					if(tempIFrame) {
						tempIFrame.removeNode(true); //Remove iFrame from the object tree
					}
					return true;
				}
			);
		}
		iframe = document.body.appendChild(tempIFrame);
		if(document.frames) {
			iframe = document.frames[iframeID];
		}
	} catch(e) {
		alert(e.description);
		return false;
 	}
	return document.getElementById(iframeID);
}

function syncRequest(actionURL, elementIDsArray, resultAreaId, idleMessage, methodType, forceScriptReexecution, after_onload_callmethod) {
var i, equalSignPos, dumbRPC, elementRef, resultAreaRef, queryString, iframeRef, iframeId;
	dumbRPC = 'undefined' == typeof(resultAreaId) || !resultAreaId;
	forceScriptReexecution = 'undefined' == typeof(forceScriptReexecution) ? false : forceScriptReexecution;
	resultAreaRef = false === dumbRPC ? document.getElementById(resultAreaId) : false;
	if(false === forceScriptReexecution && resultAreaRef && '' != resultAreaRef.innerHTML.replace(/(\s+$)|(^\s+)/g, '')) {
		return; //Already done
	}
	for(i = 0, queryString = '?'; i < elementIDsArray.length; ++i) {
		if(elementRef = document.getElementById(elementIDsArray[i])) {
			if('undefined' != typeof(elementRef.name)){
				queryString += elementRef.name + '=' + unicodeURLEncode(elementRef.value) + '&';
			}	
		} else if(-1 != elementIDsArray[i].indexOf('=')) {
			queryString += elementIDsArray[i] + '&';
		}
	}
	if(false === dumbRPC && resultAreaRef && '' != idleMessage) {
		resultAreaRef.innerHTML = idleMessage;
	}
	if(iframeRef = createIFrame(iframeId = 'iframeid' + parseInt(1000000 * Math.random()), resultAreaId, dumbRPC, 'undefined' != typeof(after_onload_callmethod) ? after_onload_callmethod : false)) {
		iframeRef.src = actionURL + queryString + Math.random();
	}
}

// pourshahmir 7/26 add selected category into Array
function setCategoryImage(actionURL, categoryArray , elementIDsArray, resultAreaId, idleMessage, methodType, forceScriptReexecution) {
	try{
		elementIDsArrayResult = new Array();
		elementIDsArrayResult =	elementIDsArray ;
		for(var i=0;i<categoryArray.length;i++){
			elementIDsArrayResult[elementIDsArrayResult.length]= categoryArray[i] ;
		}		
		ajaxSyncRequest(actionURL, elementIDsArrayResult , resultAreaId, idleMessage, methodType, forceScriptReexecution);
	}catch(e){alert(e.description)}	
	
}
// pourshahmir 7/26 add selected category into Array
function set_cat_ids(object,cat_num){

	if(typeof(cat_ids) == "undefined")
		return false;
	if(cat_ids[cat_num]==undefined ){
		cat_ids[cat_num] = new Array();
	}
	if(object.type == 'checkbox'){
		if(object.checked){
			cat_ids[cat_num][cat_ids[cat_num].length] = object.id;	
		}else{
			arr_temp = new Array();
			arr_temp = cat_ids[cat_num];
			cat_ids[cat_num] = new Array();
			for(var i=0,j=0;i<arr_temp.length;i++)
				{
					if(arr_temp[i] != object.id){
						cat_ids[cat_num][j++] = arr_temp[i];					
					}					
				}
		}	
	}else if (object.type == 'radio'){
		if(object.checked){
			cat_ids[cat_num][0] = object.id;
		}else{
			cat_ids[cat_num][0] = null; 	
		}
	}	
}	
//
function toggle_dynamic_var($name) {
	name1 = 'dyn_'+$name+'_display';
	name2 = 'dyn_'+$name+'_edit';
	if(document.getElementById(name1).style.display == "none") {
		document.getElementById(name2).style.display = "none";
		document.getElementById(name1).style.display = "inline";
	} else {
		document.getElementById(name1).style.display = "none";
		document.getElementById(name2).style.display = "inline";
	
	}
	
}

function chgArtType() {
	if (document.getElementById('articletype').value != 'Review') {
		document.getElementById('isreview').style.display = "none";
	} else {
		document.getElementById('isreview').style.display = "";
	}
}

function chgTrkFld() {
	if (document.getElementById('trkfldtype').value == 'd'){
		document.getElementById('trkfldoptions').style.display = "inline";
		document.getElementById('trkflddropdown').style.display = "inline";
		document.getElementById('trkfldimage').style.display = "none";
	} else if (document.getElementById('trkfldtype').value == 'i' ) {
		document.getElementById('trkfldoptions').style.display = "inline";
		document.getElementById('trkflddropdown').style.display = "none";
		document.getElementById('trkfldimage').style.display = "inline";
	} else {
		document.getElementById('trkfldoptions').style.display = "none";
		document.getElementById('trkflddropdown').style.display = "none";
		document.getElementById('trkfldimage').style.display = "none";
	}
}

function setMenuCon(foo) {
	var it = foo.split(",");
	document.getElementById('menu_url').value = it[0];
	document.getElementById('menu_name').value = it[1];
	if (it[2]) {
		document.getElementById('menu_section').value = it[2];
	} else {
		document.getElementById('menu_section').value = '';
	}
	if (it[3]) {
		document.getElementById('menu_perm').value = it[3];
	} else {
		document.getElementById('menu_perm').value = '';
	}
}

function genPass(w1, w2, w3) {
	vo = "aeiouAEU";
	co = "bcdfgjklmnprstvwxzBCDFGHJKMNPQRSTVWXYZ0123456789_$%#";
	s = Math.round(Math.random());
	for (i = 0, l = 8, p = ''; i < l; i++, s ^= 1, p += letter) {
		letter = 1 == s ? vo.charAt(Math.round(Math.random() * (vo.length - 1))) : co.charAt(Math.round(Math.random() * (co.length - 1)));
	}
	p += Math.round(Math.random() * 1000);
	document.getElementById(w1).value = p;
}

function setUserModule(foo1) {
	document.getElementById('usermoduledata').value = foo1;
}

function setSomeElement(fooel, foo1) {
	document.getElementById(fooel).value = document.getElementById(fooel).value + foo1;
}
function setSomeElement(fooel, foo1,doc) {
	alert(foo1);
	doc.getElementById(fooel).value = doc.getElementById(fooel).value + foo1;
}

function replaceSome(fooel, what, repl) {
	document.getElementById(fooel).value = document.getElementById(fooel).value.replace(what, repl);
}

function replaceLimon(vec) {
	document.getElementById(vec[0]).value = document.getElementById(vec[0]).value.replace(vec[1], vec[2]);
}

function replaceImgSrc(imgName,replSrc) {
  document.getElementById(imgName).src = replSrc;
}

function setSelectionRange(textarea, selectionStart, selectionEnd) {
  if (textarea.setSelectionRange) {
    textarea.focus();
    textarea.setSelectionRange(selectionStart, selectionEnd);
  }
  else if (textarea.createTextRange) {
    var range = textarea.createTextRange();
    textarea.collapse(true);
    textarea.moveEnd('character', selectionEnd);
    textarea.moveStart('character', selectionStart);
    textarea.select();
  }
}
function setCaretToPos (textarea, pos) {
  setSelectionRange(textarea, pos, pos);
}
function insertAt(elementId, replaceString) {
	try{	
		  //inserts given text at selection or cursor position
		  textarea = document.getElementById(elementId);
		  var toBeReplaced = /text|page|area_name/;//substrings in replaceString to be replaced by the selection if a selection was done
		  if (textarea.setSelectionRange) {
			    //Mozilla UserAgent Gecko-1.4
			    var selectionStart = textarea.selectionStart;
			    var selectionEnd = textarea.selectionEnd;
			    var scrollTop=textarea.scrollTop;
			    if (selectionStart != selectionEnd) { // has there been a selection
					var newString = replaceString.replace(toBeReplaced, textarea.value.substring(selectionStart, selectionEnd));
				    	textarea.value = textarea.value.substring(0, selectionStart)
				                  + newString
				                  + textarea.value.substring(selectionEnd);
				      setSelectionRange(textarea, selectionStart, selectionStart + newString.length);
			    }else  {// set caret
					       textarea.value = textarea.value.substring(0, selectionStart)
					                  + replaceString
					                  + textarea.value.substring(selectionEnd);
					      setCaretToPos(textarea, selectionStart + replaceString.length);
			    }
				    textarea.scrollTop=scrollTop;
		}else if (document.selection) {
			    //UserAgent IE-6.0
			    textarea.focus();
			    var range = document.selection.createRange();
				if (range.parentElement() == textarea) {
						var isCollapsed = range.text == '';
						if (! isCollapsed)  {
						        range.text = replaceString.replace(toBeReplaced, range.text);
						        range.moveStart('character', -range.text.length);
						        range.select();
						}	else {
								range.text = replaceString;
						}
			    }
		} else { //UserAgent Gecko-1.0.1 (NN7.0)
			    setSomeElement(elementId, replaceString)
			    //alert("don't know yet how to handle insert" + document);
		}
	}catch(e){alert(e.description)}	
}

function insertAt1(elementId, replaceString,doc) {
  //inserts given text at selection or cursor position
//  alert(elementId);
//  alert(replaceString);
	var doc1;
  if (doc)  
  {	
//  	  	alert('Hi!');
			doc1=doc;	
//  		alert(textarea.value);
  }
  else
  {
		doc1=document;
  }
	textarea = doc1.getElementById(elementId);

  var toBeReplaced = /text|page|area_name/;//substrings in replaceString to be replaced by the selection if a selection was done
  if (textarea.setSelectionRange) {
    //Mozilla UserAgent Gecko-1.4
    var selectionStart = textarea.selectionStart;
    var selectionEnd = textarea.selectionEnd;
    var scrollTop=textarea.scrollTop;
    if (selectionStart != selectionEnd) { // has there been a selection
	var newString = replaceString.replace(toBeReplaced, textarea.value.substring(selectionStart, selectionEnd));
    	textarea.value = textarea.value.substring(0, selectionStart)
                  + newString
                  + textarea.value.substring(selectionEnd);
      setSelectionRange(textarea, selectionStart, selectionStart + newString.length);
    }
    else  {// set caret
       textarea.value = textarea.value.substring(0, selectionStart)
                  + replaceString
                  + textarea.value.substring(selectionEnd);
      setCaretToPos(textarea, selectionStart + replaceString.length);
    }
    textarea.scrollTop=scrollTop;
  }
  else if (doc1.selection) {
    //UserAgent IE-6.0
    textarea.focus();
    var range = doc1.selection.createRange();
    if (range.parentElement() == textarea) {
      var isCollapsed = range.text == '';
      if (! isCollapsed)  {
        range.text = replaceString.replace(toBeReplaced, range.text);
        range.moveStart('character', -range.text.length);
        range.select();
      }
	else {
		range.text = replaceString;
	}
    }
  }
  else { //UserAgent Gecko-1.0.1 (NN7.0)
    setSomeElement(elementId, replaceString,doc1)
    //alert("don't know yet how to handle insert" + document);
	}
}


function setUserModuleFromCombo(id) {
	document.getElementById('usermoduledata').value = document.getElementById('usermoduledata').value
		+ document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
//document.getElementById('usermoduledata').value='das';
}

function show(foo,f) {
	if(null === document.getElementById(foo))
		return;
	document.getElementById(foo).style.display = "block";
	if (f) { setCookie(foo, "o"); }
}

function hide(foo,f) {
	if(null === document.getElementById(foo))
		return;
	document.getElementById(foo).style.display = "none";
	if (f) { setCookie(foo, "c"); }
}

function flip(foo) {
	if (document.getElementById(foo).style.display == "none") {
		show(foo);
	} else {
		if (document.getElementById(foo).style.display == "block") {
			hide(foo);
		} else {
			show(foo);
		}
	}
}
//pourshahmir 84/5 for faq's
function changeDisplay(foo) {
	if (document.getElementById(foo).style.display == "none") {
		show(foo,1);
	} else {
		if (document.getElementById(foo).style.display == "block") {
			hide(foo,1);
		} else {
			show(foo,1);
		}
	}
}
function setDisplay(foo){
	if (getCookie(foo)=="o")
		show(foo,1);
}	
//

function toggle(foo) {
	if (document.getElementById(foo).style.display == "none") {
		show(foo);

		setCookie(foo, "o");
	} else {
		if (document.getElementById(foo).style.display == "block") {
			hide(foo,1);
		} else {
			show(foo,1);
		}
	}
}
//pourshahmir
function objshow(object,use_cookie) {
	try{
		if(null === object)
			return;
		object.style.display = "block";
		if (use_cookie){
		 	setCookie(object.id, "o"); 
		}
	}catch(e){
		alert(e.description);
	}	
}
function objhide(object,use_cookie) {
	try{	
		if(null === object)
			return;
		object.style.display = "none";
		if (use_cookie){
			 setCookie(object.id, "c"); 
		}
	}catch(e){
		alert(e.description);
	}	
}
function objToggle(object){
	try{
		if (object.style.display == "none") {
				objshow(object,true);
		}else if (object.style.display == "block") {
				objhide(object,true);
		}
	}catch(e){
		alert(e.description);
	}	
}
function callToServer(iframe,div,src){
	try{
		objToggle(div);
		if(div.allow_change){
			div.innerHTML = '<span style="color:blue;font-size:11px">لطفا چند لحظه صبر کنید ...</span>';
			iframe.src = src;
		}	
	}catch(e){
	}	
}	
function afterloadiFrame(iframe,div){
    try{
    	  if(iframe.src!="about:blank" && div.allow_change){
          		div.innerHTML = iframe.contentWindow.document.body.innerHTML;
          		iframe.src="about:blank";
          		div.allow_change = false;
          }
      }
    catch(e){alert(e.description);}
    return;
}
//pourshahmir
function mavaratabs(focus,max) {
	for (var i = 1; i < max; i++) {
		var tabname = 'tab' + i;
		var content = 'content' + i;
		//if (document.getElementById(tabname) != 'undefined') {
			if (i == focus) {
				//show(tabname);
				show(content);
				setCookie('tab',focus);
			} else {
				//hide(tabname);
				hide(content);
			}
		//}
	}
}

function setfoldericonstate(foo) {
	pic = new Image();

	if (getCookie(foo) == "o") {
		pic.src = "img/icons/ofo.gif";
	} else {
		pic.src = "img/icons/fo.gif";
	}
	if(document.getElementsByName(foo + 'icn')[0])
		document.getElementsByName(foo + 'icn')[0].src = pic.src;
}
/* foo: name of the menu
 * def: menu type (e:extended, c:collapsed, f:fixed)
 * the menu is collapsed function of its cookie: if no cookie is set, the def is used
 */
function setfolderstate(foo, def) {
	status = getCookie(foo);
	if (status == "o") {
		show(foo);
	} else if (status != "c" && def == 'e') {
		show(foo, "o");
	}
	else {
		hide(foo);
	}

	setfoldericonstate(foo);
}

function icntoggle(foo) {
	if (document.getElementById(foo).style.display == "none") {
		show(foo);

		setCookie(foo, "o");
	} else {
		hide(foo);

		setCookie(foo, "c");
	}

	setfoldericonstate(foo);
}

//
// set folder icon state during page load
//
function setFolderIcons() {
	var elements = document.forms[the_form].elements[elements_name];

	var elements_cnt = ( typeof (elements.length) != 'undefined') ? elements.length : 0;

	if (elements_cnt) {
		for (var i = 0; i < elements_cnt; i++) {
			elements[i].checked = document.forms[the_form].elements[switcher_name].checked;
		}
	} else {
		elements.checked = document.forms[the_form].elements[switcher_name].checked;

		;
	} // end if... else

	return true;
}     // setFolderIcons()

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "")
		+ ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");

	document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var dc = document.cookie;

	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1) {
		begin = dc.indexOf(prefix);

		if (begin != 0)
			return null;
	} else begin += 2;

	var end = document.cookie.indexOf(";", begin);

	if (end == -1)
		end = dc.length;

	return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "="
			+ ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
	var base = new Date(0);

	var skew = base.getTime();

	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

//
// Expand/collapse lists
//
function flipWithSign(foo) {
	if (document.getElementById(foo).style.display == "none") {
		show(foo);

		collapseSign("flipper" + foo);
		setCookie(foo, "o");
	} else {
		hide(foo);

		expandSign("flipper" + foo);
		setCookie(foo, "c");
	}
}

// set the state of a flipped entry after page reload
function setFlipWithSign(foo, forceOpen) {
	forceOpen = 'undefined' == typeof(forceOpen) ? false : forceOpen;
	if (getCookie(foo) == "o" || true === forceOpen) {
		collapseSign("flipper" + foo);

		show(foo);
	} else {
		expandSign("flipper" + foo);

		hide(foo);
	}
}

function expandSign(foo) {
	if(null === document.getElementById(foo))
		return;
	document.getElementById(foo).firstChild.nodeValue = "[+]";
}

function collapseSign(foo) {
	if(null === document.getElementById(foo))
		return;
	document.getElementById(foo).firstChild.nodeValue = "[-]";
} // flipWithSign()

//
// Check / Uncheck all Checkboxes
//
function switchCheckboxes(the_form, elements_name, switcher_name) {
	// checkboxes need to have the same name elements_name
	// e.g. <input type="checkbox" name="my_ename[]">, will arrive as Array in php.
	var elements = document.forms[the_form].elements[elements_name];

	var elements_cnt = ( typeof (elements.length) != 'undefined') ? elements.length : 0;

	if (elements_cnt) {
		for (var i = 0; i < elements_cnt; i++) {
			elements[i].checked = document.forms[the_form].elements[switcher_name].checked;
		}
	} else {
		elements.checked = document.forms[the_form].elements[switcher_name].checked;

		;
	} // end if... else

	return true;
}     // switchCheckboxes()

//
// Set client offset (in minutes) to a cookie to avoid server-side DST issues
// Added 7/25/03 by Jeremy Jongsma (jjongsma@tickchat.com)
//
var expires = new Date();
var offset = -(expires.getTimezoneOffset() * 60);
expires.setFullYear(expires.getFullYear() + 1);
setCookie("tz_offset", offset, expires, "/");

// function added for use in navigation dropdown
// example :
// <select name="anything" onchange="go(this);">
// <option value="http://mavaradaneshnameh.org">mavaradaneshnameh.org</option>
// </select>
function go(o) {
	if (o.options[o.selectedIndex].value != "") {
		location = o.options[o.selectedIndex].value;
	}

	return false;
}


// function:	targetBlank
// desc:	opens a new window, XHTML-compliant replacement of the "TARGET" tag
// added by: 	Ralf Lueders (lueders@lrconsult.com)
// date:	Sep 7, 2003
// params:	url: the url for the new window
//		mode='nw': new, full-featured browser window
//		mode='popup': new windows, no features & buttons

function targetBlank(url,mode) {
  var features = 'menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes';
  switch (mode) {
    // new full-equipped browser window
    case 'nw':
      break;
    // new popup-window
    case 'popup':
      features = 'menubar=no,toolbar=no,location=no,directories=no,fullscreen=no,titlebar=no,hotkeys=no,status=no,scrollbars=yes,resizable=yes';
      break;
    default:
      break;
   }
   blankWin = window.open(url,'_blank',features);
}

// function:	confirmTheLink
// desc:	pop up a dialog box to confirm the action
// added by: 	Franck Martin
// date:	Oct 12, 2003
// params:	theLink: The link where it is called from
// params: theMsg: The message to display
function confirmTheLink(theLink, theMsg)
{
    // Confirmation is not required if browser is Opera (crappy js implementation)
    if (typeof(window.opera) != 'undefined') {
        return true;
    }
                                                                                                                  
    var is_confirmed = confirm(theMsg);
    //if (is_confirmed) {
    //    theLink.href += '&amp;is_js_confirmed=1';
    //}
                                                                                                                  
    return is_confirmed;
} 

/** \brief: modif a textarea dimension
 * \elementId = textarea idea
 * \height = nb pixels to add to the height (the number can be negative)
 * \width = nb pixels to add to the width
 * \formid = form id (needs to have 2 input rows and cols
 **/
function textareasize(elementId, height, width, formId) {
	textarea = document.getElementById(elementId);
	form = document.getElementById(formId);
	if (textarea && height != 0 && textarea.rows + height > 5) {
		textarea.rows += height;
		if (form.rows)
			form.rows.value = textarea.rows;
	}
	if (textarea && width != 0 && textarea.cols + width > 10) {
		 textarea.cols += width;
		if (form.cols)
			form.cols.value = textarea.cols;
	}
}

function backup(table){
	//table = 'messu_messages';
	var win = window.open('about:blank','download','left=20,top=20,width=300,height=70,toolbar=0,resizable=0,menubar=0');
	var div = '<div align = "center" style = "FONT-WEIGHT: bold; COLOR: red; FONT-FAMILY: Curier" >...لطفا چند لحظه صبر کنید</div>';
	div +='<br>' + 'اگر در دریافت فایل مشکل دارید، ' + '<a href = "messu-mailbox.php?action=backup" >اینجا</a>' + ' را کلیک کنید';

	win.document.write(div);
	win.location = 'messu-mailbox.php?action=backup';
//syncRequest('messu-mailbox.php',new Array('backup'),'result','{tr}Please wait...{/tr}','POST',true);
}
function forum_onload(all){
	try{
		if(typeof(all) != 'undefined' && true === all){
			if(document.getElementsByName('__list__[]')){
				_id_ = document.getElementsByName('__list__[]');        
				while(_id_.length>0){
					ID = _id_[0].value
					obj = document.getElementById('__list__'+ID+'_');	
					obj.removeNode(true);
						toggle_forum(ID,new Array('comment','node') , new Array(ID,ID),
				            		 	'child' , 'child_area' ,new Array() , 'img' ,'mavara-view_forum_threads.php',false , false,'forum_onload(true)');		
				}	
				return;
			}
		}		
		nodeId   = document.getElementById('node').value;
		topId    = document.getElementById('top').value; 
		Id  = document.getElementById('comment').value; 
		if(nodeId == "") return;
		self.location = "#ref"+topId;	
		if(nodeId == topId){
			return;	
		}else if(0 == topId ){
			document.getElementById('top').value = topId = nodeId;
			is_marked('title'+topId,'forumnameread');									
		}else{
			if(document.getElementById('temp_top_'+topId)){
				topId = document.getElementById('top').value = document.getElementById('temp_top_'+Id).value;
				self.location = "#ref"+topId;					
				if(nodeId == topId){
					return;	
				}	
			}	
    	}  
		toggle_forum(topId,new Array('comment','node') , new Array(topId,nodeId),
            		 	'child' , 'child_area' ,new Array() , 'img' ,'mavara-view_forum_threads.php',false , false,'forum_onload()');		
 		if(document.getElementById('warning_reply') && document.getElementById('warning_reply').value == 'y'){
 			alert(10);
			threadId_ 		= document.getElementById('default_threadId').value;
			parentId_ 		= document.getElementById('default_parentId').value;
			ancestorId_ 	= document.getElementById('default_ancestorId').value;
			document.getElementById('warning'+threadId_).style.display='block';		
			newPost(threadId_,parentId_,ancestorId_,'share_area_newPost');		
		}	
    }catch(e){alert(e.description)}        	 
}	
function iframe_onload_remove(){
	try{
			if(document.getElementById('remove_thread')){
					if(document.getElementById(document.getElementById('remove_thread').value)){
						document.getElementById(document.getElementById('remove_thread').value).removeNode(true);						
					}else{	
						document.getElementById(document.getElementById('remove_thread').value).removeNode(true);
					}	
			}else if(document.getElementById('clear_title')){
				title = document.getElementById('clear_title').value;
				document.getElementById(title).innerHTML="";
				data= document.getElementById('clear_data').value;
				document.getElementById(data).innerHTML="";
			}	
	}catch(e){alert(e.description)}
}	
function fill_textarea(areaData ,Id){
	try{
		if(document.getElementById(areaData)){
			form =document.getElementById('form'+Id);
			data = document.getElementById(areaData).innerHTML.replace(/xxxlineBreakxxx/g, '\r\n');
			form.elements['comments_data'].value	= data;
			document.getElementById(areaData).innerHTML = '';
		}	
	}catch(e){alert(e.description)}	
}	
function sendToClipboard(s){
	try{	
		if( window.clipboardData && clipboardData.setData ){
			clipboardData.setData("Text", s);
		}else{
			alert("Internet Explorer required");
		}
	}catch(e){alert(e.description)}  
}
function viewImage(imageId ,areaId){
	area  = document.getElementById(areaId);	
	area.innerHTML = '<img  src="show_image.php?imageId='+imageId+'"  onreadystatechange="viewImageProgress(\''+areaId+'\',this.readyState)" onError="viewImageProgress(\''+areaId+'\',\'error\')" />';
	viewImageProgress(areaId ,'loading');
}	
function viewImageProgress(areaId ,status){
	area = document.getElementById(areaId);
	switch(status){
		case 'loading':
				if(null == (div = document.getElementById('temp_message'))){
					div = document.createElement('DIV');
					div.id = 'temp_message';
					area.appendChild(div);					
				}
					div.innerHTML = '<span style="color:red;font-size:11px">لطفا چند لحظه صبر کنید ...</span>';														
				area.style.display = 'block'; 				
			break;	
		case 'complete':
				document.getElementById('temp_message').innerHTML = ''; 
			break;	
		case 'error':
			area.style.display = 'none'; 					
			document.getElementById('temp_message').innerHTML = ''; 		
			alert('خطا در بارگذاری تصویر ! دوباره سعی نمایید');
			break;	
			
	}	
}	