var hex=new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
function stringEncodex(preescape){
			var escaped="";
			
			var i=0;
			for(i=0;i<preescape.length;i++)
			{
				escaped=escaped+encodeCharx(preescape.charAt(i));
			}
			
			return escaped;
}
		
function encodeCharx(original){
 	   	var found=true;
 	   	var thecharchar=original.charAt(0);
  	   	var thechar=original.charCodeAt(0);
		switch(thecharchar) {
				case '\n': return "\\n"; break; //newline
				case '\r': return "\\r"; break; //Carriage return
				case '\'': return "\\'"; break;
				case '"': return "\\\""; break;
				case '\&': return "\\&"; break;
				case '\\': return "\\\\"; break;
				case '\t': return "\\t"; break;
				case '\b': return "\\b"; break;
				case '\f': return "\\f"; break;

				default:
					found=false;
					break;
			}
			if(!found)
			{
				if(thechar>127) {
					var c=thechar;
					var a4=c%16;
					c=Math.floor(c/16); 
					var a3=c%16;
					c=Math.floor(c/16);
					var a2=c%16;
					c=Math.floor(c/16);
					var a1=c%16;
				//	alert(a1);
					return "\\u"+hex[a1]+hex[a2]+hex[a3]+hex[a4]+"";		
				}
				else
				{
					return original;
				}
			}
}
function intToHex(num){
   hexStr = "0123456789ABCDEF";
   hex="";
   if (num>=16) {
      hex = hexStr.substr(parseInt(num/16),1);
      num = num%16;
   }
   hex += hexStr.substr(num,1);

   return hex;
}
function hexToInt(h){
   return parseInt("0x"+h);
}

function hexStringToString(buff){
	var buffer = new Array();
	var i=0;
	while (i<buff.length-1){
		var num=buff.substring(i,i+2);
		var ss=String.fromCharCode(hexToInt(num));
		buffer[buffer.length] =ss;
		i=i+2;
	}
	return buffer.join("");
}
function stringToHexString(str){
    var r="";
    var e=str.length;
    var c=0;
    var h;
    while(c<e){
        h=str.charCodeAt(c++).toString(16);
        while(h.length<2) h="0"+h;
        r+=h;
    }
    return r;
}
			
function getMousePositionX(e) {
	try{
		var isIE = document.all?true:false;
		if (e==null) e = window.event;
		var _x=0;
		if (!isIE) {
			_x = e.pageX;
			_x = e.pageX + document.body.scrollLeft;
		}else{
			_x = e.clientX + document.body.scrollLeft;
		}
		return _x+"px";
	}catch(ev){
		return "-100px";
	}

}
function getMousePositionY(e) {
	try{
		var isIE = document.all?true:false;
		if (e==null) e = window.event;
		var _x=0;
		var _y=0;
		if (!isIE) {
			_y = e.pageY;
			_y = e.pageY + document.body.scrollTop;
		}else{
			_y = e.clientY + document.body.scrollTop;
		}
		return _y+"px";
	}catch(ev){
		return "-100px";
	}

}

