// JavaScript Document

function StrCode(str){
  if (encodeURIComponent)
    return encodeURIComponent(str);
  if (escape)
    return escape(str);
}

function UnStrCode(str){
  if (decodeURIComponent)
    return decodeURIComponent(str);
  if (unescape)
    return unescape(str);
}

function Trim(s){
  var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
  return (m == null) ? "" : m[1];
}

function HtmlEncode(text){
  var re = {
    '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;'
  };
  for (i in re)
    text = text.replace(new RegExp(i, 'g'), re[i]);
  return text;
}

function HtmlDecode(text){
  var re = {
    '&lt;': '<', '&gt;': '>', '&amp;': '&', '&quot;': '"'
  };
  for (i in re)
    text = text.replace(new RegExp(i, 'g'), re[i]);
  return text;
}

function gid(id){
  return document.getElementById ? document.getElementById(id): null;
}

function gna(id){
  return document.getElementsByName ? document.getElementsByName(id): null;
}

function gname(name){
  return document.getElementsByTagName ? document.getElementsByTagName(name):new Array();
}


/*弹出窗口的函数*/
function windowOpen(theURL,width,height)
{
  window.open(theURL,'window','width='+width+',height='+height);
}
/*清空一个选择框的记录*/
function emptySelect(oSelect)
{
 while(oSelect.length>0)
 oSelect.remove(0);	
 oSelect.options.add(new Option("Please select","0"));
}

function getSelectText(obj){
 if(obj==null){
 return "";
 }
 var optionlist=obj.options;
 if(optionlist.selectedIndex>0 && optionlist[optionlist.selectedIndex]!=null)
 return optionlist[optionlist.selectedIndex].text;
 return "";
}

/*设置单选框的值*/
function   setRadioValue(whichformvalue,value)
{
   var radiovalue=whichformvalue;
   if(value!=null)
   {
     for(var i=0;i<radiovalue.length;i++)
     {
      if(radiovalue[i].value==value)
	  {
	      radiovalue[i].checked=true;
	  }
     } 
   }
   else
   {
     radiovalue[0].checked=true;
   }   
}
/*从单选框中过来的数据*/
function getRadioValue(rObj){
	
	if(rObj==null)
	return false;
    for(i=0; i<rObj.length; i++)
	{
		if(rObj[i].checked == true)
		{
			return rObj[i].value ;
		}
	}
}
/**/
function deleteNotice(url,notice)
{
     if(notice=='')
	 notice="The deletion of this information will not be restored, you recognized that the implementation of the deletion?";
    var returnvar=confirm(notice);
   if(returnvar==true)
   {
       self.location=url;
   }
}


/*显示网页的头部*/
function showPageHeader()
{document.writeln("<div id=\"header\"><a href=\"\/index.php\"><img ");
document.writeln("src=\"\/images\/logo\/ENlogo.gif\" alt=\"Back to Homepage\" width=\"167\" height=\"66\" vspace=\"4\" border=\"0\" align=\"left\" \/><\/a>");
document.writeln("  <div id=\"utility\"><a ");
document.writeln("href=\"#\">Help<\/a> <\/div>");
document.writeln("  <div id=\"navbar\">");
document.writeln("    <ul>");
document.writeln("      <li><a title=\"Find suppliers\" ");
document.writeln("  href=\"\/index.php?name=Catalog&handle=buyer\">Buy<\/a><\/li>");
document.writeln("      <li><a title=\"Find buyers\" href=\"\/index.php?name=Catalog&handle=seller\">Sell<\/a> <\/li>");
document.writeln("      <li><a title=\"Find essential trade information and discussion forums\" ");
document.writeln("  href=\"#\">Forum<\/a> <\/li>");
document.writeln("      <li  class=\"noshadow\"><a title=\"Manage your trade activities on Amb2b.com\" ");
document.writeln("  href=\"\/user.php\">My Amb2b<\/a> <\/li>");
document.writeln("    <\/ul>");
document.writeln("  <\/div>");
document.writeln("<\/div>");
}

