

var timer1 = 0; // timer for sound alert on chatui
var timer2 = 0; // timer for logout on chatui
var timer3 = 0; // timer for display urgent bulletin
var timer4 = 0; // timer for refresh chatui when there is no message
var timer5 = 0; // timer for sound alert and logout on chatui
var timer6 = 0; // timer for all message update
var timer7 = 0; // timer for chatui lost link detection & sound
var timer8 = 0; // timer for chatui reply message focus 
var timer9 = 0; // timer for menu
var timer10 = 0; // timer for loading animation
var timer = new Array();

// Asaf Shamir 2006 (mostly ripped)

/*******************************************************************************
 Start Change style sheet
*******************************************************************************/

function getAllSheets() {
  if( !window.ScriptEngine && navigator.__ice_version ) { return document.styleSheets; }
  if( document.getElementsByTagName ) { var Lt = document.getElementsByTagName('link'), St = document.getElementsByTagName('style');
  } else if( document.styleSheets && document.all ) { var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
  } else { return []; } for( var x = 0, os = []; Lt[x]; x++ ) {
    var rel = Lt[x].rel ? Lt[x].rel : Lt[x].getAttribute ? Lt[x].getAttribute('rel') : '';
    if( typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) { os[os.length] = Lt[x]; }
  } for( var x = 0; St[x]; x++ ) { os[os.length] = St[x]; } return os;
}
function changeStyle() {
  for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
    if( ss[x].title ) { ss[x].disabled = true; }
    for( var y = 0; y < arguments.length; y++ ) {
     if( ss[x].title == arguments[y] ) { ss[x].disabled = false; }
} } }

/*******************************************************************************
 End Change style sheet
*******************************************************************************/
/*******************************************************************************
 Start FORM to URL
*******************************************************************************/

function formData2QueryString(docForm) {

  var submitContent = '';
  var formElem;
  var lastElemName = '';
  
  for (i = 0; i < docForm.elements.length; i++) {
    
    formElem = docForm.elements[i];
    switch (formElem.type) {
      // Text fields, hidden form elements
      case 'text':
      case 'hidden':
      case 'password':
      case 'textarea':
      case 'select-one':
        submitContent += formElem.name + '=' + escape(formElem.value) + '&'
        break;
        
      // Radio buttons
      case 'radio':
        if (formElem.checked) {
          submitContent += formElem.name + '=' + escape(formElem.value) + '&'
        }
        break;
        
      // Checkboxes
      case 'checkbox':
        if (formElem.checked) {
          // Continuing multiple, same-name checkboxes
          if (formElem.name == lastElemName) {
            // Strip of end ampersand if there is one
            if (submitContent.lastIndexOf('&') == submitContent.length-1) {
              submitContent = submitContent.substr(0, submitContent.length - 1);
            }
            // Append value as comma-delimited string
            submitContent += ',' + escape(formElem.value);
          }
          else {
            submitContent += formElem.name + '=' + escape(formElem.value);
          }
          submitContent += '&';
          lastElemName = formElem.name;
        }
        break;
        
    }
//              	alert(submitContent + ' ' + lastElemName);
  }
  // Remove trailing separator
  submitContent = submitContent.substr(0, submitContent.length - 1);
  return submitContent;
}
/*******************************************************************************
 END FORM to URL
*******************************************************************************/

