// JavaScript Document
function chkform_order(){
	var caution;
	var a=b=c=d=e=f=g=0;
	var j=k=m=n=0;
	
	var testNum=/^[0-9]*\s*[0-9]*\/?[0-9]*(\"?|\''?|in|inch|IN|Inch|INCH|In|mm|MM|Mm|mM)$/;        //正则表达式，判断是否为分数
	if (document.myform.DesignWidth.value!=""){
		if (!testNum.exec(document.myform.DesignWidth.value) && isNaN(document.myform.DesignWidth.value)){
			//if(isNaN(document.form.Design_Width.value)){
			//alert("Design Width accept number only,please check.");
			//document.myform.DesignWidth.focus();
			j=1;
			//return false;
		}
		//}
	}
	if (document.myform.DesignHeight.value!=""){
		if(!testNum.test(document.myform.DesignHeight.value) && isNaN(document.myform.DesignHeight.value)){
			//alert("Design Height accept number only,please check.");
			//document.myform.DesignHeight.focus();
			k=1;
			//return false;
		}
	}


	//验证邮箱
	if (document.myform.email.value!=""){
		var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
		if (!rule.exec(document.myform.email.value)){
			m=1;
		}
	}

	//验证电话
	if(document.myform.Tel.value!=""){
		var strTel=document.myform.Tel.value;
		var strUnit;
		var x=strTel.length;
		var i;
		for(i=0;i<x;i++){
			strUnit=strTel.substring(i,i+1);
			if(isNaN(strUnit) && strUnit!="-" && strUnit!="(" && strUnit!=")" && strUnit!="_" && strUnit!="+"){
				n=1;
				break;
			}
		}
	}

	if (j==1||k==1||m==1||n==1){
		var msg;
		msg="Please check the field below:";
		if(m==1){
			msg=msg+"\nIncorrect email address, please check it."
		}
		if(n==1){
			msg=msg+"\nIncorrect Telphone number, please check it."
		}
		if(j==1){
			msg=msg+"\nDesign Width accept number only,please check."
		}
		if(k==1){
			msg=msg+"\nDesign Height accept number only,please check."
		}
		window.alert(msg);
		if(m==1){
			document.myform.email.focus();
		}else if(j==1){
			document.myform.DesignWidth.focus();
		}else if(k==1){
			document.myform.DesignHeight.focus();
		}
		return false;
	}
	caution="Please fill the field below:";
	if (document.myform.CustomerName.value==""){
		a=1;
		caution=caution+"\n- Customer Name";
	}
	if (document.myform.CompanyName.value==""){
		b=1;
		caution=caution+"\n- Company Name";
	}
	if (document.myform.email.value==""){
		c=1;
		caution=caution+"\n- Email";
	}
	if (document.myform.Tel.value==""){
		d=1;
		caution=caution+"\n- Telephone";
	}
	if (document.myform.DesignWidth.value=="" && document.myform.DesignHeight.value==""){
		e=1;
		caution=caution+"\n- Design Width or Design Height";
	}


	if (caution!="Please fill the field below:"){
		alert(caution);
		if(a==1){
			document.myform.CustomerName.focus();
		}else if(b==1){
			document.myform.CompanyName.focus();
		}else if(c==1){
			document.myform.email.focus();
		}else if(d==1){
			document.myform.Tel.focus();
		}else if(e==1){
			document.myform.DesignWidth.focus();
		}
		return false;
	}

	if(document.myform.image.value==""){
		if(document.myform.image_request.value==""){
			if(!confirm("There is no Attachment here, are you sure?")){
				return false;
			}
		}
	}
}//表单验证完毕



//增加上传文件的控件
var i=1;
function add_att(){
//检查浏览器的类型，不同的浏览器设置不同的lineHeight
	if (navigator.userAgent.indexOf("Firefox")>0){
		document.getElementById("att_text").style.lineHeight="21px";
	}

	var att_div=document.getElementById("att");//获取file所在的层，也就是file的父层
	var img=document.createElement("input");//新建一个file，以下为设置file的各种属性
	img.type="file";
	img.name="image";
	img.id="img"+i;
	att_div.appendChild(img);//添加这个file到所在的层里
	
	
	add_att_text(i);
	i++;
}

function add_att_text(num){
	var att_text=document.getElementById("att_text").innerHTML;
	att_text+="<br><a href='javascript:del_att("+num+");' id='text"+num+"'>Remove</a>";
	document.getElementById("att_text").innerHTML=att_text;
}

function del_att(I){
	var att_div=document.getElementById("att");
	var a=document.getElementById("img"+I);
	att_div.removeChild(a);
	var strHtml=document.getElementById("att_text").innerHTML;
	strHtml=strHtml.toLowerCase();
	var i=strHtml.indexOf("text"+I);
	var strHtmlB=strHtml.substring(0,i);
	strHtmlB=strHtmlB.substring(0,strHtmlB.lastIndexOf("<br"));
	//alert(strHtmlB);
	//alert(strHtml);
	var len=strHtml.length;
	var strHtmlA=strHtml.substring(i+1,len);
	//alert(strHtmlA);

	if(strHtmlA.indexOf("<br")>0){
		strHtmlA=strHtmlA.substring(strHtmlA.indexOf("<br"),strHtmlA.length);
	}
	else if(strHtmlA.indexOf("<br")<=0){
		strHtmlA="";
	}
	//alert(strHtmlA);
	strHtml=strHtmlB+strHtmlA;
	//alert(strHtml);
	strHtml=strHtml.replace(/remove/g,"Remove");
	strHtml=strHtml.replace(/add attachment/g,"Add Attachment");
	//strHtml=strHtml.replace(/style24/g,"STYLE24");
	//alert(strHtml);
	document.getElementById("att_text").innerHTML=strHtml;
}


// JavaScript Document
function chk_reg(){
	var a=b=c=d=e=f=g=h=i=0;
	var msg="Please fill the follwing fields."
	if(document.form.email.value==""){
		a=1;
		msg+="\n - Email Address";
	}
	if(document.form.psw.value==""){
		b=1;
		msg+="\n - Password";
	}
	if(document.form.cname.value==""){
		c=1;
		msg+="\n - Company Name";
	}
	if(document.form.address.value==""){
		d=1;
		msg+="\n - Address";
	}
	if(document.form.contact.value==""){
		e=1;
		msg+="\n - Contact";
	}
	if(document.form.state.value==""){
		f=1;
		msg+="\n - State";
	}
	if(document.form.tel.value==""){
		g=1;
		msg+="\n - Telephone";
	}
	if(document.form.city.value==""){
		h=1;
		msg+="\n - City";
	}
	if(document.form.zip.value==""){
		i=1;
		msg+="\n - Zip Code";
	}
		
	if(msg!="Please fill the follwing fields."){
		alert(msg);
		if(a==1){
			document.form.email.focus();
		}else if(b==1){
			document.form.psw.focus();
		}else if(c==1){
			document.form.cname.focus();
		}else if(d==1){
			document.form.address.focus();
		}else if(e==1){
			document.form.contact.focus();
		}else if(f==1){
			document.form.state.focus();
		}else if(g==1){
			document.form.tel.focus();
		}else if(h==1){
			document.form.city.focus();
		}else if(i==1){
			document.form.zip.focus();
		}
	return false;
	}
		
	//check the email
	if(document.form.email.value!=""){
		var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-\.]*)$/i;
		if (!rule.exec(document.form.email.value)){
			alert("Incorrect email address, please check it.");
			document.form.email.focus();
			return false;
		}
	}
		
	//check the telphone
	if(document.form.tel.value!=""){
		var strTel=document.form.tel.value;
		var strUnit;
		var x=strTel.length;
		var i;
		for(i=0;i<x;i++){
			strUnit=strTel.substring(i,i+1);
			if(isNaN(strUnit) && strUnit!="-" && strUnit!="(" && strUnit!=")" && strUnit!="_" && strUnit!="+"){
				alert("Incorrect telephone number, please check it.");
				document.form.tel.focus();
				return false;
			}
		}
	}
}
	
	
function chkpsw(){
	var psw=document.form.psw.value;
	var psw_re=document.form.psw_re.value;
	
	if(psw!=psw_re){
		alert("Password is diffrent.");
		document.form.psw.select();
		return false;
	}
}
	