function showPageFooter()
{	   
document.writeln("<div id=\"footer\">");
document.writeln("  <DIV id=pagetool><A href=\"javascript:emailThisPage()\">Email this page<\/A> <A ");
document.writeln("href=\"javascript:addToFavorite(\'Amb2b focus on Auto-Motor B2B E-commerce\')\">Bookmark ");
document.writeln("    this page<\/A><\/DIV>");
document.writeln("  <HR>");
document.writeln("  <div>  ");
document.writeln("   <a href=\"\/static\/other\/aboutus.htm\" target=\"_blank\">About Us<\/a> | <a href=\"\/static\/help\/rules_and_policies\/intellectual_property_policy.html\" target=\"_blank\">Intellectual");
document.writeln("    Property Policy<\/a> | <a href=\"\/static\/help\/rules_and_policies\/privacy_policy.html\" target=\"_blank\"> Privacy");
document.writeln("    Policy<\/a> | <a href=\"\/static\/help\/rules_and_policies\/terms_of_use.html\">Terms Of Use<\/a> | <a href=\"/index.php?name=EnBugReport&url=http%3A%2F%2Fwww.amb2b.com%2Findex.php%3F\" target=\"_blank\">Send");
document.writeln("    Feedback <\/a> | <a href=\"\/static\/help\/contact_us.html\" target=\"_blank\">Contact");
document.writeln("    Us<\/a> | <a href=\"\/static\/help\/index.html\" target=\"_blank\">Help<\/a> <br \/>");
document.writeln("    Copyright Notice &copy; 2005-2009 Amb2b.com Corporation and its licensors. All rights ");
document.writeln("    reserved. <\/div>");
document.writeln("<\/div>");	
}

/*切换标签*/
function switchNavi(naviElement)
{  
 for(var i=0;i<itemArray.length;i++)
   {
     var naviarray=itemArray[i].split("|");	 
	 var divElement=document.getElementById(naviarray[1]);	;
	 var naviClass =(naviElement.className).substr(0,(naviElement.className).indexOf("_"));	 
	 if(naviarray[0]==naviElement.id)
	 { 
	   document.getElementById(naviarray[0]).className=naviClass+"_On";
	   divElement.style.display="block";
	 }else
	 {
	   document.getElementById(naviarray[0]).className=naviClass+"_Off";
	   divElement.style.display="none";
	 }
   }
}

/*翻页*/
function gotoPage(pagename){
var pagenum=document.getElementById('thispage').value;
if(pagenum!=null && pagenum!=''){
 if(!isNaN(pagenum)){
	this.location=pagename+'&page='+pagenum;
 }
}
}

/**/
function setIframeSrc(elementid,url)
{
  document.getElementById(elementid).src=url;
}

function showLoginAjax(){
//var markDiv=document.createElement("div");
//markDiv.id="markDiv";
var loginDiv= document.createElement("div");
loginDiv.id="loginDiv";
//markDiv.appendChild(loginDiv);
//document.body.appendChild(markDiv);
 document.body.appendChild(loginDiv);
 pullToSpanAjax("/ajax.php?name=UserLogin","loginDiv",'');
}

function userLoginAjax(){
    try{
    var loginDiv= document.getElementById("loginDiv");
    var v_uname=loginDiv.getElementById("").value;
    //var v_pwd=loginDiv.getElementById("pwd").value;  
    alert(v_uname+"|"+v_pwd);
    }catch(e){
	alert(e.message);
    }
}

//保存商业条款模板
function saveTmp(form,handle)
{
	var obj = eval("document."+form);		
	var validdate=getRadioValue(document.getElementsByName("validdate"));
	var packing_type_int=document.getElementById("packing_type_int").value;
	var packing_type_ext=document.getElementById("packing_type_ext").value;
	var delivery_type=getRadioValue(document.getElementsByName("delivery_type"));
	var delivery_time=document.getElementById("delivery_time").value;
	var payment_term=document.getElementById("payment_term").value;
	var guarantee=document.getElementById("guarantee").value;
	var freight=document.getElementById("freight").value;
  
    var url = "/ajax.php?name=StatusSet&handle="+handle;
	var postStr="&validdate="+validdate+"&packing_type_int="+packing_type_int+"&packing_type_ext="+packing_type_ext+"&delivery_type="+delivery_type+"&delivery_time="+delivery_time+"&payment_term="+payment_term+"&guarantee="+guarantee+"&freight="+freight;

	pullToSpanAjax(url,'',postStr,'eval');
}