/*******************************************************************************
 Start XMLHttpRequest script
*******************************************************************************/
 var http_request = false;
 var request_queue = Array();
 var post_request_queue = Array();
 var request_url = '';
 function makeRequest(url,get_request) { 
 	//alert("makeRequest('" + url + "','" + get_request + "')");
 	request_url = url;
 	if(http_request) {

	 		request_queue.push("makeRequest('" + url + "','" + get_request + "');");
	 		return;
	 } 
	get_request = unescape(get_request);

	if(url.indexOf('.php') != -1){	
		random_number1 = 10000 + Math.round(100000*Math.random())
		random_number2 = 10000 + Math.round(100000*Math.random())
		str = 'wa' + random_number1 + '=' + random_number2;
	
		if(get_request.indexOf('?') != -1)
			get_request += '&' + str;
		else
			get_request += '?' + str;
	}

 	//document.getElementById("loading").style.display='block';
 	displayLoading();
 	
 	http_request = false; if (window.XMLHttpRequest) {  
 		http_request = new XMLHttpRequest(); 
 		if (http_request.overrideMimeType) { 
 			http_request.overrideMimeType('text/xml'); 
 		} 
 	} else if (window.ActiveXObject) {  
 		try { 
 			http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
 		} catch (e) { 
 			try { 
 				http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
 			} catch (e) {} 
 		} 
 	} 
 	if (!http_request) { 
 		alert('Cannot create XMLHTTP instance'); 
 		return false; 
 	} 
 	

 	http_request.onreadystatechange = alertContents;  
 	url = url + get_request;
// 	alert(url);
 	http_request.open('GET', url, true); 
 	http_request.send(null);
		
 }
 
 function makeiFrameRequest(form) {

 	//document.getElementById("loading").style.display='block'; 
 	displayLoading();
 	 	
 	waiframe = document.getElementById('waiframe');
 	if(waiframe == null) {
		alert('No Iframe');
		return;	
 	}

	form.target = 'waiframe'; 	
	form.submit();
 	return true;
 }
 
 function processiFrame(iFrame) {
 	data = extractIFrameBody(iFrame);
 	try {
 	processData(data.innerHTML);

 	} catch(e) {}
    //document.getElementById("loading").style.display = 'none';
    displayLoaded(); 	
 	 
 }
 
 function extractIFrameBody(iFrameEl) {

  var doc = null;
  if (iFrameEl.contentDocument) { // For NS6
    doc = iFrameEl.contentDocument; 
  } else if (iFrameEl.contentWindow) { // For IE5.5 and IE6
    doc = iFrameEl.contentWindow.document;
  } else if (iFrameEl.document) { // For IE5
    doc = iFrameEl.document;
  } else {
    alert("Error: could not find sumiFrame document");
    return null;
  }
  return doc.body;

}
 
 function alertContents() {
	if(!http_request)return;	
  	if (http_request.readyState == 4) 
  	{
   		if (http_request.status == 200) 
   		{					
	   		processData(http_request.responseText);	
	     	//document.getElementById("loading").style.display = 'none';
	     	displayLoaded();
 	
    		http_request = false;	     
		    // process request queue
		    if(request_queue.length > 0)
		    	setTimeout(request_queue.shift(), 100);	     
		    return;

	   } 
	   else 
	   {
			/*
	    	var username = readCookie('pox_username');
   			var browser=navigator.appName;
			var b_version=navigator.appVersion;
			var version=parseFloat(b_version);
			var d = new Date(); 
			
			var errmsg = 'Sorry we have encountered an error, please take a screenshot of this dialog and email it to support@smsc.com.au\r\n\r\n';
			errmsg += "--Date: " + d + "\r\n";
			errmsg += "--Browser: " + browser + " v" + version  + "\r\n";
			errmsg += "--Failer Url: " + request_url + "\r\n";
			errmsg += "--Username: " + username + "\r\n";
			errmsg += "--HTTP Status: " + http_request.status  + "\r\n";
			//alert(errmsg);
			*/
	   }
  	}	
 }
 
 function processData(data) {
 		 aresult = data.split("::|::");
 		 amaxii=(aresult.length-3)/3;
	     j=0;
	     for(i=0;i<amaxii;i++){
	      idobject=document.getElementById(aresult[j]);
	      	//alert('[' + aresult[j+2] + '] ' + aresult[j] + ': ' + idobject + ' ' + idobject.type + '\r\n' + '\r\n------------------------\r\n' + aresult[j+1] + '\r\n------------------------\r\n' + idobject.innerHTML);
		  if (idobject != null) {	 		  		  	 	  
		      switch(aresult[j+2]) {
		      	case '4':
		      		 fadeId(aresult[j]); //,null, 1500, "#EEFCC5","#FF0000");
	    	     case '3':
	    	    // works better when elements are attached to the beginning
				//idobject = document.getElementById(aresult[j]).innerHTML;
				     idobject.innerHTML = aresult[j+1] + idobject.innerHTML;
				     //idobject.innerHTML += aresult[j+1];// + idobject.innerHTML;
				     break;
		      	case '2':	   
					 //alert(aresult[j+1]);
					 var jscode = unescape(aresult[j+1]).replace(/&amp;/g, "&");	
					 try {					 
					 	eval(jscode);
					 } catch (e) {
					 	if(typeof console != 'undefined') {
					 		console.log('Evaluation failed\n', jscode);
					 	}
					 }
					 break;
		      	case '1':
		      		fadeId(aresult[j]); //,null, 1500, "#EEFCC5","#FF0000");
		      	default:
				  	idobject.innerHTML = aresult[j+1];		
					//alert(aresult[j+1]);					 
		      		break;	      	
		      }
		  }
	
		  	
	      j+=3;
	     }
 }
 
 function get(name,obj) {
  var getstr = "?";
  for (i=0; i<obj.childNodes.length; i++) {
   if (obj.childNodes[i].tagName == "INPUT") {
    if (obj.childNodes[i].type == "hidden")   {getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; }
    if (obj.childNodes[i].type == "button")   {getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; }
    if (obj.childNodes[i].type == "checkbox") {if (obj.childNodes[i].checked) { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";  } else { getstr += obj.childNodes[i].name + "=&";  } }
    if (obj.childNodes[i].type == "radio")    {if (obj.childNodes[i].checked) { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; } }
    if (obj.childNodes[i].type == "text")     {getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; }
    if (obj.childNodes[i].type == "file")     {getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; }
   }
   if (obj.childNodes[i].tagName == "SELECT") {
    var sel = obj.childNodes[i]; getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
   }
   if (obj.childNodes[i].type == "textarea") {
    getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
   }
  }
  // around #-problem
  var t = /#/g;
  getstr=getstr.replace(t,"zsdiesz");
  makeRequest(name,getstr);
}
/*******************************************************************************
 End XMLHttpRequest
*******************************************************************************/

/*******************************************************************************
 Start menu script
*******************************************************************************/
function navmenu(){ var navRoot = document.getElementById("navnav").getElementsByTagName("LI"); for (var i=0; i<navRoot.length; i++) { navRoot[i].onmouseover=function() {this.className+="over"; }; navRoot[i].onmouseout=function()  {this.className=this.className.replace("over",""); } } }
/*******************************************************************************
 End menu script
*******************************************************************************/


/*******************************************************************************
   Start content boxes script initially based on google/ig
*******************************************************************************/
function getID(a){return document.getElementById?document.getElementById(a):null} function apgelstn(a){return document.getElementsByTagName?document.getElementsByTagName(a):new Array()} function apuc(a){return a.toUpperCase()} function aptrim(a){return a.replace(/^\s*|\s*$/g,"")} function apesc(a){return window.encodeURIComponent?encodeURIComponent(a):escape(a)}var aO=function(a){return window.decodeURIComponent?decodeURIComponent(a):unescape(a)};var _unesc=aO;function _hesc(a){return a.replace(/</g,"&lt;").replace(/>/g,"&gt;")}var aN=0;function _uid(){return"obj"+aN++} function _min(a,aa){return a<aa?a:aa} function _max(a,aa){return a>aa?a:aa}var aI=navigator.userAgent.indexOf("Safari")>=0;function _sendx(a,aa){var ab=aP();if(!ab||aI&&!aa){(new Image()).src=a}else{ab.open("GET",a,true);if(aa){ab.onreadystatechange=function(){if(ab.readyState==4){aa(ab.responseText)}}}ab.send(null)}} function _uhc(a,aa,ab){var ac="m_"+a+"_"+aa;var ad=getID(ac);if(!ad){ad=document.createElement("INPUT");ad.type="hidden";ad.disabled=true;ad.name=ac;getID("m_"+a+"_form").appendChild(ad)}ad.value=ab;ad.disabled=false} function aP(){var a=null;if(window.ActiveXObject){a=new ActiveXObject("Msxml2.XMLHTTP");if(!a){a=new ActiveXObject("Microsoft.XMLHTTP")}}else if(window.XMLHttpRequest){a=new XMLHttpRequest()}return a}var apet="";var appid="";var as="";function an(a,aa,ab){var ac=document.createElement("input");ac.type="hidden";ac.name=aa;ac.value=ab;a.appendChild(ac)} function aF(){var a=new Object();var aa=document.location.search.substring(1);var ab=aa.split("&");for(var ac=0;ac<ab.length;ac++){var ad=ab[ac].indexOf("=");if(ad==-1)continue;var ae=ab[ac].substring(0,ad);var af=ab[ac].substring(ad+1);af=af.replace(/\+/g," ");a[ae]=_unesc(af)}return a} function ar(){var a={pid:1,host:1,hl:1};var aa=aF();var ab="?";for(var ac in aa){if(a[ac]){ab+=ac+"="+apesc(aa[ac])+"&"}}return ab} function _xsetp(a){_sendx(as+ar()+"et="+apet+"&pid="+appid+"&"+a,null)} function apdlsetp(a,aa){if(!aa){aa=apesc(document.location)}document.location=as+ar()+"et="+apet+"&pid="+appid+"&url="+aa+"&"+a} function _ssbc(a,aa,ab){var ac=apgelstn("*");for(var ad=0;ad<ac.length;ad++){if(ac[ad].className==a){ac[ad].style[aa]=ab}}} function aM(a){_xsetp("pnlo="+(a?1:0))}var apuli;var apnlo;var appl;var apmod;var az=false;var apcols=new Array(); function apupc(){_ssbc("medit","display",apnlo||apuli?"":"none");_ssbc("panelo","display",apnlo?"":"none");_ssbc("panelc","display",apnlo?"none":"");_ssbc("mod","display",apmod?"":"none");_ssbc("unmod","display",apmod?"none":"");if(appl&&(apuli||apnlo)){if(!az){aH(apcols);az=true}_ssbc("mttl","cursor","move")}}var aq=0;function _tp(a){if(aq>0)clearInterval(ap);apnlo=a;apmod=true;aM(a);apupc();var aa=getID("cpnl");var ab=getID("cpnls");var ac=getID("cpnlc");var ad=getID("nhdr");var ae=getID("ehdr");var af=aa.offsetWidth;var ah;var ai;if(a){ah=ac.offsetWidth;ai="visible";ae.style.display="";ad.style.display="none"}else{ah=1;ai="hidden";ae.style.display="none";ad.style.display=""}aa.style.overflow="hidden";var ak=100;var at=10;var au=0;aq=setInterval(function(){var av=au/at;var aA=af+(ah-af)*av;ab.width=(aa.style.width=aA);au++;if(av>=1){clearInterval(aq);aq=0;ab.width=(aa.style.width=ah);aa.style.overflow=ai}},ak/at);return false} function _ts(a,aa){var ab=getID(a+aa);var ac;if(ab.className=="mlist_open"){ab.className="mlist_closed";ac="pnlsc"}else{ab.className="mlist_open";ac="pnlso"}_xsetp(ac+"="+apesc(aa));return false} function _add_m(a){apdlsetp(a)} function _add_m_confirm(a,aa){if(confirm(aa)){_add_m(a)}} function _add_f(a){apdlsetp("n_25="+apesc("url="+apesc(a)))}var aw=/^_add_m(_confirm)?\(\"[^"]+\"(, *\"[^"]+\")?\)$/; function aB(a){var aa=/^alert\(\"[^"]+\"\)$/;if(a.match(aw)!=null||a.match(aa)!=null){eval(a)}} var aj=[];  var ap=0;var am=null;function ag(){if(!am){am=document.createElement("DIV");am.style.display="none";am.style.position="absolute";am.style.cursor="move";am.style.backgroundColor="#ffffff";am.style.paddingBottom="0px";document.body.appendChild(am)}return am}var al={obj:null,init:function(a){a.onmousedown=al.start;if(isNaN(parseInt(ag().style.left)))ag().style.left="0px";if(isNaN(parseInt(ag().style.top)))ag().style.top="0px";a.onDragStart=new Function();a.onDragEnd=new Function();a.onDrag=new Function()},start:function(a){var aa=al.obj=this;a=al.fixE(a);var ab=parseInt(ag().style.top);var ac=parseInt(ag().style.left);aa.onDragStart(ac,ab,a.clientX,a.clientY);aa.lastMouseX=a.clientX;aa.lastMouseY=a.clientY;document.onmousemove=al.drag;document.onmouseup=al.end;  return false}, drag:function(a){a=al.fixE(a);var aa=al.obj;var ab=a.clientY;var ac=a.clientX;var ad=parseInt(ag().style.top);var ae=parseInt(ag().style.left);var af,ah;af=ae+ac-aa.lastMouseX;ah=ad+ab-aa.lastMouseY;ag().style.left=af+"px";ag().style.top=ah+"px";aa.lastMouseX=ac;aa.lastMouseY=ab;aa.onDrag(af,ah,a.clientX,a.clientY);   return false}, end:function(){document.onmousemove=null;document.onmouseup=null;al.obj.onDragEnd(parseInt(ag().style.left),parseInt(ag().style.top)); ;al.obj=null},fixE:function(a){if(typeof a=="undefined")a=window.event;if(typeof a.layerX=="undefined")a.layerX=a.offsetX;if(typeof a.layerY=="undefined")a.layerY=a.offsetY;return a}};var ax=false;function aH(a){if(ax)return;ax=true;  aj=a;  for(var aa=0;aa<aj.length;aa++){for(var ab=0;ab<aj[aa].childNodes.length-1;ab++){  var ac=aj[aa].childNodes[ab];  var ad=getID(ac.id+"_h");  if(!ad)continue;ad.module=ac;al.init(ad);  var ae=getID(ac.id+"_url");  if(ae){ae.h=ad;ae.onmousedown=function(){this.h.href=this.href;this.h.target=this.target;} }ad.onDragStart=function(af,ah){clearInterval(ap);var ai=this.module;aC(ai);ai.origNextSibling=ai.nextSibling;var ak=ag();ak.style.left=ao(ai,true);ak.style.top=ao(ai,false);ak.style.height=ai.offsetHeight;ak.style.width=ai.offsetWidth;ak.style.display="block";ak.style.opacity=0.8;ak.style.filter="alpha(opacity=80)";ak.innerHTML=ai.innerHTML;ak.className=ai.className;this.dragged=false} ;ad.onDrag=function(af,ah){aJ(this.module,af,ah);this.dragged=true} ;ad.onDragEnd=function(af,ah){if(this.dragged){ap=aG(this.module,150,15); draggedapmodule_col=this.module.parentNode.id.replace(/c_/,"")-1;draggedapmodule_id=this.module.id.replace(/m_/,"");draggedapmodule_top=this.module["offsetTop"]; save_boxes();   }else{ay();if(this.href){if(this.target){window.open(this.href,this.target);}else{document.location=this.href}}}  this.target=null;  this.href=null;   } }}} function ay(){ag().style.display="none"} function aG(a,aa,ab){var ac=parseInt(ag().style.left);var ad=parseInt(ag().style.top);var ae=(ac-ao(a,true))/ab;var af=(ad-ao(a,false))/ab;return setInterval(function(){if(ab<1){clearInterval(ap);ay();return}ab--;ac-=ae;ad-=af;ag().style.left=parseInt(ac)+"px";ag().style.top=parseInt(ad)+"px"},aa/ab)} function aC(a){for(var aa=0;aa<aj.length;aa++){var ab=0;for(var ac=0;ac<aj[aa].childNodes.length;ac++){var ad=aj[aa].childNodes[ac];if(ad==a)ab=ad.offsetHeight;ad.pagePosLeft=ao(ad,true);ad.pagePosTop=ao(ad,false)-ab}}} function ao(a,aa){var ab=0;while(a!=null){ab+=a["offset"+(aa?"Left":"Top")];a=a.offsetParent}return ab} function aJ(a,aa,ab){var ac=null;var ad=100000000;for(var ae=0;ae<aj.length;ae++){for(var af=0;af<aj[ae].childNodes.length;af++){var ah=aj[ae].childNodes[af];if(ah==a)continue;var ai=Math.sqrt(Math.pow(aa-ah.pagePosLeft,2)+Math.pow(ab-ah.pagePosTop,2));if(isNaN(ai))continue;if(ai<ad){ad=ai;ac=ah}}}if(ac!=null&&a.nextSibling!=ac){ac.parentNode.insertBefore(a,ac);aK(a)}} function aK(a){a.parentNode.style.display="none";a.parentNode.style.display=""}
/*******************************************************************************
 End the script initially  based on google/ig
*******************************************************************************/