function smallAlertDialog(title,message,label){
	var backGround = document.createElement('div');       
	backGround.style.backgroundImage = "url(images/content.png)";       
	backGround.style.position = "absolute";       
	backGround.style.width = "100%";       
	backGround.style.height = "2000px";       
	backGround.style.top = "0px";       
	backGround.style.left = "0px";       
	backGround.style.verticalAlign = "middle";       
	backGround.align = "center";
	
	var form = document.createElement('div');       
	form.style.backgroundImage="url(images/panel240x138.gif)";       
	form.style.width = "240px";       
	form.style.height = "138px";       
	form.style.margin="220px";
	form.style.backgroundRepeat="no-repeat";
	
	var header = document.createElement('div');          
	header.className = "sectiontitle";          
	header.innerHTML = "<span style='color:black'><b>"+title+"</b></span>";        
	header.style.marginLeft ="10px";
	header.style.verticalAlign = "middle";  
	header.style.paddingTop="7px";
	
	var content = document.createElement('div');          
	content.style.padding = "5px"; 
	content.style.marginTop="20px";
	content.style.height="60px";
	content.innerHTML = "<span style='color:black'>"+message+"</span>";              

	var cerrar = document.createElement('div');          
	
	var buton = document.createElement('div');             
	buton.className="button75x19";    
	buton.style.marginLeft="90px";
	
	var cmd=document.createElement('a');
	cmd.setAttribute('href', '#');
	cmd.innerHTML = label; 
	cmd.id="23982098093842903";
	cmd.onclick = function() {                
		backGround.style.visibility = "hidden";             
	}; 
	cmd.onblur = function() { 
		document.getElementById("23982098093842903").focus();
	}; 
	buton.appendChild(cmd);
	cerrar.appendChild(buton);
	form.appendChild (header);       
	form.appendChild (content);       
	form.appendChild (cerrar);           
	backGround.appendChild (form);    
	top.document.body.appendChild(backGround);  
	document.getElementById("23982098093842903").focus();
}
function bigAlertDialog(title,message,label){
	var backGround = document.createElement('div');       
	backGround.style.backgroundImage = "url(images/content.png)";       
	backGround.style.position = "absolute";       
	backGround.style.width = "100%";       
	backGround.style.height = "2000px";       
	backGround.style.top = "0px";       
	backGround.style.left = "0px";       
	backGround.style.verticalAlign = "middle";       
	backGround.align = "center";
	
	var form = document.createElement('div');       
	form.style.backgroundImage="url(images/panel400x200.gif)";       
	form.style.width = "400px";       
	form.style.height = "200px";       
	form.style.margin="300px";
	form.style.backgroundRepeat="no-repeat";
	
	var header = document.createElement('div');          
	header.className = "sectiontitle";          
	header.innerHTML = "<span style='color:black'><b>"+title+"</b></span>";        
	header.style.marginLeft ="10px";
	header.style.verticalAlign = "middle";  
	header.style.paddingTop="7px";
	
	var content = document.createElement('div');          
	content.style.padding = "5px"; 
	content.style.marginTop="10px";
	content.style.height="110px";
	content.innerHTML = "<span style='color:black'>"+message+"</span>" ;              

	var cerrar = document.createElement('div');          
	cerrar.style.padding = "5px"; 

	var buton = document.createElement('div');             
	buton.className="button75x19";    
	buton.style.float="right";
	var cmd=document.createElement('a');
	cmd.setAttribute('href', '#');
	cmd.innerHTML = label; 
	cmd.id="23982098093842903";
	cmd.onclick = function() {                
		backGround.style.visibility = "hidden";             
	};
	buton.appendChild(cmd);
	cerrar.appendChild(buton);
	form.appendChild (header);       
	form.appendChild (content);       
	form.appendChild (cerrar);           
	backGround.appendChild (form);    
	top.document.body.appendChild(backGround);  	
	document.getElementById("23982098093842903").focus();
}
function wait(msg,e,time){
	var data ="<span style='color:white;margin-left:7px'><img src='images/bussy.gif' >"+msg+"</span>";
	if ((time==null)|| (time==0)) time=15000;
	window.clearTimeout(waitTimer);
	if (!e) e = window.event;
	var form = document.getElementById('divWait');
	if (form!=null){
		form.style.top = getMousePositionY(e);       
		form.style.left = getMousePositionX(e);   
		form.innerHTML=data;
		form.style.visibility='visible';
	}else{
		form = document.createElement('div');  
		form.id="divWait";
		form.style.position = "absolute";  
		form.style.width = "100px";       
		form.style.height = "20px";  
		form.style.textAlign="left";
		form.style.top = getMousePositionY(e);       
		form.style.left = getMousePositionX(e);   
//		form.style.backgroundColor="white";
//		form.style.border="1px solid white";
		form.innerHTML=data;
		top.document.body.appendChild(form);
	}
	var waitTimer=window.setTimeout("document.getElementById('divWait').style.visibility='hidden'",time);
}
function cancelWait(){
	try{
		document.getElementById('divWait').style.visibility='hidden';
	}catch(e){}
}

function numberToLocaleString(n){
	var num=parseNumber(n);
	return num.toLocaleString();

}
function parseNumber(num){
	var n=new Number(localNumberToNumber(num));
	return n;
}
function localNumberToNumber(num){
	var s="";
	var theDot=false;
	for (i=num.length-1;i>=0;i--){
		var c=num.charAt(i);
		if ((c==',') || (c=='.')){
			if (!theDot){
				theDot=true;
				s='.'+s;
			}
		}else{
			s=c+s;
		}
	}
	return s;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*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);
}
function evalScript(scripts)
{	try
	{	if(scripts != '')	
		{	var script = "";
			scripts = scripts.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
	       	                         if (scripts !== null) script += arguments[1] + '\n';
 	        	                        return '';});
			if(script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
		}
		return false;
	}
	catch(e)
	{	alert(e);
	}
}
function alertContentsInit(http_request, tag_target) {
	  if (http_request.readyState == 4) {
	    if (http_request.status == 200) {
	      result = http_request.responseText;
	      // with this I get all the response that a PHP page build
	      document.getElementById(tag_target).innerHTML = result;
	      evalScripts( result );
	      } 
	    else {
	      alert("There was a problem...");
	      }
	    }
	  }	
