// JavaScript Document
function chkcon(){
	var msg;
	var a=b=c=0;
	
	msg="Following fields are blank or incorrect, please check."
	if(document.form.cus_name.value==""){
		a=1;
		msg=msg+"\n - Customer Name can't be blank";
		}
		if (document.form.email.value==""){
			b=1;
			msg+="\n - Email Address can't be blank";
		}
		if(document.form.email.value!=""){
			emailPattern =  /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;
			if(!document.form.email.value.match(emailPattern)){
				c=1;
				msg+="\n - Email Address is incorrect"
			}
		}
		
		if (msg!="Following fields are blank or incorrect, please check."){
			if(a==1){
				alert(msg);
				document.form.cus_name.focus();
				return false;
			}
			if (b==1 || c==1){
				alert(msg);
				document.form.email.focus();
				return false;
			}
		}
	}

function addBookMark(title,url){
	if (window.sidebar){
		window.sidebar.addPanel(title,url,"");
	}else if(document.all){
		window.external.AddFavorite(url,title);
	}else if(window.opera && window.print){
		return true;
	}
}


function chkform(){
var caution;
var a=b=c=d=e=f=g=0;

caution="Please fill the field below:";
if (document.form.Company_Name.value==""){
a=1;
caution=caution+"\n- Company Name";
}
if (document.form.Customer_Name.value==""){
b=1;
caution=caution+"\n- Customer Name";
}
if (document.form.email.value==""){
c=1;
caution=caution+"\n- Email";
}
if (document.form.Phone.value==""){
d=1;
caution=caution+"\n- Phone";
}
if (document.form.Design_Width.value=="" && document.form.Design_Height.value==""){
e=1;
caution=caution+"\n- Design Width or Design Height";
}

//验证邮箱
if (document.form.email.value!=""){
//var rule=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
//var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
emailPattern =  /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;
if(!document.form.email.value.match(emailPattern)){
//alert("Incorrect email address, please check it.");
//document.form.Email.focus();
//return false;
g=1;
caution=caution+"\n- Incorrect email address, please check it.";
}
}


var testNum=/^[0-9]*\s?[0-9]*\/?[0-9]*(\"?|\''?|in|inch|IN|Inch|INCH|In|mm|MM|Mm|mM)$/;        //正则表达式，判断是否为分数
if (document.form.Design_Width.value!=""){
	if (!testNum.exec(document.form.Design_Width.value) && isNaN(document.form.Design_Width.value)){
//	if(isNaN(document.form.Design_Width.value)){
//	alert("Design Width accept number only,please check.");
//	document.form.Design_Width.focus();
//	return false;
e=1;
caution=caution+"\n- Design Width accept number only,please check.";
	}
	//}
	}
if (document.form.Design_Height.value!=""){
	if(!testNum.test(document.form.Design_Height.value) && isNaN(document.form.Design_Height.value)){
//	alert("Design Height accept number only,please check.");
//	document.form.Design_Height.focus();
//	return false;
e=1;
caution=caution+"\n- Design Height accept number only,please check.";
	}
	}
	
//验证电话
if(document.form.Phone.value!=""){
var i=document.form.Phone.value.length;
var j;
for (j=0;j<i;j++){
var strunit=document.form.Phone.value.substring(j,j+1);
//alert (strunit);
if(isNaN(strunit) && strunit!="-" && strunit!="(" && strunit!=")" && strunit!="_" && strunit!="+"){
	f=1;
	caution=caution+"\n- Phone is incorrect,please check!";
	break;
//alert("Phone is incorrect,please check!");
//document.form.Address.focus();
//return false;
}
}
}


if (caution!="Please fill the field below:"){
alert(caution);
if(a==1){
document.form.Company_Name.focus();
}else if(b==1){
document.form.Customer_Name.focus();
}else if(c==1||g==1){
document.form.email.focus();
}else if(d==1||f==1){
document.form.Phone.focus();
}else if(e==1){
document.form.Design_Width.focus();
}
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;
}
