 function uzXmlHttp(){       
    var xmlhttp = false;      
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(e){
            xmlhttp = false;
        }
    }
    if(!xmlhttp && document.createElement){
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;  
}   
   
var i=0;
var ie=(document.all)?1:0;
var ns=(document.layers)?1:0;

function initStyleElements(){
		var c = document.pad;
		if (ie)
			{
				//c.text.style.backgroundColor="#DDDDDD";
				c.compileIt.style.backgroundColor="#C0C0A8";
				c.compileIt.style.cursor="hand";
				c.select.style.backgroundColor="#C0C0A8";
				c.select.style.cursor="hand";
				c.view.style.backgroundColor="#C0C0A8";
				c.view.style.cursor="hand";
				c.retur.style.backgroundColor="#C0C0A8";
				c.retur.style.cursor="hand";
				c.clear.style.backgroundColor="#C0C0A8";
				c.clear.style.cursor="hand";
			}
		else return;
	}

/* Buttons Enlightment of "Compilation" panel */
function LightOn(what)
	{
		if (ie) what.style.backgroundColor = '#E0E0D0';
		else return;
	}
function FocusOn(what)
	{
		if (ie) what.style.backgroundColor = '#EBEBEB';
		else return;
	}
function LightOut(what)
	{
		if (ie) what.style.backgroundColor = '#C0C0A8';
		else return;
	}
function FocusOff(what)
	{
		if (ie) what.style.backgroundColor = '#DDDDDD';
		else return;
	}
/* Buttons Enlightment of "Compilation" panel */

function generate() /* Generation of "Compilation" */
	{
		code = document.pad.text.value;
		if (code)
			{
				document.pad.text.value='Compiling...Please wait!';
				setTimeout("compile()",0);
			}
		else alert('First enter something to compile and then press CompileIt')
	}
function compile() /* The "Compilation" */
	{
		document.pad.text.value='';
		compilation=escape(code);   
		myString = new String(compilation);
		rExp = /%/gi;
		newString = new String("\\");
		results = myString.replace(rExp, newString);
		document.pad.text.value=results;
		i++;
		if (i=1) alert("Page compiled 1 time!");
		else alert("Page compiled "+i+" times!");
	}
function selectCode() /* Selecting "Compilation" for Copying */
	{
		if(document.pad.text.value.length>0)
			{
				document.pad.text.focus();
				document.pad.text.select();         
			}
		else alert('Nothing for be selected!')
	}
function preview() /* Preview for the "Compilation" */
	{
		if(document.pad.text.value.length>0)
			{
				pr=window.open("","Preview","scrollbars=1,menubar=1,status=1,width=700,height=320,left=50,top=110");
				pr.document.write(document.pad.text.value);
			}
		else alert('Nothing for be previewed!')
	}
function uncompile(unic){
		if (unic.length>0)	{            
				myString = new String(unic); 
				rExp = /\\/gi;                    
				newString = new String("%");
				results = myString.replace(rExp, newString);
				source=unescape(results);				     
				return source;                
		}else{
			alert('You need compiled code to uncompile it!');
		}   
}    
		
function AlertMessageText(var1,keyMsg){              
    var result;     
    var url = "AlertMsgs/AlertMsgClassic1.php?keyMsg="+keyMsg;                            
    xmlhttp = uzXmlHttp();                 
    xmlhttp.open("GET", url, false);   
    xmlhttp.send(null);                    
    result = xmlhttp.responseText;        
 	var idiv = window.document.getElementById(var1);        	              
    idiv.innerHTML = result;                  
}                 
function requestHtmlText(reqUrl){                
	var urlCall = reqUrl;         
	var result;                         
    var url = urlCall;
	xmlhttp = uzXmlHttp();                       
    xmlhttp.open("GET", url, false);   
    xmlhttp.send(null);    
    result = xmlhttp.responseText;        
 	var idiv = window.document.getElementById("displayDiv");        	
	if(idiv!=undefined)          
	    idiv.innerHTML = result;                  
} 
function requestHtmlTextOnly(reqUrl){                
	var urlCall = reqUrl;         
	var result;                         
    var url = urlCall;
	xmlhttp = uzXmlHttp();                       
    xmlhttp.open("GET", url, false);   
    xmlhttp.send(null);    
    result = xmlhttp.responseText;          
	return trim(result); 
}  
function requestHtmlText(reqUrl,displayDiv){              
	var urlCall = reqUrl+"&ranseq="+Math.random(); 
	//alert("["+displayDiv+"] urlCall -:- "+urlCall);                  
	var result;                              
    var url = urlCall;
	xmlhttp = uzXmlHttp();                       
    xmlhttp.open("GET", url, false);                        
    xmlhttp.send(null);    
    result = xmlhttp.responseText;        
 	var idiv = window.document.getElementById(displayDiv);        	
	if(idiv!=undefined){                                          
		idiv.innerHTML = result;      
	}else
		alert(displayDiv+" is undefined ");
}             
function ajaxPost(reqUrl){
	var result;       
	var url = reqUrl+"&ranseq="+Math.random();    
	xmlhttp = uzXmlHttp();      
	xmlhttp.open("POST", url, false);
	xmlhttp.send(null);
	result = xmlhttp.responseText;
	return result;
}   
function displaydropdown(div,key){
	var countlist =	document.forms[0].elements[div].length;
	for(var i = 0;i<countlist;i++){                                                                             
			document.forms[0].elements[div].selectedIndex = key;
	}
}
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function fn_AutoSelected(id,key){
			var ptest = window.document.getElementById(id);
			for(var i=0;i<ptest.length;i++){ 
				//alert(ptest.options[i].value);
				if(ptest.options[i].value==key)
					ptest.options[i].selected = true;
			} 
}    
function fn_autoSelected(ptest,key){  
			for(var i=0;i<ptest.length;i++){ 
				//alert(ptest.options[i].value);
				if(ptest.options[i].value==key)
					ptest.options[i].selected = true;
			} 
}      
/*
function $(var1){
	return	 window.document.getElementById(var1);        	              
}
*/

function fn_AutoChecked(obj, key){
		for(var i=0;i<obj.length;i++){ 
			if(key==""){
				obj[0].checked = true; 
				break;
			}
			if(obj[i].value==key)
				obj[i].checked = true; 
		} 
}                    


 
    