/*******************************************************************************
 Start fade script  based on  http://www.axentric.com/aside/fat/ by Adam Michela
*******************************************************************************/
 var Fat = {make_hex : function (r,g,b)  { r = r.toString(16); if (r.length == 1) r = '0' + r; g = g.toString(16); if (g.length == 1) g = '0' + g; b = b.toString(16); if (b.length == 1) b = '0' + b; return "#" + r + g + b; }, fade_all : function () { var a = document.getElementsByTagName("*"); for (var i = 0; i < a.length; i++)  { var o = a[i]; var r = /fade-?(\w{3,6})?/.exec(o.className); if (r) { if (!r[1]) r[1] = ""; if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]); } } }, fade_element : function (id, fps, duration, from, to)  { if (!fps) fps = 30; if (!duration) duration = 3000; if (!from || from=="#") from = "#FFFF33"; if (!to) to = this.get_bgcolor(id);  var frames = Math.round(fps * (duration / 1000)); var interval = duration / frames; var delay = interval; var frame = 0; if (from.length < 7) from += from.substr(1,3); if (to.length < 7) to += to.substr(1,3);        var rf = parseInt(from.substr(1,2),16); var gf = parseInt(from.substr(3,2),16); var bf = parseInt(from.substr(5,2),16); var rt = parseInt(to.substr(1,2),16); var gt = parseInt(to.substr(3,2),16); var bt = parseInt(to.substr(5,2),16);        var r,g,b,h; while (frame < frames) { r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames)); g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames)); b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames)); h = this.make_hex(r,g,b);        setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);  frame++; delay = interval * frame;  } setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay); }, set_bgcolor : function (id, c) { var o = document.getElementById(id); o.style.backgroundColor = c; }, get_bgcolor : function (id) { var o = document.getElementById(id); while(o) { var c; if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color"); if (o.currentStyle) c = o.currentStyle.backgroundColor; if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; } o = o.parentNode; } if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF"; var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/); if (rgb) {c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));} return c; } }; window.onload = function () { Fat.fade_all(); };
