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 && keycode!=9) { //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 || navigator.userAgent.indexOf("Opera")>=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 **/
function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 6000);

	//Hide the current image
	current.animate({opacity: 0.0}, 6000)
	.removeClass('show');
	
}

function showhideloginbox() {
	if(document.getElementById('signin_menu').style.display=="none") {
		document.getElementById('signin_menu').style.display="block";
	} else {
		document.getElementById('signin_menu').style.display="none";		
	}
}

function homepagescoller(prev1) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');

	
	//if prev is set to 1 (previous item)
	if (prev1) {		
		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
	
	//if prev is set to 0 (next item)
	} else {		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
	}

	//clear the selected class
	$('#gallery li').removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');
	

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image,800);
}

function ajax_stucture_image(keyword,divId,month) {	
	var stuct_array = keyword.split('^^^');
	var url1= "strimg.php?keyword="+stuct_array[0];	
	if(divId!=undefined)
	{
		var url1= "strimg.php?divId="+divId+"&Type="+month+"&keyword="+stuct_array[0];	
	}	
	xmlHttp1=GetXmlHttpObject(strimgChanged)
	xmlHttp1.open("GET", url1, true)
	xmlHttp1.send(null)
	return false;	
}
function showhide(id, flag)
{
	document.getElementById(id).style.display = 'inline';
	if(flag == 'show') {
		document.getElementById(id).style.display = '';
	}
	else {
		document.getElementById(id).style.display = 'none';
	}
}
