﻿
   function doLocation(url){
   	window.location =url;
   }
   
   function dosubmit(formName){
       	document.forms[formName].submit();  
   }
   
   function dosubmit(formName,action){
      	document.forms[formName].action=action;
       	document.forms[formName].submit();  
       	window.status="正在搜尋...";
   }
   
   function getKeyword_and_dosubmit(inputId,formName,action){
      var origin_k = document.getElementById(inputId).value;
    	var encoding_k = Url.encode(origin_k);

    	if(encoding_k!=-1){
    		//encoding_k =  encodeURIComponent(encoding_k);
    		document.forms[formName].action = action + "&searchText=" + encoding_k;
      		document.forms[formName].submit();
      		window.status="正在搜尋...";
      	}
   }
   
   function getKeyword_and_dosubmit2(inputId,formName,action){
      var origin_k = document.getElementById(inputId).value;
    	var encoding_k = Url.encode(origin_k);

    	if(encoding_k!=-1){
    		encoding_k =  encodeURIComponent(encoding_k);
    		document.forms[formName].action = action + "&searchText=" + encoding_k;
      		document.forms[formName].submit();
      		window.status="正在搜尋...";
      	}
   }
   
   function urlEncode_and_winOpen(url,width,height){
	   var condition="width="+ width+",height="+height+",left=0,top=100,screenX=0,screenY=100,toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes";
	   window.open(url,'mywindow',condition);
   }
   
   function urlEncode_and_doLocation(url){
	   var tmpArr1=url.split("?");
	   var tmpArr2=tmpArr1[1].split("&");
	   var encodingParam="",encodingUrl="";
	   
	   for(var i=0;i<tmpArr2.length;i++){
	   	var tmpArr3=tmpArr2[i].split("=");
	   	//alert(tmpArr3[1])
	   	var encoding_p = Url.encode(tmpArr3[1]);
	   	//alert(encoding_p)
	   	encodingParam+=tmpArr3[0]+"="+encoding_p+"&";
	   	//alert(encodingParam)
	   }
	   encodingUrl=tmpArr1[0]+"?"+encodingParam;
	   //alert(encodingUrl)
	   window.location =encodingUrl;
   }
   
   function getKeyword_chk_WithinSupplier_and_dosubmit(inputId,formName,productActionUrl,supplierActionUrl,companyChkBoxId){
   	var action=null;
   	if(document.getElementById(companyChkBoxId)!=null){
	   	if(document.getElementById(companyChkBoxId).checked==true){
	   		action=supplierActionUrl;
	   	}
	   	else{
   			action=productActionUrl;
   		}
   	}
   	else{
   		action=productActionUrl;
   	}
   	//alert(document.getElementById(companyChkBoxId).checked==true)
   	//alert(productActionUrl)
		//alert(supplierActionUrl)
		getKeyword_and_dosubmit(inputId,formName,action);
   }
   
   function getKeyword_ifChkValue_and_dosubmit(inputId,formName,ActionUrl1,ActionUrl2,chkboxId){
   	var action=null;
   	if(document.getElementById(chkboxId).checked==true){
   		action=ActionUrl2;
   	}
   	else{
   		action=ActionUrl1;
   	}
   	//alert(document.getElementById(chkboxId).checked==true)
   	//alert(ActionUrl1)
		//alert(ActionUrl2)
		getKeyword_and_dosubmit(inputId,formName,action);
   }
   
   function getKeyword_and_doLocation(inputId,action){
		var origin_k = document.getElementById(inputId).value;
		var encoding_k = Url.encode(origin_k);
		if(encoding_k!=-1){
   		//alert(encoding_k)
   		//alert(action + "&searchText=" + encoding_k);
   	  window.location = action + "&searchText=" + encoding_k;
   	 }
   }
   
   function clear_checked_withinResult(){
   alert(getElementById("product_wtr_chk_id").checked)
   alert(getElementById("biz_wtr_chk_id").checked)
   alert(getElementById("news_wtr_chk_id").checked)
   alert(getElementById("tradeEvents_wtr_chk_id").checked)
   alert(getElementById("companyName_wtr_chk_id").checked)
   
   	getElementById("product_wtr_chk_id").checked=false;
   	getElementById("biz_wtr_chk_id").checked=false;
   	getElementById("news_wtr_chk_id").checked=false;
   	getElementById("tradeEvents_wtr_chk_id").checked=false;
   	getElementById("companyName_wtr_chk_id").checked=false;
   }
   
	function windowOpen(action,width,height){
		var condition="width="+ width+",height="+height+",left=0,top=100,screenX=0,screenY=100,toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes";
		window.open(action,'mywindow',condition);
	}

	function productAdvPageMapper(formName,actionName){
	      document.forms[formName].action=actionName;
       	document.forms[formName].submit();  
	}
	
	function pageMapper(member_type,web_open,DOMAIN_NAME,DOMAIN_NAME_FLAG,NEXT_PAGE){
		if((member_type=="8")&&(web_open=="1"))
		{
			var open_action="http://";
			var website_name=".taiwantrade.com.tw";
			if(DOMAIN_NAME_FLAG=="1"){
			
				open_action=open_action+DOMAIN_NAME+website_name;
			}
			else if(DOMAIN_NAME_FLAG=="0")
			{
				open_action=open_action+"www"+website_name+"/"+DOMAIN_NAME;
			}
			window.open(open_action,'mywindow','width=850,height=650,left=0,top=100,screenX=0,screenY=100,toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');
		}
		else
		{
			window.location=NEXT_PAGE;
		}
	}
	
		function isOpenNewPage(member_type,web_open,DOMAIN_NAME,DOMAIN_NAME_FLAG){
		
			var open_action="http://";
			var website_name=".taiwantrade.com.tw";
			if(DOMAIN_NAME_FLAG=="1"){
			
				open_action=open_action+DOMAIN_NAME+website_name;
			}
			else if(DOMAIN_NAME_FLAG=="0")
			{
				open_action=open_action+"www"+website_name+"/"+DOMAIN_NAME;
			}
			window.open(open_action,'mywindow','width=850,height=650,left=0,top=100,screenX=0,screenY=100,toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');
			window.history.back();

	}
	
	function openNewComPage(action){
		var open_action=action;
		//window.open(open_action,'mywindow','width=850,height=650,left=0,top=100,screenX=0,screenY=100,toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');
		//window.history.back();
		location.href = action;
	}
	
	function home_searchBar_display(searchName,searchserv_actionUrl,from_index){
		var product_div=document.getElementById("product_Bar");
		var bizExchange_div=document.getElementById("bizExchange_Bar"); 
		var news_div=document.getElementById("news_Bar"); 
		var tradeEvents_div=document.getElementById("tradeEvents_Bar"); 
		var companyName_div=document.getElementById("companyName_Bar"); 
		
		product_div.style.display = "none";
		bizExchange_div.style.display = "none";
		news_div.style.display = "none";
		tradeEvents_div.style.display = "none";
		companyName_div.style.display = "none";
		document.getElementById(searchName).style.display = "block";
		if(from_index!="1"){
			window.location=searchserv_actionUrl;
		}
	}
	
	function bringValue2AnotherSelect(formName,optionValue,nextUrl){
  	document.forms[formName].action=nextUrl+"&biz_continent="+optionValue.value;
   	document.forms[formName].submit();  
	}
	
	function onEnter(elementID){
		if(event.keyCode==13){
			document.getElementById(elementID).onclick();
		}
	}
	
	function onEnter(elementID,e){
		var keynum
		if(window.event) // IE
		{
		keynum = e.keyCode
		}
		else if(e.which) // Netscape/Firefox/Opera
		{
		keynum = e.which
		}
		if(keynum==13){
			document.getElementById(elementID).onclick();
		}
	}
	
	function download_lock(msg){
	window.event.returnValue=false; //將滑鼠右鍵事件取消
	alert(msg);
}

	function eliminateTag(str){
		str = str.replace(/<.*?>/," ");
		str = str.replace(/<\/.*?>/," ");
		str = str.replace(/&lt;.*?&gt;/," ");
		str = str.replace(/&lt;\/.*?&gt;/," ");
		return str;
	}

