
/*****************************************************************************************************************************/
//reg_status/user_name_ok/agree is defined in the page /User/reg.jsp
function click_agree(){
	agree=0;
	var agree_value=document.getElementById("agree").checked;
	if(agree_value==true || agree_value=="true" || agree_value=="checked"){
		agree=1;
	}
}

function disable_input_and_select(){
	var i=0;
	var list=document.getElementsByTagName("input");
	for(i=0;i<list.length;i++) {
		if(list[i].type=="text" || list[i].type=="radio" || list[i].type=="checkbox" || list[i].type=="password"){
			list[i].disabled=true;
		}
	}
	var list2=document.getElementsByTagName("select");
	for(i=0;i<list2.length;i++) {
		list2[i].disabled=true;
	}
}

function enable_input_and_select(){
	var i=0;
	var list=document.getElementsByTagName("input");
	for(i=0;i<list.length;i++) {
		list[i].disabled=false;
	}
	var list2=document.getElementsByTagName("select");
	for(i=0;i<list2.length;i++) {
		list2[i].disabled=false;
	}
}

function go_next(){
	//edit button
	document.getElementById("go_next_button").style.display="none";
	document.getElementById("submit_button").style.display="";
	document.getElementById("go_back_button").style.display="";
	
	//hide msg
	document.getElementById("reg2_msg1").style.display="";
	var tmp=null;
	for(i=1;i<10;i++){
		tmp=document.getElementById("reg1_msg"+i);
		if(tmp!=null){
			document.getElementById("reg1_msg"+i).style.display="none";
		}
	}
	
	//disable input & select & password
	disable_input_and_select();
	
	//set status, if reg_status=1 then the page can submit;
	reg_status=1;
	
	//clear alerm msg
	clear_msg();
	
	//go top
	go_top();
}

function go_back(){
	//edit button
	document.getElementById("go_next_button").style.display="";
	document.getElementById("submit_button").style.display="none";
	document.getElementById("go_back_button").style.display="none";
	
	//hide msg
	document.getElementById("reg2_msg1").style.display="none";
	var tmp=null;
	for(i=1;i<10;i++){
		tmp=document.getElementById("reg1_msg"+i);
		if(tmp!=null){
			document.getElementById("reg1_msg"+i).style.display="";
		}
	}
	
	//enable input & select
	enable_input_and_select();
	
	//set status, if reg_status=1 then the page can submit;
	reg_status=0;
}

function go_top(){
	//go to top
	//window.location.href="/User/reg.jsp?top#";
	window.location.href="#top";
}


/*****************************************************************************************************************************/
function check_email(strEmail) {
	if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		return true;
	}
	return false;
}

function check_english_name(str){
	if(str.search(/^[A-Za-z0-9 _.,-\|\)\(]+$/)!=-1)
		return true;
	else
		return false;
}


function check_digit_or_letter(str){
	if(str.search(/^[A-Za-z0-9]+$/)!=-1)
		return true;
	else
		return false;
}

function check_letter(str){
	if(str.search(/^[A-Za-z]+$/)!=-1)
		return true;
	else
		return false;
}

function check_digit(str){
	if(str.search(/^[0-9]+$/)!=-1)
		return true;
	else
		return false;
}

function check_str_length(str, min, max){
	if(str!=null && str.length>=min && str.length<=max){
		return true;
	}
	return false;
}

function clear_msg(){
	var msg_max=20;
	var i=0;
	var tmp;
	for(i=0;i<msg_max;i++){
		tmp=document.getElementById("msg_"+i);
		if(tmp!=null){
			document.getElementById("msg_"+i).innerHTML="";
		}
	}
}

function set_msg(id,msg){
	document.getElementById("msg_"+id).innerHTML=msg;
	window.location.href="#point_"+id;
}

function my_alert(msg_index, element_id, msg_id){
	if(msg_id!=null){
		set_msg(msg_id, getOtherLanguage(msg_index));
	}
	if(element_id!=""){
		document.getElementById(element_id).focus();
	}
	//return false;
}

function check_form_reg(){
	//check status
	if(reg_status==0){
		return false;
	}
	enable_input_and_select();
	return true;
}

