function newopen(openkey){
	window.open("/common/com_categorySelect.jsp?openkey="+openkey,"","height=400,width=685,left=190,top=0,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
function addtags(t,v){
	document.all.tags.options.add(new Option(t,v));
}
function removetags(){
document.all.tags.options.length=0;
}

var checkOk = new Array();
checkOk[0] = "12288";
checkOk[1] = "8364";
function check(object,input_value){
	if (!(checkchi(input_value)))
	{
		window.alert("Sorry, the information you filled is not in English. Please input in English instead.");
		object.value='';
		//object.focus();
	}
}
function isOkChar(ch){
	for (j = 0;  j < checkOk.length;  j++)
      	if (ch == checkOk[j])
      	{
        	return true;
        }
    return false;
	
}
function checkchi(myint) {
  
  		var checkStr = myint;
  		var allValid = true;
  		for (i = 0;  i < checkStr.length;  i++)
  		{
    		
			ch = checkStr.charCodeAt(i);
     		if (ch > 256 && !isOkChar(ch))
    		{      
      			allValid = false;
     		    break;
    		}
			
  		}
	    if (!allValid){
	    	return (false);
	    }
	  		return (true);
}

function addtags(t,v){
	$_("tags").options.add(new Option(t,v))
}
function removetags(){
$_("tags").options.length=0;
}


 function ckpost(f){
	 	__ff_sampleKey(f);
		var ok=Validator.Validate(f,3);
		if(!ckmid()){
			$("#MemberID").focus();
			return false;
		}
		if(!ckpassword()){
			$("#Password").focus();
			return false;
		}
		if(!ckcompanyname()){
			$("#CompanyName").focus();
			return false;
		}
		return ok;
}


function ckpassword(){
		if($("#Password").val().length<6){
			$("#td_password").html("<font color=red>( ( 6-20 characters (A-Z, a-z, 0-9, no spaces.) ) </font>");
			return false;
		}else{
			$("#td_password").html("<font color=green>Ok</font>");
			return true;
		}	
	}
	
	function ckcompanyname(){
		var isok=true;
		if(!checkchi($("#CompanyName").val())){
			$("#td_companyname").html("<font color=red>Sorry,please input in Einglish instead.</font>");
			$("#td_companyname").attr("class","f_n_e");			
			return false;
		}
		if($("#CompanyName").val().length<10){
			$("#td_companyname").html("<font color=red> Please specify your Company Name. </font>");
			$("#td_companyname").attr("class","f_n_e");
			//$("#CompanyName").focus();
			return false;
		}else{
			$.get("/sysstate.do?actiontype=ckexist&tag=CompanyName&value="+$("#CompanyName").val(),function(ok){
					if(ok>0){
						//$("#CompanyName").focus();
						$("#td_companyname").html("<font color=red>This Company Name  has been created by others.  </font>");
					$("#td_companyname").attr("class","f_n_e");
					isok=false;
					}
				})
		}
		if(isok){
			$("#td_companyname").html("<font color=green>Ok</font>");
			$("#td_companyname").attr("class","f_n_o");
		}
		return isok;
	}
			
function chkDomain(str)
{
    if (str.length==0||str.charAt(0)=="-"||str.charAt(str.length-1)=="-") { return 0; }
    if (str.charAt(0)=="."||str.charAt(str.length-1)==".") { return 0; }
    strSource="-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    var ch;
    var i;
    var temp;    
    for (i=0;i<=(str.length-1);i++)
    {
        ch = str.charAt(i);
        temp = strSource.indexOf(ch);
        if (temp==-1) {return 0;}
    }
    return 1;
}

function ckmid(){
		var isok=true;
		if(!checkchi($("#MemberID").val())){
			$("#td_memberid").html("<font color=red>Sorry,please input in Einglish instead.</font>");
			$("#td_memberid").attr("class","f_n_e");			
			return false;
		}
		if($("#MemberID").val().length<4||chkDomain($("#MemberID").val().Trim())==0){
			//$("#MemberID").focus();
			$("#td_memberid").html("<font color=red>( 4-20 characters (A-Z, a-z, 0-9, hyphen ( '-' ), no spaces) </font>");
			$("#td_memberid").attr("class","f_n_e");																			  
			return false;
		}else{
			$.get("/sysstate.do?actiontype=ckexist&tag=MemberID&value="+$("#MemberID").val(),function(ok){
					if(ok>0){
						//$("#MemberID").focus();
						$("#td_memberid").html("<font color=red>This Member ID has been chosen by others. Please choose another. </font>");
						$("#td_memberid").attr("class","f_n_e");
						isok=false;
					}
				})
		}
		if(isok){
			$("#td_memberid").html("<font color=green>Ok</font>");
			$("#td_memberid").attr("class","f_n_o");
		}
		return isok;
}



function ckemail(){
			var isok=true;
			if(!checkchi($("#Email").val())){
				$("#div_email").html("<font color=red>Sorry,please input in Einglish instead.</font>");
				$("#div_email").attr("class","f_n_e");			
				return false;
			}
			
			if($("#Email").val().length<1){
				$("#div_email").html("<font color=red>Please specify your Current Email.</font>");
				$("#div_email").attr("class","f_n_e");
				return false;
			}else if(!isEmail($("#Email").val())){
				$("#div_email").html("<font color=red>Please specify a valid email address. </font>");
				$("#div_email").attr("class","f_n_e");	
				return false;
			}else{
				$.get("/sysstate.do?actiontype=ckexist&tag=email&value="+$("#Email").val(),function(ok){
					if(ok>0){
						$("#div_email").html("<font color=red>That email address has been chosen by others. Please choose another email address.</font>");
						$("#div_email").attr("class","f_n_e");
						isok=false;
					}
				})
			}
			if(isok){
				$("#div_email").html("<font color=green>Ok</font>");
				$("#div_email").attr("class","f_n_o");	
			}
			return isok;
	}

	function ckquestion(){
			if(!checkchi($("#Question").val())){
				$("#td_q").html("<font color=red>Sorry,please input in Einglish instead.</font>");
				$("#td_q").attr("class","f_n_e");
				return false;
			}						 
			if($("#Question").val().length<1){
				$("#td_q").html("<font color=red>Please specify a Question Question.</font>");
				$("#td_q").attr("class","f_n_e");
				return false;
			}else{
				$("#td_q").html("<font color=green>Ok</font>");
				$("#td_q").attr("class","f_n_o");
				return true;
			}
	}
	
	function ckanswer(){
		if(!checkchi($("#Answer").val())){
				$("#td_a").html("<font color=red>Sorry,please input in Einglish instead.</font>");
				$("#td_a").attr("class","f_n_e");
				return false;
			}
		if($("#Answer").val().length<1){
				$("#td_a").html("<font color=red>Please specify an Anwser to Password Question.</font>");
				$("#td_a").attr("class","f_n_e");
				return false;
			}else{
				$("#td_a").html("<font color=green>Ok</font>");
				$("#td_a").attr("class","f_n_o");
				return true;
			}
	}
	
	function ckproduct(){
		if(!checkchi($("#product").val())){
			$("#div_product").html("<font color=red>Sorry,please input in Einglish instead.</font>");
			$("#div_product").attr("class","f_n_e");
			return false;
		}
		if($("#product").val().length<3){
			$("#div_product").html("Please specify product.")	
			$("#div_product").attr("class","f_n_e");
			return false;
		}else if($("#product").val().length>198){
			$("#div_product").html("Please confirm the product less than 200 characters. ")	
			$("#div_product").attr("class","f_n_e");
			return false;
		}else{
			$("#div_product").html("<font color=green>Ok</font>");
			$("#div_product").attr("class","f_n_o");
			return true;
		}	
	}

	function ckaddress(){
		if(!checkchi($("#Address").val())){
				$("#div_address").html("<font color=red>Sorry,please input in Einglish instead.</font>");
				$("#div_address").attr("class","f_n_e");
				return false;
		}
		if($("#Address").val().length<1){
				$("#div_address").html("<font color=red>Please specify your Company Address.</font>");
				$("#div_address").attr("class","f_n_e");
			}else{
				$("#div_address").html("<font color=green>Ok</font>");
				$("#div_address").attr("class","f_n_o");
		}	
	}

	function ckisCn(objid,msgid,show){
		if(!checkchi($("#"+objid).val())){
				$("#"+msgid).html("<font color=red>Sorry,please input in Einglish instead.</font>");
				$("#"+msgid).attr("class","f_n_e");
				return false;
		}
		if(show){
			$("#"+msgid).html("<font color=green>Ok</font>");
			$("#"+msgid).attr("class","f_n_o");
		}
		return true;
	}


	$(function(){
		$("#MemberID").focus(function(){
			//$("#td_memberid").html("");
			$("#td_memberid").attr("class","f_n_j");
		});
		$("#MemberID").blur(function(){
			ckmid();
		});
		$("#Password").focus(function(){
			//$("#td_password").html("");
			$("#repassword").html("");	
			$("#td_password").attr("class","f_n_j");
		});
		$("#Password").blur(function(){
			if($("#Password").val().length<6){
				$("#td_password").html("<font color=red>( 6-20 characters (A-Z, a-z, 0-9, no spaces. ) </font>");
				$("#td_password").attr("class","f_n_e");														   
			}else{
				$("#td_password").html("<font color=green>Ok</font>");
				$("#td_password").attr("class","f_n_o");
			}
		});
		$("#CompanyName").focus(function(){
			//$("#td_companyname").html("");
			$("#td_companyname").attr("class","f_n_j");
		})
		$("#CompanyName").blur(function(){
			ckcompanyname();
		})
		$("#RePassword").blur(function(){
			$("#repassword").attr("class","f_n_j");
		});
		$("#RePassword").blur(function(){
			if($("#RePassword").val()!=$("#Password").val()||$("#RePassword").val().length<1){
				$("#repassword").html("<font color=red>Your password entries did not match. Please confirm your Password.</font>");	
				$("#repassword").attr("class","f_n_e");
			}else{
				$("#repassword").html("<font color=green>Ok</font>");
				$("#repassword").attr("class","f_n_o");
			}							   
		})
		$("#Question").focus(function(){
			$("#td_q").attr("class","f_n_j");
		})
		$("#Question").blur(function(){
				ckquestion();
		})
		$("#Answer").focus(function(){
			$("#td_a").attr("class","f_n_j");
		})
		$("#Answer").blur(function(){
			ckanswer();
		})
		
		$("#product").focus(function(){
			$("#div_product").attr("class","f_n_j");
		});
		
		$("#product").blur(function(){
			ckproduct();
		});
		
		$("#Address").focus(function(){
			$("#div_address").attr("class","f_n_j");
		});
		
		$("#Address").blur(function(){
			ckaddress();
		})
		
		$("#FullName").blur(function(){
			if($("#FullName").val().length<1){
				$("#div_fname").html("<font color=red>Please specify your Full Name.</font>");
				$("#div_fname").attr("class","f_n_e");
			}else{
				$("#div_fname").html("<font color=green>Ok</font>");
				$("#div_fname").attr("class","f_n_o");
			}
		})
		
/*		$("#yz").focus(function(){
				$("#div_yz").attr("class","f_n_j");			   
		});
		
		$("#yz").blur(function(){
			if($("#yz").val().length!=5){
				$("#div_yz").html("<font color=red>Please type the verification code you see in the picture above. </font>");
				$("#div_yz").attr("class","f_n_e");
			}else{
				$("#div_yz").html("<font color=green>Ok</font>");
				$("#div_yz").attr("class","f_n_o");
			}
		})
*/		
		$("#Email").focus(function(){
				$("#div_email").attr("class","f_n_j");				   
		});
		
		$("#FullName").focus(function(){
				$("#div_fname").attr("class","f_n_j");				   
		});
		$("#Email").blur(function(){
			ckemail();
		})
		
		
		
 })

 function switchshow(country){
			if(country=="China"){
				$("#select_province").show();
				$("#input_province").hide();
				document.catform.input_com_province.value = "";
			}else{
				$("#select_province").hide();
				$("#input_province").show();
				document.catform.select_com_province.value = "";
			}
}
 function switchshow(country,t){
			if(country=="China"){
				$("#select_province").show();
				$("#input_province").hide();
				document.catform.input_com_province.value = "";
			}else{
				$("#select_province").hide();
				$("#input_province").show();
				document.catform.select_com_province.value = "";
			}
			$("#TelephoneNo1").val(t);
			
}	

var first_nmchk = "Y";
var first_subchk = "Y";
function chk_case(f_name){
	var str = "";
	var matchstr = "";
	var chk_value = "N";
	var modified1 = "N";
	var b_str = eval("document.catform."+f_name+".value");
	var abbr = ["MP3","LCD","USB","DVD","TV","ATV","LED","PC","CD","PVC","TFT","FM","HDD","GSM","DVR","DC","CCTV","HP","PP","3D","EVA","CDMA","CCD","PU","RC","CRT","VCD","PE","RF","ID","AC","TFT-LCD","PDA","BBQ","VGA","UV","PDP","PCB","PET","MP4","GPS","UPS","OEM","AB","CNC","PTFE","CPU","IC","LV","EEC","IR","SIM","IQF","TL","NZ","IP","EL","OLED","SD","SMD","MF","TN","PCI","ADSL","RO","CD-R","PCMCIA","LG","PS","MOP","HDPE","LPG","LAN","CE","CMOS","ATX","MPEG4","PVA","VAIO","HMS","NYA","AV","HD","ATI","IBM","PTC","PIN","PS2","ECG","AAA","4WD","PCS","DDR","PA","RCA","ABS","AA","DIY","LDPE","MMC","UFO","IPOD","MDF","CDR","MTB","DIVX","HDTV"];
	var prep = ["of","for","and","or","with","in","the","by"];
	var reg = new RegExp("")

	if(first_nmchk == "Y"){
		// first_nmchk = "N";
		keyValue = eval("document.catform."+f_name+".value");
		if(keyValue.search(/[A-Z]/)!=-1 && keyValue.search(/[a-z]/)==-1 ) {
			modified1 = "Y";
			keyValue = keyValue.toLowerCase();
		}
		if(keyValue.search(/\b[a-z]+[A-Z]/)!=-1) {
			keyValue = keyValue.toLowerCase();
		}
		for(i=0;keyValue.length > i;i++){
			if(i ==0)
				str = keyValue.charAt(i).toUpperCase();
			else if(keyValue.charAt(i) == "{"
				||keyValue.charAt(i) == "}"
				||keyValue.charAt(i) == "("
				||keyValue.charAt(i) == ")"
				||keyValue.charAt(i) == "<"
				||keyValue.charAt(i) == ">"
				||keyValue.charAt(i) == " "
				||keyValue.charAt(i) == "."
				||keyValue.charAt(i) == ","
				||keyValue.charAt(i) == ":"
				||keyValue.charAt(i) == ";"
				||keyValue.charAt(i) == "!"
				||keyValue.charAt(i) == "&"
				||keyValue.charAt(i) == "/"){
				chk_value = "Y";
				str = str + keyValue.charAt(i);
			}else if(chk_value == "Y"){
				str = str + keyValue.charAt(i).toUpperCase();
				chk_value = "N"
			}else
				str = str + keyValue.charAt(i);
		}
		for(i=0;abbr.length > i;i++){
			reg.compile("\\b"+abbr[i]+"\\b","gi");
			str = str.replace(reg, abbr[i]);
		}
		for(i=0;prep.length > i;i++){
			reg.compile(" "+prep[i]+"\\b","gi");
			str = str.replace(reg, " "+prep[i]);
		}
		reg.compile("\\b[a-zA-Z]+[0-9-]*[0-9]+\\b","gi");
		i=0;
		while((pos = str.substring(i,str.length).search(reg))!=-1){
			matchstr = str.substring(i,str.length).match(reg);
			if (pos > -1){
				pos = pos+i;
				str = str.substring(0,pos)+str.substring(pos,pos+matchstr[0].length).toUpperCase()+str.substring(pos+matchstr[0].length,str.length);
			}
			i = pos + matchstr[0].length;
		}
		con_nm = eval("document.catform."+f_name);
		con_nm.value = str;
	}
	//if(str != keyValue){
		//if(modified1 == "Y")
		//	alert("Please do not capitalize all letters.\nOnly initial letter has been left capitalized.\nYou can make adjustment if needed.");
	//	else
		//	alert("Initial letter of each word has been capitalized.\nYou can make adjustment if needed.");
	//}//
}