/*******************************************************************************
 End the script  based on  http://www.axentric.com/aside/fat/ by Adam Michela
*******************************************************************************/

function togglehidebox(id) {
	if (document.getElementById) { 
		bb= document.getElementById(id).style.display; 
		if (bb == "none"){ 
			document.getElementById(id).style.display = 'block'; 
		} else { 
			document.getElementById(id).style.display = 'none'; 
		} 
	} else { 
		if (document.layers) { 
			if (document.id.display == "none"){ 
				document.id.display = 'block'; 
			} else { 
				document.id.display = 'none'; 
			} 
		} else { 
			if (document.all.id.style.visibility == "none"){ 
				document.all.id.style.display = 'block'; 
			} else { 
				document.all.id.style.display = 'none';
			} 
		}
	} 
}
function searchonblur(a){
	document.getElementById(a).style.display = 'none';  
	return false;  
}
function searchonfocus(a){
	document.getElementById(a).style.display = 'inline';  
	return false; 
}
function clearDefault(el) {
	if (el.defaultValue==el.value) 
		el.value = "";
}
var fading = false;
function fadeId(fid) { 
	return;
	document.getElementById(fid).style.display = 'block';
	endcolor = document.getElementById(fid).style.backgroundColor;  
	if(endcolor == '')
		endcolor = '#ffffff';
	fading=true;	
	Fat.fade_element(fid,null,3000,'#D62408',endcolor);

}