function check_reg_str(){
	clear_msg();
	
	var str="";
	var temp_str="";
	//check userName
	if(user_name_ok!=1){
		my_alert(1, "userName", 1);
		return;
	}
	str=document.getElementById("userName").value;
	if(str==""){
		my_alert(1, "userName", 1);
		return false;
	}
	if(!check_str_length(str, 4, 20) || !check_digit_or_letter(str)){
		my_alert(0, "userName", 1);
		return false;
	}
	//check password
	str=document.getElementById("password").value;
	if(str==""){
		my_alert(1, "password", 2);
		return false;
	}
	if(!check_str_length(str, 6, 20) || !check_digit_or_letter(str)){
		my_alert(0, "password", 2);
		return false;
	}
	//check confirmPassword
	temp_str=document.getElementById("confirmPassword").value;
	if(temp_str==""){
		my_alert(1, "confirmPassword", 3);
		return false;
	}
	if(temp_str!=str){
		my_alert(2, "confirmPassword", 3);
		return false;
	}
	//check contactorName
	str=document.getElementById("contactorName").value;
	if(str==""){
		my_alert(1, "contactorName", 4);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "contactorName", 4);
		return false;
	}
	//check contactorNameEn
	str=document.getElementById("contactorNameEn").value;
	if(str==""){
		my_alert(1, "contactorNameEn", 5);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_english_name(str)){
		my_alert(0, "contactorNameEn", 5);
		return false;
	}
	//check email
	check_email_ok=0;
	str=document.getElementById("email").value;
	if(str==""){
		my_alert(1, "email", 6);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_email(str)){
		my_alert(0, "email", 6);
		return false;
	}
	check_email_ok=1;
	if(user_email_ok!=1){
		my_alert(13, "email", 6);
		return;
	}
	//check confirmEmail
	temp_str=document.getElementById("confirmEmail").value;
	if(temp_str==""){
		my_alert(1, "confirmEmail", 7);
		return false;
	}
	if(temp_str!=str){
		my_alert(3, "confirmEmail", 7);
		return false;
	}
	//check companyName
	str=document.getElementById("companyName").value;
	if(str==""){
		my_alert(1, "companyName", 8);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyName", 8);
		return false;
	}
	//check companyNameEn
	str=document.getElementById("companyNameEn").value;
	if(str==""){
		my_alert(1, "companyNameEn", 9);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_english_name(str)){
		my_alert(0, "companyNameEn", 9);
		return false;
	}
	//check companyRegion
	str=document.getElementById("companyRegion").value;
	if(str==""){
		my_alert(1, "companyRegion", 10);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyRegion", 10);
		return false;
	}
	//check companyCountry
	str=document.getElementById("companyCountry").value;
	if(str==""){
		my_alert(1, "companyCountry", 10);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyCountry", 10);
		return false;
	}
	//check companyAddress
	str=document.getElementById("companyAddress").value;
	if(str==""){
		my_alert(1, "companyAddress", 10);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyAddress", 10);
		return false;
	}
	//check tel1
	str=document.getElementById("tel1").value;
	if(str==""){
		my_alert(1, "tel1", 11);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_digit(str)){
		my_alert(0, "tel1", 11);
		return false;
	}
	//check tel2
	str=document.getElementById("tel2").value;
	if(str==""){
		my_alert(1, "tel2", 11);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "tel2", 11);
		return false;
	}
	//check tel3
	str=document.getElementById("tel3").value;
	if(str==""){
		my_alert(1, "tel3", 11);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "tel3", 11);
		return false;
	}
	//check tel4
	str=document.getElementById("tel4").value;
	if(str==""){
		my_alert(1, "tel4", 11);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "tel4", 11);
		return false;
	}
	//check fax1
	str=document.getElementById("fax1").value;
	if(str==""){
		my_alert(1, "fax1", 12);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_digit(str)){
		my_alert(0, "fax1", 12);
		return false;
	}
	//check fax2
	str=document.getElementById("fax2").value;
	if(str==""){
		my_alert(1, "fax2", 12);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "fax2", 12);
		return false;
	}
	//check fax3
	str=document.getElementById("fax3").value;
	if(str==""){
		my_alert(1, "fax3", 12);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "fax3", 12);
		return false;
	}
	//check fax4
	str=document.getElementById("fax4").value;
	if(str==""){
		my_alert(1, "fax4", 12);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "fax4", 12);
		return false;
	}
	//check companyUrl
	/*str=document.getElementById("companyUrl").value;
	if(str==""){
		my_alert(1, "companyUrl", 13);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyUrl", 13);
		return false;
	}*/
	//check checkCode
	str=document.getElementById("checkCode").value;
	if(str==""){
		my_alert(1, "checkCode", 17);
		return false;
	}
	if(!check_str_length(str, 4, 4) || !check_digit(str)){
		my_alert(0, "checkCode", 17);
		return false;
	}
	
	if(agree!=1){
		my_alert(1, "agree", 18, false);
		return;
	}
	
	go_next();
}




