/**
 * 2006.06.28 yhbyun created
 */

function trim(str){
   return(trimExt(str,' '));	
}


function trimExt(str,ch){
   if(str == null) return(null);
   	
   var start = 0,end = 0;
   var i = 0;
   while(i<str.length){
   	  if(str.charAt(i) == ch){
   	  	i++;
   	  }else{
   	    start = i;
   	    break;
   	  }
   }
   
   i = str.length -1;
   while(i>=0){
   	  if(str.charAt(i) == ch){
   	  	i--;
   	  }else{
   	    end = i + 1;
   	    break;
   	  }
   }   
   
   return(str.substring(start,end));
}


function isNumber(value){
	if(trim(value)!=''&&!isNaN(value)&&(value.indexOf('.')==-1)){
		return(true);
	}
	
	return(false);
}

function isEnglish(sValue){
	var myReg=/[^\x00-\x80]/g;
	if(myReg.test(sValue)){
		return false;
	} else {
		return true;
	}
}

function initSelectWithValue(selectObj,oldValue){
  for(var i=0;i<selectObj.length;i++){
    if(selectObj.options[i].value == oldValue){
      selectObj.options[i].selected = true;
      break;
    }
  }
}


function getCookie(name) {
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	
	if ((!start) && (name != document.cookie.substring(0, name.length))) return '';
	if (start == -1) return '';
	
	var end = document.cookie.indexOf(";",len);
	
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}


//SuckerTree Horizontal Menu (Sept 14th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/
var menuids=["topmenu"] //Enter id(s) of SuckerTree UL menus, separated by commas
function build_topmenu(){
	var bodytag = document.getElementsByTagName("body")[0];
	if (bodytag.id != "") {
		var atag = document.getElementById(bodytag.id + "_menu");
		if (atag != undefined) {	
			atag.className = "current";
		}
	}

	for (var i=0; i<menuids.length; i++){
		var menutag = document.getElementById(menuids[i]);
		if (menutag != undefined) {
			var ultags = document.getElementById(menuids[i]).getElementsByTagName("ul");
			for (var t=0; t<ultags.length; t++){
				if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
					ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px"; //dynamically position first level submenus to be height of main menu item
					ultags[t].style.left="0px";
					ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon";
				}
			
				ultags[t].parentNode.onmouseover=function(){
					this.getElementsByTagName("ul")[0].style.visibility="visible"
				}
				ultags[t].parentNode.onmouseout=function(){
					this.getElementsByTagName("ul")[0].style.visibility="hidden"
				}
			}
		}
	}
}

if (window.addEventListener)
window.addEventListener("load", build_topmenu, false);
else if (window.attachEvent)
window.attachEvent("onload", build_topmenu);


function getKeywordForUrl(keywords){
    keywords = keywords.replace(/[ "]/g, "_");
    keywords = keywords.replace(/__*/g, "_");
	keywords = escape(keywords);
	keywords = keywords.replace(/\./g, "%2E"); //2010.06.10 yhbyun computer ltd,. °Ë»ö¾î ¶§¹®
	
	return keywords;
}


function DoSimpleSearch(form) {
	var keywords = form.qu.value;
	if(keywords == 'Search all suppliers' || keywords == ""){
		alert("Please enter search keywords.");
		form.qu.focus();
		return false;
	}

	/*
	regexp = /^[a-z0-9][a-z0-9_ +]*$/i;
	if(keywords.search(regexp) ==-1){
		alert("Please use only letters(a-z) and numbers(0-9) for your keyword.");
		return false;
	}
	*/

	if (keywords.indexOf(">") > -1 || keywords.indexOf("<") > -1 ) {
		alert("Please do not enter these signs <  ,  >  in the keyword.");
		form.qu.focus();
        return false;
	}

	if (keywords.length > 50) {
        alert('please input a search term less than 50 characters.');
        form.qu.focus();
        return false;
    }

	if (!isEnglish(keywords)) {
        alert('Sorry, the information you filled in is not in English.\nPlease input the information in English instead.');
        form.qu.focus();
        return false;
    }

	keywords = getKeywordForUrl(keywords);
	location.href = 'http://www.ecplaza.net/search/0s1nf20sell/' + keywords + '.html';
	return false;
}