function confirmation(){
	window.status = 'Ajax boxes updated'; 
}

function bgSwitch(ac, bc) { 
	if (ac == 'on'){ 
		bc.style.background = '#ffc'; 
	} else if (ac == 'off'){ 
		bc.style.background = ''; 
	} 
}

function textChanger(result) {
	var result_array=result.split("~~|~~"); 
	document.getElementById(result_array[1]).innerHTML = result_array[0]; 
	Fat.fade_element(result_array[1], 30, 1500, "#EEFCC5", "#FFFFFF"); 
}

function parseForm(TTxT,cellID, inputID) {
    var temp = document.getElementById(inputID).value;
    var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
    //document.getElementById("loading").style.display = 'block';
    displayLoading();
 	
    if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
    var obj = /  /g;
    while (temp.match(obj)) { temp = temp.replace(obj, " "); }
    if (temp == " ") { temp = ""; }
    if (! temp) {alert("This field must contain at least one non-whitespace character.");return;}
    var st = document.getElementById(inputID).value + '~~|~~' + cellID;
    document.getElementById(cellID).innerHTML = "<span class=\"update\">Updating...</span>";
    x_changeText(TTxT,st,textChanger);
    //document.getElementById("loading").style.display = 'none';
	displayLoaded();    
}
function editCellT(id, cellSpan) {
    var inputWidth  = 60; //(document.getElementById(id).offsetWidth/ 7);
    var oldCellSpan = cellSpan; //cellSpan.innerHTML;
    //document.getElementById("loading").style.display = 'block';
    displayLoading();
 	
    document.getElementById(id).innerHTML = "<form  name=\"activeForm\" onsubmit=\"parseForm('0','"+id+"', '"+id+"input'); return false;\" action=\"\"><input type=\"text\" size=\""+ inputWidth + "\"  id=\""+id+"input\"  onblur=\"parseForm('0','"+id+"', '"+id+"input'); return false;\"><noscript><input value=\"OK\" type=\"submit\"></noscript></form>";
    document.getElementById(id+"input").value = oldCellSpan;
    document.getElementById(id+"input").focus();
    document.getElementById(id+"input").style.background = '#ffc';
    //document.getElementById("loading").style.display = 'none';
    displayLoaded();	
 	
}
function editCellTxT(id, cellSpan) {
    var inputWidth  = 60; //(document.getElementById(id).offsetWidth / 3);
    var inputHeight = 20; //(document.getElementById(id).offsetHeight / 10 );
    var oldCellSpan = cellSpan.innerHTML;
    document.getElementById(id).innerHTML = "<form  name=\"activeForm\" onsubmit=\"parseForm('1','"+id+"', '"+id+"input'); return false;\" action=\"\"><textarea cols=\""+ inputWidth + "\" rows=\""+ inputHeight +"\" id=\""+id+"input\"  onblur=\"parseForm('1','"+id+"', '"+id+"input'); return false;\"></textarea><noscript><input value=\"OK\" type=\"submit\"></noscript></form>";
    document.getElementById(id+"input").value = oldCellSpan;
    document.getElementById(id+"input").focus();
    document.getElementById(id+"input").style.background = '#ffc';
}

function save_boxes(){
/*
	var  dataseq=''; 
	var  databid=''; 
	var  datai=''; 
	for(i=0;i<BoxNumber;i++){
		xy=document.getElementById('m_'+BoxId[i]).offsetLeft+document.getElementById('m_'+BoxId[i]).offsetTop; 
		dataseq+=xy; 
		databid+=BoxId[i]; 
		datai+= i;
		if(i!=BoxNumber-1) {
			dataseq+=':'; databid+=':'; datai+=':';
		}   
	}
	
	data=dataseq + ',' + databid + ',' + datai + ',' + draggedapmodule_col + ':' + draggedapmodule_id; x_update_boxes(data,confirmation);
	return false;  
	*/
}