function check_form_edit(){
	clear_msg();
	var str="";
	var temp_str="";
	//check contactorName
	str=document.getElementById("contactorName").value;
	if(str==""){
		my_alert(1, "contactorName", 2);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "contactorName", 2);
		return false;
	}
	//check contactorNameEn
	str=document.getElementById("contactorNameEn").value;
	if(str==""){
		my_alert(1, "contactorNameEn", 3);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_english_name(str)){
		my_alert(0, "contactorNameEn", 3);
		return false;
	}
	//check email
	check_email_ok=0;
	str=document.getElementById("email").value;
	if(str==""){
		my_alert(1, "email", 4);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_email(str)){
		my_alert(0, "email", 4);
		return false;
	}
	check_email_ok=1;
	if(user_email_ok!=1){
		my_alert(13, "email", 4);
		return;
	}
	//check confirmEmail
	temp_str=document.getElementById("confirmEmail").value;
	if(temp_str==""){
		my_alert(1, "confirmEmail", 5);
		return false;
	}
	if(temp_str!=str){
		my_alert(3, "confirmEmail", 5);
		return false;
	}
	//check companyName
	str=document.getElementById("companyName").value;
	if(str==""){
		my_alert(1, "companyName", 6);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyName", 6);
		return false;
	}
	//check companyNameEn
	str=document.getElementById("companyNameEn").value;
	if(str==""){
		my_alert(1, "companyNameEn", 7);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_english_name(str)){
		my_alert(0, "companyNameEn", 7);
		return false;
	}
	//check companyRegion
	str=document.getElementById("companyRegion").value;
	if(str==""){
		my_alert(1, "companyRegion", 8);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyRegion", 8);
		return false;
	}
	//check companyCountry
	str=document.getElementById("companyCountry").value;
	if(str==""){
		my_alert(1, "userName", 8);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyCountry", 8);
		return false;
	}
	//check companyAddress
	str=document.getElementById("companyAddress").value;
	if(str==""){
		my_alert(1, "companyAddress", 8);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyAddress", 8);
		return false;
	}
	//check tel1
	str=document.getElementById("tel1").value;
	if(str==""){
		my_alert(1, "tel1", 9);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_digit(str)){
		my_alert(0, "tel1", 9);
		return false;
	}
	//check tel2
	str=document.getElementById("tel2").value;
	if(str==""){
		my_alert(1, "tel2", 9);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_digit(str)){
		my_alert(0, "tel2", 9);
		return false;
	}
	//check tel3
	str=document.getElementById("tel3").value;
	if(str==""){
		my_alert(1, "tel3", 9);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "tel3", 9);
		return false;
	}
	//check tel4
	str=document.getElementById("tel4").value;
	if(str==""){
		my_alert(1, "tel4", 9);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "tel4", 9);
		return false;
	}
	//check fax1
	str=document.getElementById("fax1").value;
	if(str==""){
		my_alert(1, "fax1", 10);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_digit(str)){
		my_alert(0, "fax1", 10);
		return false;
	}
	//check fax2
	str=document.getElementById("fax2").value;
	if(str==""){
		my_alert(1, "fax2", 10);
		return false;
	}
	if(!check_str_length(str, 1, 255) || !check_digit(str)){
		my_alert(0, "fax2", 10);
		return false;
	}
	//check fax3
	str=document.getElementById("fax3").value;
	if(str==""){
		my_alert(1, "fax3", 10);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "fax3", 10);
		return false;
	}
	//check fax4
	str=document.getElementById("fax4").value;
	if(str==""){
		my_alert(1, "fax4", 10);
		return false;
	}
	if(!check_str_length(str, 1, 4) || !check_digit(str)){
		my_alert(0, "fax4", 10);
		return false;
	}
	//check companyUrl
	/*str=document.getElementById("companyUrl").value;
	if(str==""){
		my_alert(1, "companyUrl", 11);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyUrl", 11);
		return false;
	}*/
	return true;
}


