﻿// example: window.onload=functionName; -> AddLoadEvent(functionName) 
function AddLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function AddPageLoadEvent(aFunction){
  if (navigator.appName == 'Microsoft Internet Explorer'){
    // Ensure that method only runs after dom is loaded.
    setTimeout(function() { aFunction(); }, 0);          
  }
  else{
    aFunction(); 
  }
}

function Get(id){ return document.getElementById(id);}

// id : id of the control
// value : boolean (true/ false )
// UseBlock : bool ,  use  block to display
function SetDisplay( id , value, UseBlock )
{  var type =  UseBlock ? "block" : "inline"; 
  if ( value ) Get(id).style.display = type;else
   Get(id).style.display = "none";
}

// Ajax calls
//how to use
//jx.load('http://sdsad.com',function(data){
//  	/*... do what you want with 'data' varaible ...//  	*/
//  	alert(data);
//	},'text','get');
 jx={http:false,format:'text',callback:function(data){},error:false,getHTTPObject:function(){var http=false;
if(typeof ActiveXObject !='undefined'){try{http=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){
try{http=new ActiveXObject("Microsoft.XMLHTTP");}catch(E){http=false;}}
}else if(XMLHttpRequest){try{http=new XMLHttpRequest();}catch(e){http=false;}}return http},
load:function(url,callback,format){this.init();if(!this.http||!url)return;
if(this.http.overrideMimeType)this.http.overrideMimeType('text/xml');this.callback=callback;
if(!format)var format="text";this.format=format.toLowerCase();var ths=this;
if(this.http.overrideMimeType)this.http.overrideMimeType('text/xml');var now="uid="+new Date().getTime();
url+=(url.indexOf("?")+1)?"&":"?";url+=now;
this.http.open("GET",url,true);this.http.onreadystatechange=function(){
if(!ths)return;var http=ths.http;if(http.readyState==4){if(http.status==200){var result="";
if(http.responseText)result=http.responseText;if(ths.format.charAt(0)=="j"){result=result.replace(/[\n\r]/g,"");
result=eval('('+result+')'); }if(ths.callback)ths.callback(result);}else{if(ths.error)ths.error()}}}
this.http.send(null);},init:function(){this.http=this.getHTTPObject();}}

function BrowserIsActiveXCompatible(){
	blnResult = false;	
	if (navigator.appName.indexOf("Internet Explorer") != -1){		
		blnResult = true;

		// Exclude Opera
		if (navigator.userAgent.indexOf("Opera") != -1)
			blnResult = false;
	}	
	return blnResult;
}
function WindowsXpServicePack2Installed(){
  blnResult = false;
  if (navigator.appName.indexOf("Internet Explorer") != -1){
    if ((navigator.userAgent.indexOf("SV1;") != -1) || (navigator.userAgent.indexOf("SV1)") != -1)){
      blnResult = true;
    }
  }
  return blnResult;
}