function showError(text, type, callback, timeout){
	//var errorElem = document.getElementById("popup_error");
	/*var errorElem = document.getElementById("popup_content");
	var errorElemContent = document.getElementById("popup_elem");
	if(errorElem && errorElemContent){
		errorElem.style.display='block';
		errorElemContent.innerHTML = "<p class='error'>"+text+"</p>"; 
		//Fat.fade_element('popup_error',60,3000,'#F5C2C2','#ffffff'); 
	}*/
	
	
	if(!type) type = "error";
	
	var time = 20000; // milisecond
	if(!timeout) {
		if(type == "info"){
			time = 3000;
		}else if(type == "alert"){
			time = -1;
		}
	} else {		
		time = timeout;
	}	
	if(!callback) 
		callback = "";
	
	var errorElem = document.getElementById("popup_error");
	var viewportwidth = GetViewportWidth();
	var viewportheight = GetViewportHeight();
	var scrOfX = getScrollX();
	var scrOfY = getScrollY();
	
	var exec_after = "removeError();" + callback;
		
	if(errorElem){
		clearTimeout(timer['error']);
		if(time != -1){
			timer['error'] = setTimeout(exec_after, time); 
		}
		
		oHeight = errorElem.offsetHeight;
		oWidth = errorElem.offsetWidth;
		
		//give some initial values for the popup error if it doesnt have width and height
		if (oWidth == 0)  {
			oWidth = 400;
		}
		
		if (oHeight == 0)  {
			oHeight = 100;
		}
		
		errorElem.style.top = parseInt(((viewportheight / 2) - (oHeight / 2))  + scrOfY);
		errorElem.style.left = parseInt(((viewportwidth / 2) - (oWidth / 2)) + scrOfX);
		
		errorElem.style.display='block';
		errorElem.innerHTML = '<img src="image/close.jpg" alt="close" onclick="removeError();" align="right" />' +
							  '<div class="div_error">' +text+ '</div>'; 
		
		errorElem.onclick = new Function("event", exec_after);
		//Fat.fade_element('popup_error',60,3000,'#F5C2C2','#ffffff'); 
	}	
}

function removeError(){
	clearTimeout(timer['error']);
	var errorElem = document.getElementById("popup_error");
	//var errorElem = document.getElementById("popup_content");
	if(errorElem){
		errorElem.style.display='none';
	}
}


function showProtection(text){
	if(!text || text == "") text = "Please hold ...";
	protectElem = document.getElementById("popup_transparent");
	if(protectElem){
		protectElem.style.display='block';
		textHTML = "<center><img src=\"image/ajax-loader.gif\" /><br>" +
					"<b>"+text+"</b></center>";
		protectElem.innerHTML = textHTML; 		
	}
}



function removeProtection(){
	protectElem = document.getElementById("popup_transparent");
	if(protectElem){
		protectElem.style.display='none';
	}
}

function showWarning(text){
	document.getElementById("warnings").style.display='block'; 
	document.getElementById("warnings").innerHTML = "<span class='error'>"+text+"</span>"; 
	Fat.fade_element('warnings',null,3000,'#F5C2C2','#ffffff'); 
}