function check_form_product(){
	clear_msg();
	var str="";
	//check typeName
	str = document.getElementById("productCodeOnly").value;
	if(str==""){
		my_alert(1, "productCodeOnly", 11);
		return false;
	}
	str=document.getElementById("typeName").value;
	if(str==""){
		my_alert(1, "typeName", 2);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "typeName", 2);
		return false;
	}
	//check factory
	str=document.getElementById("factory").value;
	if(str==""){
		my_alert(1, "factory", 3);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "factory", 3);
		return false;
	}
	//check region
	str=document.getElementById("region").value;
	if(str==""){
		my_alert(1, "region", 7);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "region", 7);
		return false;
	}
	//check country
	str=document.getElementById("country").value;
	if(str==""){
		my_alert(1, "country", 7);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "country", 7);
		return false;
	}
	//check title
	str=document.getElementById("title").value;
	if(str==""){
		my_alert(1, "title", 9);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "title", 9);
		return false;
	}
	//check description
	str = document.getElementById("productForm").description.value;
       if(str==""){
			my_alert(1, "description", 10);   
           	return false;   
       }
       	return true;
}
function check_form_edit_product(){
	clear_msg();
	var str="";
	//check typeName
	str = document.getElementById("productCodeOnly").value;
	if(str==""){
		my_alert(1, "productCodeOnly", 11);
		return false;
	}
	str=document.getElementById("typeName").value;
	if(str==""){
		my_alert(1, "typeName", 2);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "typeName", 2);
		return false;
	}
	//check factory
	str=document.getElementById("factory").value;
	if(str==""){
		my_alert(1, "factory", 3);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "factory", 3);
		return false;
	}
	//check region
	str=document.getElementById("region").value;
	if(str==""){
		my_alert(1, "region", 7);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "region", 7);
		return false;
	}
	//check country
	str=document.getElementById("country").value;
	if(str==""){
		my_alert(1, "country", 7);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "country", 7);
		return false;
	}
	//check title
	str=document.getElementById("title").value;
	if(str==""){
		my_alert(1, "title", 9);
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "title", 9);
		return false;
	}
	//check description
	str = document.getElementById("edit_product_form").description.value;
       if(str==""){
			my_alert(1, "description", 10);   
           	return false;   
       }
       	return true;
}

function check_form_password(){
	clear_msg();
	var str="";
	var temp_str="";
	//check password
	str=document.getElementById("password").value;
	if(str==""){
		my_alert(1, "password", 1);
		return false;
	}
	if(!check_str_length(str, 6, 20) || !check_digit_or_letter(str)){
		my_alert(0, "password", 1);
		return false;
	}
	//check newPassword
	str=document.getElementById("newPassword").value;
	if(str==""){
		my_alert(1, "newPassword", 2);
		return false;
	}
	if(!check_str_length(str, 6, 20) || !check_digit_or_letter(str)){
		my_alert(0, "newPassword", 2);
		return false;
	}
	//check confirmNewPassword
	temp_str=document.getElementById("confirmNewPassword").value;
	if(temp_str==""){
		my_alert(1, "confirmNewPassword", 3);
		return false;
	}
	if(temp_str!=str){
		my_alert(2, "confirmNewPassword", 3);
		return false;
	}
	return true;
}