/*得到多选择框的选择个数*/
function getBoxCheckNum(obj){
	
 if(obj==null){
 return 0;
 }
 var checknum=0;
 //alert(obj);
 for(var i=0;i<obj.length;i++){
	
   if(obj[i].checked==true){
    checknum++;
   }
 }
 return checknum;
}

//
function getMatchResult(searchKey,SearchType)
{
	var url = "ajax.php?name=Match_Prod_list&keyWord="+searchKey+"&SearchType="+SearchType;
	pullToSpanAjax(url,"matchList");
}

//
function getProdDetail(prod_no,type,spanId,hrefId)
{
	var url = "ajax.php?name=Price&prod_no=" + prod_no + "&type=" + type;
	pullToSpanAjax(url,spanId);
	
	if(eval("document.getElementById(\"" + spanId + "\").innerHTML") != "")
	{
		if(eval("document.getElementById(\"" + spanId + "\").style.display") == "block")
		{
			//document.getElementById(spanId).style.display = "none";
			eval("document.getElementById(\"" + spanId + "\").style.display=\"none\"");
			eval("document.getElementById(\"" + hrefId + "\").src=\"/images/icon/add.gif\"");
			//eval("document.getElementById(\"" + hrefId + "\").innerHTML=\"点击查看\"");
		}
		else
		    //(eval("document.getElementById(\"" + spanId + "\").style.display") == "none")
		{
			eval("document.getElementById(\"" + spanId + "\").style.display=\"block\"");
			eval("document.getElementById(\"" + hrefId + "\").src=\"/images/icon/subtract.gif\"");
			//eval("document.getElementById(\"" + hrefId + "\").innerHTML=\"&nbsp;收&nbsp;&nbsp;缩&nbsp;\"");
		}
	}
}

function selectKind2(kind2,kind3)
{	  
        var selectObject=document.getElementById("kind3");
        var phpurl="/ajax.php?name=Kind2_Kind3&kind2="+kind2+"&kind3="+kind3;
        returnValue=getOption(phpurl,selectObject,1,"selectKind3",'');
		emptySelect(document.getElementById("kind4"));
		//document.getElementById('part_detail').style.display='block';		
}	

////
function selectKind3(kind3,kind4)
{	    var selectObject=document.getElementById("kind4");
        var phpurl="/ajax.php?name=Kind3_Kind4&kind3="+kind3+"&kind4="+kind4;
         returnValue=getOption(phpurl,selectObject,1,"",'');
		
		//document.getElementById('part_detail').style.display='block';		
}