function createCookie(name,value,hours) {
	if (hours) {
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/*******************************************************************************
 Start href claim script - Asaf Shamir
*******************************************************************************/

function claimForms() {
	arr = document.getElementsByTagName('form');
	for(i=0;i<arr.length;i++) {
		// only deal with ajax links
		if(arr[i].target != 'ajax') {
			continue;
		}
		arr[i].target = 'waiframe';
		//js = "document.getElementById('loading').style.display='block';document.getElementById('loaded').style.display='none';";
		js = "displayLoading();"; 	
		InsertHandler(arr[i], 'onsubmit', js);		
	}
	return true;	
}
var WildAjax;
function claimHrefs() {
	arr = document.getElementsByTagName('a');
	var areplace = "javascript:WildAjax=WildAjax";
	for(i=0;i<arr.length;i++) {
		// only deal with ajax links
		if(arr[i].target != 'ajax') {
			continue;
		}

		url = arr[i].href;		
		// if its already been changed
		if(url == areplace) {
			continue;
		}	
							
		params = '';		
		idx = url.indexOf('?');
		if(idx != -1) {
			params = url.substring(idx, url.length);
			url = url.substring(0,idx);
		}
		
		request = 'makeRequest("' + url + '\", \"' + params + '\");';
		InsertHandler(arr[i], 'onclick', request);
		arr[i].href = areplace;
		arr[i].target = '';
	}
	return true;	
}

function InsertHandler(obj, eventname, handlercode) {
	if(obj == null)
		return false;
	if(eventname == 'onclick') {	
		obj.onclick = InjectCode(obj.onclick, handlercode);			
	} else if(eventname == 'onchange') {
	    obj.change = InjectCode(obj.change, handlercode);
	} else if(eventname == 'onsubmit') {
	    obj.onsubmit = InjectCode(obj.onsubmit, handlercode);
	} else 
		return false;
	return true;
}

//Currently not parsing function parameters
function InjectCode(functioncode, newcode) {
	body = 'alert("InjectCode Failed")';
	if(functioncode != null) {
		fcstr = functioncode.toString();
		idx = fcstr.indexOf('{');
		if(idx == -1) {
			alert('InjectCode: No handler code found');
			return functioncode;
		}
		body = fcstr.substring(idx+1, fcstr.lastIndexOf('}')) + ' ' + newcode;
	} else
		body = newcode;	
	newfunc=new Function("event", body);	
	return newfunc;
}

/*******************************************************************************
 End href claim script - Asaf Shamir
*******************************************************************************/



function CheckAll(elem, name){
	var checkflag = elem.checked;
	var field = document.getElementsByName(name);
	
	if (checkflag) {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
		}
		
	}else {
		for (i = 0; i < field.length; i++) {
			field[i].checked = false; 
		}
		
	}
}

function addAllCheckedValue(dataelem, elem, name){
	var data = dataelem.value;
	var checkflag = elem.checked;
	var field = document.getElementsByName(name);
	var dataarray= data.split(",");
	var values = "";
	if(checkflag){
		for (var i = 0; i < field.length; i++) {
			if(in_array(field[i].value, dataarray) == "false"){
				if(dataarray[0] == "")
					dataarray.splice(0,1,field[i].value);
				else
					dataarray.splice(0,0,field[i].value);
			}
			
		}
		
	}else{
		for (var i = 0; i < field.length; i++) {
			index = in_array(field[i].value, dataarray);
			if(index != "false")
				dataarray.splice(index,1);
			
		}
	}
	var newvalue = dataarray.toString();
	dataelem.value = newvalue;
	return dataelem.value;
}

function addCheckedValue(dataelem,elem){
	var data = dataelem.value;
	var checkflag = elem.checked;
	var dataarray= data.split(",");
	var checkvalue = elem.value;
	
	if(checkflag){
		if(dataarray[0] == "")
			dataarray.splice(0,1,checkvalue);
		else
			dataarray.splice(0,0,checkvalue);
	}else{
		index = in_array(checkvalue, dataarray);
		if(index != "false")
			dataarray.splice(index,1);
	}
	
	var newvalue = dataarray.toString();
	newvalue.substring(0, newvalue.length-1);
	dataelem.value = newvalue;
	return dataelem.value;
}

function in_array(key,anarray){
	var index = "false";
	for(var i = 0; i < anarray.length; i++){
		if(key == anarray[i]){
			index = i;
		}
	}
	return index;
}

function uncheck(name){
	var field = document.getElementsByName(name);
	for(var i = 0; i < field.length; i++){
		field[i].checked = false;
	}
}

function to2digit(value){
	if (value >= 10)
		return value;
	else
		return '0' + value;	
		
}

function getDate(value, startid, endid){
	if(value == '')
		return;
	var startElement = document.getElementById(startid);
	var endElement = document.getElementById(endid);
	var value_array = value.split(" ");
	var num = value_array[0];
	var quantity = (value_array[1]) ? value_array[1] : "month";
	var today = new Date();
	var startDate = new Date();
	var endDate = new Date();
	startDate.setHours("00");
	startDate.setMinutes("00");
	startDate.setSeconds("00");	
	
	switch(quantity.toLowerCase()){
		case "day" :
		case "days":
			startDate.setDate(today.getDate() - num);	
			if(num > 0){				
				endDate.setDate(today.getDate()- num);
				endDate.setHours("23");
				endDate.setMinutes("59");
				endDate.setSeconds("59");	
			}
			break;
		case "week":
		case "weeks":
			day = startDate.getDay();
			startDate.setDate(today.getDate() - (num * 7 + day-1));	
			
			if(num > 0){				
				endDate.setDate(today.getDate() - ((num-1) * 7 + day)) ;
				
				endDate.setHours("23");
				endDate.setMinutes("59");
				endDate.setSeconds("59");	
			}
			break;
		case "month":
		case "months":
			startDate.setDate("01");
			startDate.setMonth(today.getMonth() - num);	
			
			if(num > 0){				
				endDate = new Date(startDate.getFullYear(), startDate.getMonth()+1, 0);	
				endDate.setHours("23");
				endDate.setMinutes("59");
				endDate.setSeconds("59");	
			}
			break;
		default:
			break;
	}
	 
	if(startElement)
		startElement.value = convertDate(startDate);
	if(endElement)
		endElement.value = convertDate(endDate);
			
	return(convertDate(startDate) + "=" + convertDate(endDate));
}

//format yyyy-mm-dd hh:mm:ss
function convertDate(date){
	thisdate = date.getDate();
	thismonth = date.getMonth() + 1;
	thisyear = date.getFullYear();
	thishour = date.getHours();
	thisminute = date.getMinutes();
	thissecond = date.getSeconds();
	
	return (thisyear + "-" + to2digit(thismonth) + "-" + to2digit(thisdate) + " " + to2digit(thishour) + ":" + to2digit(thisminute) + ":" + to2digit(thissecond));
}

//Layer Position
//if(window.Event && document.captureEvents)
	//document.captureEvents(Event.MOUSEMOVE);
function setPosition(d, e){	
	var elem = document.getElementById(d);
	if(!e) var e = window.event || window.Event;
		
	var cX = 0;
	var cY = 0;
	if (e.pageX || e.pageY) 	{
		cX = e.pageX;
		cY = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		cX = e.clientX;
		cY = e.clientY;
	}
	
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	}else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	}else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}
	if(document.all) {
		cX += rX; 
		cY += rY;
	}
	if(elem){
		if(cY < 200) cY = 200;
		
		elem.style.display = "none";
		elem.style.right = (cX) + "px";
		elem.style.top = (cY) + "px";
	}
	
	//alert("X=" + elem.style.right + "; Y=" + elem.style.top);
}
/*
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	}else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	}else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}
	if(document.all) {
		cX += rX; 
		cY += rY;
	}
	d.style.right = (cX+10) + "px";
	d.style.top = (cY+10) + "px";
}*/