function check_form_msg(){
	var str="";
	//check msg
	var oEditor = FCKeditorAPI.GetInstance("msgContent");   
       var checkContent = oEditor.GetXHTML();   
       if(checkContent == "")   
       {   
           alert(getOtherLanguage(11));
           oEditor.SetHTML(""); 
           oEditor.Focus();   
           return false;   
       }else{
       	return true;
       }
}
function check_form_product_msg(){
	var str="";
		str = document.getElementById("msgContent").value;
		if(str==""){
			 alert(getOtherLanguage(11));
		 document.getElementById("msgContent").focus();
		 return false;
		}
		return true;
}
function check_form_descript_msg(){
	var str="";
	//check descript_msg
	
	email = document.getElementById("email").value;
	tel = document.getElementById("tel").value;
	contactorName = document.getElementById("contactorName").value;
	companyName = document.getElementById("companyName").value;
	checkCode = document.getElementById("checkCode").value;
	str  = document.getElementById("msgContent").value;
	if(str==""){
		 alert(getOtherLanguage(11));
		 document.getElementById("msgContent").focus();
		 return false;
	}
	//check companyRegion
	str=document.getElementById("companyRegion").value;
	if(str==""){
		alert(getLanguage('reg',31)+getOtherLanguage(1));
		document.getElementById("companyRegion").focus();
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyRegion", 10);
		return false;
	}
	//check companyCountry
	str=document.getElementById("companyCountry").value;
	if(str==""){
		alert(getLanguage('reg',31)+getOtherLanguage(1));
			document.getElementById("companyCountry").focus();
		return false;
	}
	if(!check_str_length(str, 1, 255)){
		my_alert(0, "companyCountry", 10);
		return false;
	}

	if(email==""){
		alert(getLanguage('reg',17)+getOtherLanguage(1));
		document.getElementById("email").focus();
		return false;
	}
	if(!check_email(email)){
		alert(getLanguage('reg',17)+getOtherLanguage(0));
		document.getElementById("email").focus();
		return false;
	}
	if(tel==""){
		alert(getLanguage('reg',36)+getOtherLanguage(1));
		document.getElementById("tel").focus();
		return false;
	}
	if(contactorName==""){
		alert(getLanguage('reg',155)+getOtherLanguage(1));
		document.getElementById("contactorName").focus();
		return false;
	}
	if(companyName==""){
		alert(getLanguage('reg',129)+getOtherLanguage(1));
		document.getElementById("companyName").focus();
		return false;
	}
	if(checkCode==""){
		alert(getLanguage('reg',83)+getOtherLanguage(1));
		document.getElementById("checkCode").focus();
		return false;
	}
	if(checkCode.length<4){
	alert(getLanguage('reg',83)+getOtherLanguage(0));
	document.getElementById("checkCode").focus();
	return false;
	}
	return true;
}

function check_file_type(ispic,file_name){
	try{
		if(file_name==""){
			alert(getOtherLanguage(9));
			return false;
		}
		var filetype = file_name.substring(file_name.lastIndexOf("."),file_name.length);
		
		if(ispic==1){
	 		if(filetype.toUpperCase()!=".GIF"&&filetype.toUpperCase()!=".BMP"&&filetype.toUpperCase()!=".PNG"&&filetype.toUpperCase()!=".JPEG"&&filetype.toUpperCase()!=".JPG")
	    	{
	 			alert(getOtherLanguage(8));
	 			return false;
	 		}
	    }else{
	    	if(filetype.toUpperCase()!=".FLV"&&filetype.toUpperCase()!=".MP4")
	    	{
	 			alert(getOtherLanguage(8));
	 			return false;
	 		}
	    }
	    return true;
    }catch(e){
    	alert(getOtherLanguage(8));
    	return false;
    }
}
function check_form_upload(select_id,video_num,image_num,provider)
{
	var select_type=document.getElementById(select_id);
	if(select_type.value=='1'){
		if(video_num>=1){
			alert(getOtherLanguage(5));
			return false;
		}
	}
	else{
		if(provider==1){
			if(image_num>=1){
				alert(getOtherLanguage(6));
				return false;
			}
		}else{
			if(image_num>=15){
				alert(getOtherLanguage(7));
				return false;
			}
		}
	}
	return true;
}
