function getElementId(s){
	return (document.getElementById)?document.getElementById(s):document.all[s];
}
function getPair( string ){
	
	var args = new Object();
	var query = string;
	var pairs = query.split("&");
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}
//PreLoader Class
function PreLoader(){
	this.loading = null;
	this.bShow = false;
	this.numLoading = 0;
	this.getPreLoader = function( title ){
 	// Initialize the temporary Panel to display while waiting for external content to load
	YAHOO.namespace("unitedsol");	
	YAHOO.unitedsol.wait = 
			new YAHOO.widget.Panel("wait",{ width:"240px",height:"100px",fixedcenter:true,close:false,draggable:false,modal:true,visible:false,duration:0.5});
		if( title == null || title == "" ){
			YAHOO.unitedsol.wait.setHeader("Loading, please wait...");
		}else{
			YAHOO.unitedsol.wait.setHeader(title + ", please wait...");
		}
		YAHOO.unitedsol.wait.setBody("<div align='center'>please wait...<br /><img src='images/loading.gif' /></div>");
		YAHOO.unitedsol.wait.render(document.body);				
		return YAHOO.unitedsol.wait;
	}
	this.show = function(){
		this.loading.style.display = 'block';
		this.numLoading++;
	}
	this.hide = function(){
		this.numLoading--;
		if(this.numLoading < 1) {
			this.loading = document.getElementById('loading');
			if (this.loading) {
				this.loading.style.display = 'none';
			}
		}
	}
	this.getSimplePreloader=function( title ){
		this.loading = document.getElementById('loading');
		if( title == null || title == "" ){
			title = "Loading...";
		}
		if (!this.loading){
			this.loading = document.createElement('div');
			this.loading.id = 'loading';
			this.loading.innerHTML = '<font style="font-family:verdana; font-size:12px; color:white;">'+title+'</' + 'font>';
			this.loading.style.position = 'absolute';
			this.loading.style.top = '4px';
			this.loading.style.right = '4px';
			this.loading.style.backgroundColor = 'red';
			this.loading.style.width = '80px';
			this.loading.style.padding = '2px';
			document.getElementsByTagName('body').item(0).appendChild(this.loading);
		}		
	}
}
//END PRELOADER CLASS
function DataGrid(){
	//holds the php method which needs to be called
	//this.methodName = method;
	//DIV Object where the data will be shown
	//this.gridId = gid;
	//Preloader, so the user knows the process
	this.preloader = new PreLoader();
	this.URI = "";
	this.goto=function( classMethod,gridId,formId,val ){
		var gridUri=GLOBAL_URI+classMethod;
		this.preloader.getSimplePreloader();
		pre = this.preloader;
		formObject= getElementId(formId);
		formObject.page.value =  val;
		var grid = getElementId(gridId);
		var handleSuccess = function( o ){data = o.responseText;grid.innerHTML=data;pre.hide();}	
		var handleFailure = function( o ){alert("failed to retrieve data!");pre.hide();}	
		var callback = {success:handleSuccess,failure:handleFailure};	
		pre.show();
		YAHOO.util.Connect.setForm(formObject);
		//if we have no file then we need to append the POST data after callback parameter
		connection = YAHOO.util.Connect.asyncRequest("POST" , gridUri+"?ajaxcall=true",callback);
	}
	this.setLimit=function( formid,gridId ){
		this.preloader.getSimplePreloader();
		pre = this.preloader;
		var grid = getElementId(gridId);
		var formObject=getElementId(formid);
		var gridUri=formObject.action+"?ajaxcall=true";
		var handleSuccess = function( o ){data = o.responseText;grid.innerHTML=data;pre.hide();}	
		var handleFailure = function( o ){alert("failed to retrieve data!");pre.hide();}	
		var callback = {success:handleSuccess,failure:handleFailure};	
		pre.show();
		YAHOO.util.Connect.setForm(formObject);
		//if we have no file then we need to append the POST data after callback parameter
		connection = YAHOO.util.Connect.asyncRequest("POST" , gridUri,callback);
	}
		
this.next=function( classMethod,gridId,formId,val ){
		var gridUri=GLOBAL_URI+classMethod;
		formObject= getElementId(formId);
		formObject.page.value =  val;
		var grid = getElementId(gridId);
		var handleSuccess = function( o ){data = o.responseText;grid.innerHTML=data;}	
		var handleFailure = function( o ){alert(o.responseText);}	
		var callback = {success:handleSuccess,failure:handleFailure};	
		YAHOO.util.Connect.setForm(formObject);
		//if we have no file then we need to append the POST data after callback parameter
		//PreLoader.showGrid(grid);		
		connection = YAHOO.util.Connect.asyncRequest("POST",gridUri+"?ajaxcall=true",callback);
	}
	this.gotoPage=function(formId,gridId){
		var formObject=getElementId(formId);
		var gridUri=formObject.action+"?ajaxcall=true";
		var grid=getElementId(gridId);
		totalpages=formObject.totalpages.value;
		inputpageval=formObject.gotopage.value;
		inputpageval=parseInt(inputpageval);
		if(inputpageval==''){alert('please enter the page number');return false;}
		else if(inputpageval>totalpages){alert('please enter the page number between 1 and '+totalpages);return false;}
		else if(parseInt(inputpageval) != inputpageval){
			alert('please enter number only and page number between 1 and '+totalpages);return false;
		}
		else {
			formObject.page.value=formObject.gotopage.value;
			var handleSuccess = function( o ){grid.innerHTML=o.responseText;pre.hide();}	
			var handleFailure = function( o ){alert("failed to retrieve data!");pre.hide();}	
			var callback = {success:handleSuccess,failure:handleFailure};	
			pre.show();
			YAHOO.util.Connect.setForm(formObject);
			//if we have no file then we need to append the POST data after callback parameter
			connection = YAHOO.util.Connect.asyncRequest("POST",gridUri,callback);
		}
		return true;
	}
	this.switchRowCss=function(row,cssClass){
		row.className=cssClass;
	}
	this.swap=function(td){
		/*text = td.innerHTML;
		td.innerHTML="";
		input = document.createElement("input");
		input.value=text;
		td.appendChild(input);*/
	}
}

function CheckAll(frmName)
{
	
	formObject = getElementId(frmName);
	for (var i = 0; i < formObject.elements.length; i++)
	{    
    	eval("formObject.elements[" + i + "].checked = true ");  
		//form.elements[0].checked
    } 

}
function unCheckAll(frmName)
{
	formObject = getElementId(frmName);
	for (var i = 0; i < formObject.elements.length; i++)
	{    
    	eval("formObject.elements[" + i + "].checked = false ");  
		//form.elements[0].checked
    } 

}  
/**
 class Form
**/

function Form( frmName ){
	
	this.formName = frmName
	this.clear = function(){
		
		formObject = getElementId(this.formName);

		for( i = 0; i < formObject.elements.length; i++ ) {
			
			if(formObject.elements[i].type == "text" || formObject.elements[i].type == "file"){
				
				formObject.elements[i].value = "";
				formObject.elements[i].disabled = false;
			}
			
			if(formObject.elements[i].type == "textarea"){
				formObject.elements[i].text = "";
				formObject.elements[i].disabled = false;
			}
		}
		
		return;
	
		}
		//select specific index according to the value
		this.comboSelect = function( selectId, value ){

			selectId = document.getElementById(selectId);
			
			for( i = 0; i < selectId.options.length; i++ ){
				   
				   if( selectId.options[i].value == value ){
					
					   selectId.selectedIndex = i;
				   }
			 }
		}
		
		this.getForm = function(){
			
			return document.getElementById(this.formName);
		}
}