function leftTrim(sString) 
{	
	while (sString.substring(0,1) == ' ')
	{
	sString = sString.substring(1, sString.length);
	}
	return sString;
}

function rightTrim(sString) 
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function trimAll(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 XXreposLoader(){
/*
	imgheight = 100;
	imgwidth = 100;
	tp = (window.innerHeight/2)-(imgheight/2);
	lf = (window.innerWidth/2)-(imgwidth/2);
	document.getElementById("loaderindicator").style.top = tp;
	document.getElementById("loaderindicator").style.left = lf;
    document.getElementById("loaderindicator").style.display = "";
*/
}

function chageAboutMenu($activemenu){
	if ($activemenu==1)
		document.getElementById('mn1').className = "submenuactive";
	else
		document.getElementById('mn1').className = "submenu";
		
	if ($activemenu==2)
		document.getElementById('mn2').className = "submenuactive";
	else
		document.getElementById('mn2').className = "submenu";

	if ($activemenu==3)
		document.getElementById('mn3').className = "submenuactive";
	else
		document.getElementById('mn3').className = "submenu";
}

function shide(mid){	
	if (document.getElementById('mn'+mid).style.display =="")
		document.getElementById('mn'+mid).style.display = "none";
	else
		document.getElementById('mn'+mid).style.display = "";
}

function LoadSubProd(){
	var list = document.getElementById("prodList");	
	
	var val = list.selectedIndex;

	var list2 = document.getElementById("subprodList");
	
	var listSize = 1;
	
	if(val>0){ 
		listSize= subp[val].length - 1;		
		list2.length = listSize;
		for (i=0;i<listSize;i++){		
			if(subp[val][i+1] != ""){
				option0 = new Option(subp[val][i+1],subp[val][i+1])
				list2.options[i+1] = option0;		
			}
		}
	} else {
		list2.length = listSize;
	}	
}

function get(obj, turl) {
  var getstr = "?";
  for (i=0; i<obj.elements.length; i++) {
	 
	 if (obj.elements[i].tagName == "INPUT") {
		if (obj.elements[i].type == "text") {
		   if (i>0) getstr += "&";
		   getstr += obj.elements[i].name + "=" + obj.elements[i].value;
		}
		if (obj.elements[i].type == "checkbox") {
		   if (obj.elements[i].checked) {
			  if (i>0) getstr += "&";
			  getstr += obj.elements[i].name + "=" + obj.elements[i].value;
		   } else {
			  if (i>0) getstr += "&";
			  getstr += obj.elements[i].name + "=&";
		   }
		}
		if (obj.elements[i].type == "radio") {
		   if (obj.elements[i].checked) {
			  if (i>0) getstr += "&";
			  getstr += obj.elements[i].name + "=" + obj.elements[i].value;
		   }
		}
	 }   
	 if (obj.elements[i].tagName == "SELECT") {
		var sel = obj.elements[i];
		if (i>0) getstr += "&";
		getstr += sel.name + "=" + sel.options[sel.selectedIndex].value;
	 }
	 if (obj.elements[i].tagName == "TEXTAREA") {
		if (i>0) getstr += "&";
		getstr += obj.elements[i].name + "=" + obj.elements[i].value;
	 }
	 
  }
 
  getstr = getstr.replace(/\n/g,"%0D");
  //alert(getstr);
  preLoad(turl + getstr);
}

function reposLoader(){
var windowState = (function(){
var readScroll = {scrollLeft:0,scrollTop:0};
var readSize = {clientWidth:0,clientHeight:0};
var readScrollX = 'scrollLeft';
var readScrollY = 'scrollTop';
var readWidth = 'clientWidth';
var readHeight = 'clientHeight';
function otherWindowTest(obj){
if((document.compatMode)&&
(document.compatMode == 'CSS1Compat')&&
(document.documentElement)){
return document.documentElement;
}else if(document.body){
return document.body;
}else{
return obj;
}
};
if((typeof this.innerHeight == 'number')&&
(typeof this.innerWidth == 'number')){
readSize = this;
readWidth = 'innerWidth';
readHeight = 'innerHeight';
}else{
readSize = otherWindowTest(readSize);
}
if((typeof this.pageYOffset == 'number')&&
(typeof this.pageXOffset == 'number')){
readScroll = this;
readScrollY = 'pageYOffset';
readScrollX = 'pageXOffset';
}else{
readScroll = otherWindowTest(readScroll);
}
return {
getScrollX:function(){
return (readScroll[readScrollX]||0);
},
getScrollY:function(){
return (readScroll[readScrollY]||0);
},
getWidth:function(){
return (readSize[readWidth]||0);
},
getHeight:function(){
return (readSize[readHeight]||0);
}
};
})();


var viewPortWidth = windowState.getWidth();
var viewPortHeight = windowState.getHeight();
var horizontalScroll = windowState.getScrollX();
var verticalScroll = windowState.getScrollY();

var hPos = Math.round(horizontalScroll+((viewPortWidth-100)/2));
var vPos = Math.round(verticalScroll+((viewPortHeight-100)/2));
hPos = (hPos < 0)?0:hPos;
vPos = (vPos < 0)?0:vPos;

function getStyleObj(id){
var obj = null;
if(document.getElementById){
obj = document.getElementById(id);
}else if(document.all){
obj = document.all[id];
}else if(document.layers){
obj = document.layers[id];
}
return (obj && obj.style) || obj;
}

var divStyleRef = getStyleObj("loaderindicator");
if(divStyleRef){
	var positionMod = (typeof divStyleRef.top == 'string')?"px":0;
	divStyleRef.top = vPos + positionMod;
	divStyleRef.left = hPos + positionMod;
}

document.getElementById("loaderindicator").style.display = "";
//document.getElementById("overlaybox").className = "TB_overlay";

}

function scrollloader(){
	if (document.getElementById("loaderindicator").style.display != "none"){
		reposLoader();
	}
}

		
function validEmail(email) {
	invalidChars = " /:,;"

	if (email == "") {						// cannot be empty
		return false
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {					// and at least one "." after the "@"
		return false
	}
	if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
		return false
	}
	return true
}


function checkSearchStringInput(searchtextbox)
{ 	 
	//alert(frm.keyword.value);
	if (trimAll(searchtextbox.value)=="")
 	{ 
		searchtextbox.focus();
		return false;
 	} 	
	return true;
}


function checkInput(frm)
{ 	
 	//alert(frm.prodList.value);
	
	if (trimAll(frm.pname.value)=="")
 	{ alert("Please input name!");
 	frm.pname.focus();
 	return false;
 	}  
 	
 	if (trimAll(frm.email.value)=="")
 	{ alert("Please input email!");
 	frm.email.focus();
 	return false;
 	}  

 	if (!validEmail(frm.email.value))
 	{ alert("Mail address is not valid!");
 	frm.email.focus();
 	return false;
 	}  

 	if (frm.prodList.value=="0")
 	{ alert("Please input product!");
 	frm.prodList.focus();
 	return false;
 	}  
	return true;

}

function checkInputContact(frm)
{ 	
 	//alert(frm.prodList.value);
	
	if (trimAll(frm.pname.value)=="")
 	{ alert("Please input name!");
 	frm.pname.focus();
 	return false;
 	}  
 	
 	if (trimAll(frm.email.value)=="")
 	{ alert("Please input email!");
 	frm.email.focus();
 	return false;
 	}  

 	if (!validEmail(frm.email.value))
 	{ alert("Mail address is not valid!");
 	frm.email.focus();
 	return false;
 	}  

 	if (frm.aboutList.value=="0")
 	{ alert("Please input message about!");
 	frm.aboutList.focus();
 	return false;
 	}  
	return true;

}