function GetViewportWidth()  {
	
	 var viewportwidth;
	 
	//Non-IE
	 if (typeof( window.innerWidth) == 'number' ) {
		 viewportwidth = window.innerWidth;
	 }
	 
	 //IE 6+ in 'standards compliant mode'
	 else if (document.documentElement
	     && document.documentElement.clientWidth) {
		 viewportwidth = document.documentElement.clientWidth;
	 }
	 
	//IE 4 compatible
	 else if ( document.body && document.body.clientWidth)  {
		 viewportwidth = document.body.clientWidth;
	 }
	 
	 return viewportwidth;
}


function GetViewportHeight()  {
	
	 var viewportheight;
	 
	//Non-IE
	 if (typeof( window.innerHeight ) == 'number' ) {
		 viewportheight = window.innerHeight;
	 }
	 
	 //IE 6+ in 'standards compliant mode'
	 else if (document.documentElement
	     && document.documentElement.clientHeight) {
		 viewportheight = document.documentElement.clientHeight;
	 }
	 
	//IE 4 compatible
	 else if ( document.body && document.body.clientHeight)  {
		 viewportheight = document.body.clientHeight;
	 }
	 
	 return viewportheight;
   }

function getScrollX() {
	  var scrOfX = 0;
	  if( typeof( window.pageXOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfX = window.pageXOffset;
	  } else if( document.body && document.body.scrollLeft) {
	    //DOM compliant
	    scrOfX = document.body.scrollLeft;
	  } else if (document.documentElement && document.documentElement.scrollLeft) {
	    //IE6 standards compliant mode
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return scrOfX;
	}

 function getScrollY() {
	  var scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	  } else if( document.body && document.body.scrollTop) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	  } else if( document.documentElement && document.documentElement.scrollTop) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	  }
	  return scrOfY;
	}

 
function ShowContent(id) {
	if(id.length < 1) { return; }
	//var dd = document.getElementById(d);
	//dd.style.display = "block";
	
	var viewportwidth = GetViewportWidth();
	var viewportheight = GetViewportHeight();
	var scrOfX = getScrollX();
	var scrOfY = getScrollY();
	
	var heightDiff;
	
	if (document.getElementById) { 
		
		var elem = document.getElementById(id);
		elem.style.display = 'block'; 
		
		oHeight = elem.offsetHeight;
		oWidth = elem.offsetWidth;
		
		heightDiff = oHeight / 2;
		
		//first time when popup appears, the DIV height is 30px
		if (oHeight < 50)  {
			heightDiff = viewportheight / 3;
		}
		elem.style.top = parseInt(((viewportheight / 2) - heightDiff)  + scrOfY);
		elem.style.left = parseInt(((viewportwidth / 2) - (oWidth / 2)) + scrOfX);
	
	} else if (document.layers) { 
			var elem = document.layers[id];
			elem.display = 'block'; 	
			
			oHeight = elem.height;
			oWidth = elem.width;
			
			heightDiff = oHeight / 2;
			
			if (oHeight < 50)  {
				heightDiff = viewportheight / 3;
			}
			
			document.layers[id].top = parseInt(((viewportheight / 2) - heightDiff)  + scrOfY);
			document.layers[id].left = parseInt(((viewportwidth / 2) - (oWidth / 2)) + scrOfX);
			
		} else if (document.all) { 
			
			elem = document.all[id];
			elem.style.display = 'block'; 
			
			oHeight = elem.offsetHeight;
			oWidth = elem.offsetWidth;
			
			heightDiff = oHeight / 2;
			
			//first time when popup appears, the DIV height is 30px
			if (oHeight < 50)  {
				heightDiff = viewportheight / 3;
			}
			
			elem.style.top = parseInt(((viewportheight / 2) - heightDiff)  + scrOfY);
			elem.style.left = parseInt(((viewportwidth / 2) - (oWidth / 2)) + scrOfX);
			
		}
	}
//end Layer Position


//Check for flash
function hasFlash(){
	var flashinstalled = false;
	if (navigator.plugins && navigator.plugins.length)
	{
		if (navigator.plugins["Shockwave Flash"] || navigator.plugins["Shockwave Flash 2.0"])
		{
			flashinstalled = true;
		}
	}else if (navigator.mimeTypes && navigator.mimeTypes.length)
	{
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin){
			flashinstalled = true;
		}
	}else{
		for(var i=7; i>0; i--){
			try{
				var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
				flashinstalled = true;
				break;
			}
			catch(e){
			}
		}
	}
	return flashinstalled;	
}

function displayLoading(){
	clearTimeout(timer10);
	document.getElementById("loaded").style.display='none';
	document.getElementById("loading").style.display = 'block';    
}

function displayLoaded(){
	clearTimeout(timer10);
 	timer10 = setTimeout("document.getElementById('loading').style.display = 'none';document.getElementById('loaded').style.display='block'", 1000);
}

function is_ie(){
	var agt=navigator.userAgent.toLowerCase();
	var ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	return ie;
}

function ScrollTo(id){
	var element = document.getElementById(id);
	//alert(element.offsetTop);
	var position = element.offsetTop;
	
	//alert(position);
	if(!is_ie())
		window.scroll(0, position);
	else
		window.scrollTo(0, position);
}

function Hide(id){
	if (document.getElementById) { 
		if(document.getElementById(id))
			document.getElementById(id).style.display = 'none'; 		 
	} else { 
		if (document.layers) { 
			if(document.id)
				document.id.display = 'none';  
		} else { 
			if(document.all.id)
				document.all.id.style.display = 'none';
		}
	} 
}



