function trim(sString) {
	if(sString) {
		while (sString.substring(0,1) == ' ')
		{
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
			sString = sString.substring(0,sString.length-1);
		}
	}
	return sString;
}
function changeText(obj, defaultVal, type) {
	if(trim(obj.value) == '' && type == 'blur') {
		obj.value = defaultVal;
	}
	if(obj.value == defaultVal && type == 'focus') {
		obj.value = '';
	}
}
function popupWindow(url, width, height, resizable, scrollbars , top, left) {
	if(trim(url) != '') {
		
		if(width == '') { width = 150; }
		if(height == '') { height = 150; }
		
		resizable = resizable;
		if(resizable == '') { resizable = 'yes'; }
		
		scrollbars = scrollbars;
		if(scrollbars == '') { scrollbars = 'no'; }
		
		if(top == '') { top = 50; }
		if(left == '') { left = 50; }
		
		window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=' + resizable + ',copyhistory=no,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left );
		
	}
}
/** 
 * validate for allow only numeric value 
**/
function NumericValidation(eventObj) {
	var keycode;		
    if(eventObj.keyCode) {//For IE
        keycode = eventObj.keyCode;
    } else if(eventObj.Which) {
        keycode = eventObj.Which;  // For FireFox
    } else {
        keycode = eventObj.charCode; // Other Browser
    }    
    if (keycode!=8) { //if the key is the backspace key
    	/** 
		 *  keycode!=37 for left arrow key
		 *  keycode!=39 for right arrow key
		 *  keycode!=13 for Enter key
		 *  keycode!=35 for Home key
		 *  keycode!=36 for End key
		 *  keycode!=46 for Delete key
		**/
    	if ((keycode<48||keycode>57) && keycode!=37 && keycode!=39 && keycode!=13 && keycode!=35 && keycode!=36 && keycode!=46) {//if not a number
			return false; // disable key press
    	} else {            
        	return true; // enable key press
    	}
     }        
}
function OpenHelp(url) {	
	var hreflink = '/studio_help.php';
	GB_showCenter('Studio Help', hreflink, 625, 960);
}

function emailValidate(email) {
	var error = '';
	var emailFilter=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	if (email.search(emailFilter) == -1) {
	       error = "error";
	}
	return error;
}
// Start isNumber function
function isNumber(numstr, errString) {
	
	numdecs = 0;
	for (i = 0; i < numstr.length; i++) {
		mychar = numstr.charAt(i);
		if ((mychar >= "0" && mychar <= "9") || mychar == "." ) {
			if (mychar ==  ".")
				numdecs++;
		} else {
			return errString;
		}
	}
	
	if (numdecs > 1) {
		return errString;
	}
	return '';
}

// Start isNumber function
function isCurrency(numstr, errString, dec_point, thousand_sep) {
	if(dec_point == '' || (thousand_sep != '.' && thousand_sep != "" )) {
		dec_point = '.';
	}
	if(thousand_sep == '' || (dec_point != ',' && dec_point != "" )) {
		thousand_sep = ',';
	}
	numdecs = 0;
	for (i = 0; i < numstr.length; i++) {
		mychar = numstr.charAt(i);
		if ((mychar >= "0" && mychar <= "9") || mychar == dec_point || mychar == thousand_sep ) {
			if (mychar == dec_point)
				numdecs++;
		} else {
			return errString;
		}
	}
	
	if (numdecs > 1) {
		return errString;
	}
	return '';
}
// end isNumber function


// Start : Ajax Object creation Function //
function GetXmlHttpObject(handler)
{
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This Site doesn't work in Opera")
		return
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		}
		try
		{
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler
			return objXmlHttp
		}
		catch(e)
		{
			alert("Error. Scripting for ActiveX might be disabled")
			return
		}
	}
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler
		return objXmlHttp
	}
}
// End : Ajax Object creation Function //

/** For search country in admin CSV user csv help **/
function ajax_user_country_search(keyword) {
	var keyword = document.getElementById('searchcountry').value;
	var url1= "user_csv_help_country.php?keyword="+keyword;
	xmlHttp1=GetXmlHttpObject(stateChanged)
	xmlHttp1.open("GET", url1, true)
	xmlHttp1.send(null)
	return false;	
}

function stateChanged() {
	if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete") {
		document.getElementById("divCountry").innerHTML=xmlHttp1.responseText;
	}
}
/** ENd search country in admin CSV user csv help **/

/** For search country in admin CSV user csv help **/
function ajax_tax_type_search(keyword) {
	var keyword = document.getElementById('searchtaxtype').value;
	var url1= "user_csv_help_taxtype.php?keyword="+keyword;
	xmlHttp1=GetXmlHttpObject(taxChanged)
	xmlHttp1.open("GET", url1, true)
	xmlHttp1.send(null)
	return false;	
}

function taxChanged() {
	if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete") {
		document.getElementById("divTaxttype").innerHTML=xmlHttp1.responseText;
	}
}
/** ENd search country in admin CSV user csv help **/
