// JavaScript Document
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_pay(){
var caution;
var a=b=c=d=e=f=g=0;

caution="Please fill the field below:";
if (document.form.Customer_Name.value==""){
a=1;
caution=caution+"\n- Name";
}
if (document.form.Company_Name.value==""){
b=1;
caution=caution+"\n- Company";
}
if (document.form.Email.value==""){
c=1;
caution=caution+"\n- Email";
}
if (document.form.Address.value==""){
d=1;
caution=caution+"\n- Telephone";
}
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;
if (!rule.exec(document.form.Email.value)){
//alert("Incorrect email address, please check it.");
//document.form.Email.focus();
//return false;
f=1;
caution=caution+"\n- Incorrect email address, please check it.";
}
}


if(document.form.Address.value!=""){
var i=document.form.Address.value.length;
var j;
for (j=0;j<i;j++){
var strunit=document.form.Address.value.substring(j,j+1);
//alert (strunit);
if(isNaN(strunit) && strunit!="-" && strunit!="(" && strunit!=")" && strunit!="_"){
//alert("Telephone is incorrect,please check!");
//document.form.Address.focus();
//return false;
g=1;
caution=caution+"\n- Telephone is incorrect,please check!";
break;
}
}
}

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.exec(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 (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||f==1){
document.form.Email.focus();
}else if(d==1||g==1){
document.form.Address.focus();
}else if(e==1){
document.form.Design_Width.focus();
}//else if(g==1){
//document.form.Location_Fabric.focus();
//}
return false;


}

//if(document.form.Design_Width.value!=""){
	//document.form.Design_Width.value=document.form.Design_Width.value+" inches";
	//}
	//if(document.form.Design_Height.value!=""){
		//document.form.Design_Height.value=document.form.Design_Height.value+" inches";
		//}
}

function chkform()
{
	var caution;
	var a=b=c=d=0;
	caution="Please complete following files:";
	if (document.form.s_name.value==""){
		a=1;
		caution=caution+"\n-Your Name";
		}
	if (document.form.s_email.value==""){
		b=1;
		caution=caution+"\n-Your Email";
		}
	if (document.form.t_name.value==""){
		c=1;
		caution=caution+"\n-Friend Name";
		}
	if (document.form.t_email.value==""){
		d=1;
		caution=caution+"\n-Friend Email";
		}
		
		if (caution!="Please complete following files:"){
			alert(caution);
			if (a==1){
				document.form.s_name.focus();
				}
				else if (b==1){
					document.form.s_email.focus();
					}
					else if (c==1){
						document.form.t_name.focus();
						}
						else if (d==1){
							document.form.t_email.focus();
							}
							return false;
							
					
			}
		
	}
	
function cl(){
window.close();
	}
	
//增加上传文件的控件
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;
}