function prodErrorClick(ext_prod_no){
pullToSpanAjax("/ajax.php?name=ProdError&ext_prod_no="+ext_prod_no,'','','eval');
}
function changePageItem(oObject){
	var perPageItem = oObject.value;
	var url=$("#thispageitem").val()+"&perPageItem="+perPageItem;
	this.location=url;
	return true;
}
function searchSubmit(formName,objName){
    if(eval("Trim(document." + formName+"."+objName+".value)=='';")){
      alert('Please input a search term.');
      return false;
   }
   //alert(document.SearchForm.action);
   //document.+formName+.submit();
   eval("document."+formName+".submit()");
   //document.SearchForm.submit();
   return true;
    //提交
   //return true;
}
function heardSearchSubmit(){
   //清空默认的内容
   if(Trim(document.heardsearchform.heardsearchtext.value) == 'Search all suppliers' ||
      Trim(document.heardsearchform.heardsearchtext.value) == 'Search all buyers' ||
      Trim(document.heardsearchform.heardsearchtext.value) == ""){
      alert('Please input a search term.');
      return false;
   }
   return true;
}
function inquiryNow(){
	var flag=0;
	var inputSomeId = document.getElementsByName('someid[]');
	for(var i=0;i<inputSomeId.length;i++){
		if(inputSomeId[i].checked ==true){
			flag = 1;
		}
	}
	if(flag==0){
		if(document.getElementById('basket_flag').value=='yes'){
			window.open( '/index.php?name=Basket');
		}else{
			alert('No item(s) selected');
		}
		//return false;
	}else{
		document.msgsendform.submit();
	}
	
	//return true;
}
function addBasket(){
	var flag=0;
	var inputSomeId = document.getElementsByName('someid[]');
	for(var i=0;i<inputSomeId.length;i++){
		if(inputSomeId[i].checked ==true){
			flag = 1;
		}
	}
	if(flag==0){
		alert('No item(s) selected');
		//return false;
	}else{
		document.msgsendform.action='/index.php?name=Basket&handle=add';
		document.msgsendform.submit();
	}
}
function toggleAll(e,chkId,formId){
  if(e.checked) {
    checkAll(chkId,formId);
  }
  else{
    clearAll(chkId,formId);
  }
}

function checkAll(chkId,formId){
  var fo = document.getElementById(formId);
  var len = fo.elements.length;
    for(var i = 0; i < len; i++) {
    var e = fo.elements[i];
    if(e.name == chkId) {
      if(!e.checked){
        e.click();
      }
    }
  }
}

function clearAll(chkId,formId){
  var fo = document.getElementById(formId);
  var len = fo.elements.length;
  for (var i = 0; i < len; i++) {
    var e = fo.elements[i];
    if (e.name == chkId) {
        if(e.checked){
        e.click();
        }
    }
  }
}
function isCheck(chkId,formId,message){
	var boolen = false;
	var fo = document.getElementById(formId);
  var len = fo.elements.length;
  for (var i = 0; i < len; i++) {
    var e = fo.elements[i];
    if (e.name == chkId) {
        if(e.checked){
	        boolen=true;
			break;
        }
    }
  }
  if(!boolen){
	  alert(message);
	  return false;
	  }
}
function makeTextEnglish(){
	return false;
	var objs=$("TEXTAREA,INPUT");
	
	alert(objs.size());
	
	for(var i=0;i<objs.length;i++){
	    if(objs[i].className=="noenglish"){
			return false;		
		}
		
		//当键盘按起的时候
		objs[i].onkeyup= function(){	 	 
		  //累加之前的操作
		  if(this.hasAttribute("onkeyup")){
		   	eval(this.getAttribute("onkeyup"));
		  }
		  if(this.value.match(/[\u4E00-\u9FA5]/g)!=null){
		    this.value=this.value.replace(/[\u4E00-\u9FA5]/g,'');
		  }		  
		}
		 //当改变的时候
		 objs[i].onchange= function(){			 
		 if(this.value.match(/[\u4E00-\u9FA5]/g)!=null){
		  this.value=this.value.replace(/[\u4E00-\u9FA5]/g,'');
		  }	
		}
	}	
}
function showTextNum(formName,textObj,numObj){
	if("undefined" == typeof(formName2))
	{
		formName2	= formName;
		numObj2		= numObj;
		textObj2	= textObj;
	}	
 	eval("document."+formName2+"."+numObj2).value=eval("document."+formName2+"."+textObj2).value.length;
	setTimeout("showTextNum();",100);	
}

function checkConfirm(toUrl)
{
	isTrue	= confirm("单击“确定”继续。单击“取消”停止。");
	if(isTrue)
	{
		if(toUrl)
		{
			location.href=toUrl;
		}
		return true;
	}else
	{	
	}
}

function user_search_submit(link_str)
{
	if(""==$('v_search_str').value){
			alert('please input the content');
			return false;
		}
	location.href = link_str+'&v_search_str='+$("v_search_str").value;
	return true;
}













