// JavaScript Document
function $1(st){
	var obj=document.getElementById(st);
	if (obj)
		return obj;
	obj=document.getElementsByName(st);
	if (obj)
		return obj[0];
	
}
function od_unitEx(st){
	var p = $1(st).value;
	$1("od_unit1").value = p;
	$1("od_unit2").value = p;
}

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=h=0;


caution="Please fill the field below:";
//add h
if (document.order.keyword.value==""){
a=1;
caution=caution+"\n- Design Name / Keywords";
}

if (document.order.company.value==""){
a=1;
caution=caution+"\n- Company Name";
}
if (document.order.od_name.value==""){
b=1;
caution=caution+"\n- Customer Name";
}
if (document.order.email.value==""){
c=1;
caution=caution+"\n- Email";
}
if (document.order.telphone.value==""){
d=1;
caution=caution+"\n- Telephone";
}
if (document.order.Dwidth.value=="" && document.order.Dheight.value==""){
e=1;
caution=caution+"\n- Design Width or Design Height";
}
//验证邮箱
if (document.order.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.order.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.order.telphone.value!=""){
var i=document.order.telphone.value.length;
var j;
for (j=0;j<i;j++){
var strunit=document.order.telphone.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.order.Dwidth.value!=""){
	if (!testNum.exec(document.order.Dwidth.value) && isNaN(document.order.Dwidth.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.order.Dheight.value!=""){
	if(!testNum.exec(document.order.Dheight.value) && isNaN(document.order.Dheight.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.order.company.focus();
}else if(b==1){
document.order.od_name.focus();
}else if(c==1||f==1){
document.order.email.focus();
}else if(d==1||g==1){
document.order.telphone.focus();
}else if(e==1){
document.order.Dwidth.focus();
}else if(h==1){
document.order.keyword.focus();
}

//else if(g==1){
//document.form.Location_Fabric.focus();
//}
return false;
}

if(document.order.image.value==""){
	if (confirm("There is no attachment, are you sure?")==false){
		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 pswCheck()
{
	//document.regform.psw  checkpsw
	var password=document.regform.psw.value;
	var checkpassword=document.regform.checkpsw.value;
	if(password!=checkpassword){
		alert("Please recheck your password again");
		document.regform.psw.value="";
		document.regform.checkpsw.value="";
		return false;
	}
}

function chkform()
{
	var caution;
	var a=b=c=d=0;
	caution="Please complete following files:";

	if (document.tellform.yourname.value==""){
		a=1;
		caution=caution+"\n-Your Name";
		}
	if (document.tellform.youremail.value==""){
		b=1;
		caution=caution+"\n-Your Email";
		}
	if (document.tellform.yourFname.value==""){
		c=1;
		caution=caution+"\n-Friend Name";
		}
	if (document.tellform.yourFemail.value==""){
		d=1;
		caution=caution+"\n-Friend Email";
		}
		
		if (caution!="Please complete following files:"){
			alert(caution);
			if (a==1){
				document.tellform.yourname.focus();
				}
				else if (b==1){
					document.tellform.youremail.focus();
					}
					else if (c==1){
						document.tellform.yourFname.focus();
						}
						else if (d==1){
							document.tellform.yourFemail.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;
}
function renewchecknum(){

var obj=$1("checknumimg");

if(obj.src.indexOf("checkcode.asp")!=-1){
	obj.src="checkcode1.asp";
	return true;
	}
if(obj.src.indexOf("checkcode1.asp")!=-1){
	obj.src="checkcode.asp";
	return true;
	}
}

//
function linkFW(a){
	if(a=="index"){
		window.location.href="/";
		return true;
	}
	
	var a=$1(a);
	if(a){
		a.click();
	}
}
//conversion.asp
function count(){
	var strF,strFN,strT,strTN
	strF=document.cform.fromm.value;
	strFN=document.cform.from_num.value;
	strT=document.cform.to.value;
	//strTN=document.form.to_num.value;
	//strFN=parseInt(strFN);
	if(!isNaN(strFN)){
		strFN=parseFloat(strFN);
		strF=parseFloat(strF);
		if(strF==strT){
			strTN=strFN;
			}
			
			else{
				strTN=strFN*1000000*strF/(strT*1000000);				
			}
	
	document.getElementById("to_n").value=strTN;
	}
	else{
		alert("The number you input is incorrect, please check.");
		document.cform.from_num.select();
		}
}

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 ccformchk(){
	var myDate=new Date();
	var caption="Please fill flowing filed:";
	var a=b=c=d=e=0;
	if (document.ccform.cardname.value==''){
		a=1;
		caption = caption+ "\n- Name of Cardholder";
	}
	if (document.ccform.cardnumber.value==''){
		b=1;
		caption = caption+ "\n- Card Number";
	}
	if (document.ccform.expiration.value==''){
		c=1;
		caption = caption+ "\n- Expiration";
	}
	if (document.ccform.email.value==''){
		d=1;
		caption = caption+ "\n- Email";
	}
	if (document.ccform.companyname.value==''){
		e=1;
		caption = caption+ "\n- Company Name";
	}
	
	var arr_cctype=document.getElementsByName("cctype");
	var cctype_value;
	for(var i=0;i<arr_cctype.length;i++){
		if(arr_cctype.item(i).checked){
			cctype_value=arr_cctype.item(i).value;
		}
	}
	
	var ccnumber_int=document.ccform.cardnumber.value;
	if (cctype_value=="Master Card"){
		if(!(ccnumber_int.substring(0,1)=="5" && ccnumber_int.length=="16")){
			b=1;
			caption = caption+ "\n- Your Master Card Number is incorrect,please check!";
		}
		
	}else if(cctype_value=="Visa"){
		if(!(ccnumber_int.substring(0,1)=="4" && ccnumber_int.length=="16")){
			b=1;
			caption = caption+ "\n- Your Visa Card Number is incorrect,please check!";
		}
	}else if(cctype_value=="American Express"){
		if(!(ccnumber_int.substring(0,1)=="3" && ccnumber_int.length=="15")){
			b=1;
			caption = caption+ "\n- Your American Express Card Number is incorrect,please check!";
		}
	}
	
	
	
	if (document.ccform.email.value!=''){
		var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
		if (!rule.exec(document.ccform.email.value)){
			d=1;
			caption=caption + "\n- Incorrect email address, please check it.";
		}
	}
	
	if (document.ccform.cardnumber.value!=''){
		var ruleCCnum=/^[\d]+$/i;
		if (!ruleCCnum.exec(document.ccform.cardnumber.value)){
			b=1;
			caption=caption + "\n- Incorrect Cardnumber, please check it.";
		}
	}
	
	if (document.ccform.expiration.value!=''){
		var expDate=document.ccform.expiration.value;
		//var dv=new Date(expData);
		
		var myYear=myDate.getYear().toString();
		var myMonth=myDate.getMonth().toString();
		
		if(chkdate(expDate)){
			var strExpA="20"+expDate.substring(expDate.indexOf("/")+1,expDate.length);
			if (parseInt(strExpA)<parseInt(myYear)){
				c=1;
				caption=caption + "\n- Your card has exceed the time limit,please change another one.";
			}
			var strExpB=expDate.substring(0,expDate.indexOf("/"));
			if(parseInt(strExpB)==0){
				strExpB=expDate.substring(1,2);
				}
			if(parseInt(strExpA)==parseInt(myYear) && parseInt(strExpB)<(parseInt(myMonth)+1)){
				c=1;
				caption=caption + "\n- Your card has exceed the time limit,please change another one.";
			}
		}else{
			c=1;
			caption=caption + "\n- Incorrect the format of Expiration, please check it.";
		}

	}
	
	if (e==1){
		document.ccform.companyname.focus();
	}
	
	if (d==1){
		document.ccform.email.focus();
		}else if (c==1){
			document.ccform.expiration.focus();
			}else if (b==1){
				document.ccform.cardnumber.focus();
				}else if (a==1){
					document.ccform.cardname.focus();
					}
	
	if (caption!="Please fill flowing filed:"){
		alert(caption);
		return false;
	}
}

function info_chk(){
	var caption="Please fill flowing filed:";
	var a=b=0;
	if (document.sendinfoform.abemail.value==''){
		a=1;
		caption = caption+ "\n- Email";
	}
	if (document.sendinfoform.name.value==''){
		b=1;
		caption = caption+ "\n- Name";
	}

	if (document.sendinfoform.abemail.value!=''){
		var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
		if (!rule.exec(document.sendinfoform.abemail.value)){
			a=1;
			caption=caption + "\n- Incorrect email address, please check it.";
		}
	}


	if (a==1){
		document.sendinfoform.abemail.focus;
	}else if(b==1){
		document.sendinfoform.name.focus;
	}

	if (caption=="Please fill flowing filed:"){
		return true;
	}
	alert(caption);
	return false;

}