function getpsw(){
	var stremail=document.form.email.value;
	stremail=stremail.replace(/\s/g,"");
	if (stremail==""){
		alert("Email can't be blank.");
		document.form.email.focus();
		return false;
	}
}
	
function chk_reg2(){
	var a=b=c=0;
	var msg="Please fill the follwing fields."

	if(document.form.email.value==""){
		b=1;
		msg+="\n - Email";
	}
	if(document.form.psw.value==""){
		c=1;
		msg+="\n - Password";
	}
	if(document.form.name.value==""){
		a=1;
		msg+="\n - Name Address";
	}
		
	if(msg!="Please fill the follwing fields."){
		alert(msg);
		if(b==1){
			document.form.email.focus();
		}else if(c==1){
			document.form.psw.focus();
		}else if(a==1){
			document.form.name.focus();
		}
	return false;
	}
		
	//check the email
	if(document.form.email.value!=""){
		var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
		if (!rule.exec(document.form.email.value)){
			alert("Incorrect email address, please check it.");
			document.form.email.focus();
			return false;
		}
	}
		
}

function chk(){
	if (document.form.email.value==""){
		alert("Email can not be blank.");
		document.form.email.focus();
		return false;
	}
}


function chk_order_member(){
	var caution;
	var e=f=g=0;
	var j=k=0;

	var testNum=/^[0-9]*\s*[0-9]*\/?[0-9]*(\"?|\''?|in|inch|IN|Inch|INCH|In|mm|MM|Mm|mM)$/;        //正则表达式，判断是否为分数
	if (document.myform.DesignWidth.value!=""){
		if (!testNum.exec(document.myform.DesignWidth.value) && isNaN(document.myform.DesignWidth.value)){
			j=1;
		}
	}
	if (document.myform.DesignHeight.value!=""){
		if(!testNum.test(document.myform.DesignHeight.value) && isNaN(document.myform.DesignHeight.value)){
			k=1;
		}
	}

	if (j==1||k==1){
		var msg;
		msg="Please check the field below:";
		if(j==1){
			msg=msg+"\nDesign Width accept number only,please check."
		}
		if(k==1){
			msg=msg+"\nDesign Height accept number only,please check."
		}
		window.alert(msg);
		if(j==1){
			document.myform.DesignWidth.focus();
		}else if(k==1){
			document.myform.DesignHeight.focus();
		}
		return false;
	}
	caution="Please fill the field below:";
	if(document.myform.design_name.value==""){
		f=1;
		caution=caution+"\n- Design Name";
	}

	if (document.myform.DesignWidth.value=="" && document.myform.DesignHeight.value==""){
		e=1;
		caution=caution+"\n- Design Width or Design Height";
	}


	if (caution!="Please fill the field below:"){
		alert(caution);
		if(f==1){
			document.myform.design_name.focus();
		}
		else if(e==1){
			document.myform.DesignWidth.focus();
		}
		return false;
	}
	if(document.myform.image.value==""){
		if(document.myform.image_request.value=="" && document.myform.image_request.value=="" && document.myform.image_quote.value==""){
			if(!confirm("There is no Attachment here, are you sure?")){
				return false;
			}
		}
	}
}


function chkdate(strDate){
	var strDate1=strDate.replace(/\s/g,"");
	var i=strDate1.indexOf("/");
	var dateA,dateB

	if(parseInt(strDate1.substring(0,i))==0){
		dateA=parseInt(strDate1.substring(1,i));
	}
	else{
		dateA=parseInt(strDate1.substring(0,i));
	}
	
	if(parseInt(strDate1.substring(i+1,strDate1.length))==0){
		dateB=parseInt(strDate1.substring(i+2,strDate1.length));
	}
	else{
		dateB=parseInt(strDate1.substring(i+1,strDate1.length));
	}
	
	if(dateA>0 && dateA<=12){
		if(dateB>=0 && dateB<=99){
			return true;
		}
		else{
			return false;
		}
	}
	else{
		return false;
	}
}

function chkupdate(){
	var Caution;
	var a1=a2=a3=a4=a5=a6=a7=a8=a9=a10=a11=a12=a13=0;
	Caution="Please complete the following fields:";

	if (document.form.customer_name.value==""){
		Caution=Caution+"\n"+"- Name";
		a1=1;
	}
	if(document.form.company_name.value==""){
		Caution=Caution+"\n"+"- Company Name";
		a3=1;
	}
	if(document.form.telephone.value==""){
		Caution=Caution+"\n"+"- Telephone";
		a4=1;
	}

	if (Caution!="Please complete the following fields:"){
		alert(Caution);
		if (a1==1){
			document.form.customer_name.focus();
		}
		else if(a3==1){
			document.form.company_name.focus();
		}
		else if(a4==1){
			document.form.telephone.focus();
		}
		return false;
	}

	//验证电话
	if(document.form.telephone.value!=""){
		var strTel=document.form.telephone.value;
		var strUnit;
		var x=strTel.length;
		var i;
		var n;
		for(i=0;i<x;i++){
			strUnit=strTel.substring(i,i+1);
			if(isNaN(strUnit) && strUnit!="-" && strUnit!="(" && strUnit!=")" && strUnit!="_" && strUnit!="+"){
				alert("Phone is incorrect, please check.");
				document.form.telephone.focus();
				return false;
				break;
			}
		}
	}
}

function showH(){
	if(document.getElementById("MsgHistory").style.display=="block"){
		document.getElementById("MsgHistory").style.display="none";
	}
	else{
		document.getElementById("MsgHistory").style.display="block";
	}
}
	
function formatNum(){
	var target;
	var TA;
	var TAC;
	var TF;
	var TFC;
	var intA;
	var intB;
	var intC;
	var I;
	
	target=document.getElementById("stitches").value.replace(/,/g,"").replace(/\s/g,"");
	if(target.indexOf("-")>0){
		TA=target.substr(0,target.indexOf("-"));
		TF=target.substring(target.indexOf("-")+1);
		if (TA.length>3){
			intA=TA.length%3;
			intB=parseInt(TA.length/3);
			TAC=TA;
			TAC=TA.substr(0,intA);
			for(I=0;I<intB;I++){
				if (TAC==""){
					TAC=TA.substr(intA+I*3,3);
				}else{
					TAC=TAC + "," + TA.substr(intA+I*3,3);
				}
			}
			TA=TAC;
		}
		if(TF.length>3){
			intA=TF.length%3;
			intB=parseInt(TF.length/3);
			TFC=TF;
			TFC=TF.substr(0,intA);
			for(I=0;I<intB;I++){
				if (TFC==""){
					TFC=TF.substr(intA+I*3,3);
				}
				else{
					TFC=TFC + "," + TF.substr(intA+I*3,3);
				}
			}
			TF=TFC;
		}
		target=TA + "-" + TF;
	}else{
		if(target.length>3){
			intA=target.length%3;
			intB=parseInt(target.length/3);
			intC=target;
			intC=target.substr(0,intA);
			for(I=0;I<intB;I++){
				if (intC==""){
					intC=target.substr(intA+I*3,3);
				}else{
				intC=intC + "," + target.substr(intA+I*3,3);
				}
			}
		target=intC;
		}
	}
	document.getElementById("stitches").value=target;
}