var Url = {

    // public method for url encoding
    encode : function (string) {
    	string = eliminateTag(string);
    	var regExp=/[*]/g
			var tmp_rKeyword = escape(this._utf8_encode(string));
			var rNum = tmp_rKeyword.search(regExp);
			//document.write(rNum)
			if(rNum!=-1){
				document.getElementById("keyword_err_id").style.display = "block";
				return -1;
			}
			else{
				document.getElementById("keyword_err_id").style.display = "none";
				return tmp_rKeyword;
			}
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}
	
function ch_isCheckItems(checkGood,formName,action,isLogin,notLoginAction){
	
	if(checkGood == "true"){
		if(isLogin != "true"){
			if(confirm("Are You A Member of Taiwantrade ? \n Click Ok for Yes \n Click Cancel for No")){
				document.getElementById('j_username').focus();
				document.getElementById("biz_check").value="2";
				document.getElementById("redirect").innerHTML="<input type='hidden' id='gf_redirect_path' name='gf_redirect_path' value='ch_biz/page_Map.jsp?biz_check=2'>";
			}else{
				document.forms[formName].action = action;
				document.forms[formName].submit();
			}
		}else{
			document.forms[formName].action = action;
			document.forms[formName].submit();
		}
	}else{
		alert("Please select at least one product !");
	}

}
function ch_checkLogin(formName,action,isLogin){

    shoppingcart_list.checkItems("sti-shoppingcart-list-",formName,action,isLogin,"", false,isReturnCheck);

}

function isReturnCheck(str){
  	if(str != null){
  		replaceStr = str.split("|");
    	ch_isCheckItems(replaceStr[0],replaceStr[1],replaceStr[2],replaceStr[3],replaceStr[4]);
    }
}


