function Cart_Add(obj_id,obj_num,obj_size){
    var str_url;	

    if (obj_id.length<=0)
    {
        alert("産品不能爲空!");
        return false;
    }

    if (isNaN(obj_num))
    {
        alert("要爲數位!");
        return false;
    }

	if(obj_size!=0){
		var cksize = document.form1.sizecheck;
		var itemSelected = false;

		if(cksize.checked){
			obj_size=cksize.value;
			itemSelected = true;
		}
		else{

			for(i=0;i<cksize.length;i++){
				if(cksize[i].checked){
					obj_size=cksize[i].value;
					itemSelected = true;
				}
			}
		}

		if(itemSelected==false){
			alert("Please select a price !");
		}else{
			str_url=Url_Encode("/cart/basket.php?opt=Cart_Add&id="+obj_id+"&obj_num="+obj_num+"&obj_size="+obj_size);
			window.location.href=str_url;
		}

	}else{

		str_url=Url_Encode("/cart/basket.php?opt=Cart_Add&id="+obj_id+"&obj_num="+obj_num+"&obj_size="+obj_size);
		window.location.href=str_url;
	}
}

function Cart_Update(obj_id,obj_num,obj_size){
    var str_url;
    if (obj_id.length<=0)
    {
        alert("産品不能爲空!");
        return false;
    }

    if (isNaN(obj_num))
    {
        alert("要爲數位!");
        return false;
    }

    str_url=Url_Encode("/cart/basket.php?opt=Cart_Update&id="+obj_id+"&obj_num="+obj_num+"&obj_size="+obj_size);
    window.location.href=str_url;
}

function Url_Encode(url){
    var s;
    s=url.split(" ");
    url=s.join("%20");
    return url;
}


function CheckAll(form){
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
        if (e.type=="checkbox"){
            e.checked=true;
        }

    }
}

function Clear(obj) {
  for (var i=obj.elements.length-1;i>=0;i--)
    {
    var e = obj.elements[i];
        if (e.type=="checkbox" && e.checked==true){
            e.checked=false;
        }

    }
}


function chkCheckBox(obj,status){
	if(obj.type=="checkbox"){
		obj.checked=status;
	}else{
		for (var i=0;i<obj.length;i++)   {
		var e = obj[i];
			if (e.type=="checkbox"){
				e.checked=status;
			}

		}
	}
}

function chkallmail(form,objself,changetype){
  for (var i=0;i<form.elements.length;i++){
        var e = form.elements[i];
        if (e.type=="checkbox"){
            if (changetype)
            {
                e.checked=objself.checked;
            }else{
                e.checked=!objself.checked;
            }
        }

    }
}



function Show(url){
    window.open(url,"window","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,width=700,height=600,top=0,left=0");
}

function openCenterWin(url,widthVal,heightVal) {
    window.open(url,"_blank","left="+(window.screen.width-widthVal)/2+",top="+(window.screen.height-heightVal-6)/2+",width="+widthVal+",height="+heightVal+",scrollbars=yes,resizable=yes");
	
}

function openCW(url,winname,widthVal,heightVal){
	var win;
	if(winname=="") {
		winname="_blank";
	}
	win=window.open(url,winname,"left="+(window.screen.width-widthVal)/2+",top="+(window.screen.height-heightVal-6)/2+",width="+widthVal+",height="+heightVal+",scrollbars=yes,menubar=no,resizable=yes");
	win.focus();
}

function refreshWindown(url,widthVal,heightVal) {
	window.openner.refresh();	
}

function Show2(manid){
    window.open("men_profile.php?manid="+manid,"maninfo","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,width=740,height=700,top=0,left=0");
}

function ShowWin2(url,winname,winoption){
    if(winname=="") {
		winname="_blank";
	}
	window.open(url,winname,winoption);
}

function delconfirm(msg){
    if (confirm(msg)) {
        return true;
    }else{
        return false;
    }
}

function image_auto_size(obj,pwidth,pheight){
    var objheight,objwidth;

    if (pwidth<=0)
    {
        pwidth=500;
    }

    if (obj.width>=500)
    {
        obj.width=pwidth;
    }
}

function ImgAutoSize(imgD,FitWidth,FitHeight)  
{ 
	var image1=new Image();  
	image1.onload = function () 
	{ 
		if(this.width>0 && this.height>0)  
		{  
			if(this.width/this.height>= FitWidth/FitHeight)  
			{  
				if(this.width>FitWidth)  
				{  
					imgD.width=FitWidth;  
					imgD.height=(this.height*FitWidth)/this.width;  
				}  
				else  
				{  
					imgD.width=this.width;  
					imgD.height=this.height;  
				}  
			}  
			else  
			{  
				if(this.height>FitHeight)  
				{  
					imgD.height=FitHeight;  
					imgD.width=(this.width*FitHeight)/this.height;  
				}  
				else  
				{  
					imgD.width=this.width;  
					imgD.height=this.height;  
				}  
			}  
		} 
		image1 = null; 
	} 
	image1.src=imgD.src;  
	imgD.style.cursor = 'hand'; 
	imgD.onclick= function(){openCW(this.src,'',750,550)}; 
	imgD.title = "Click to view full size image"; 
}

function agent_print_emf(emfid,obj){
    self.print();
    obj.action="updateprint.php";
    obj.submit();
}

function subform(formobj,action,ack,msg){
    if (ack=='1'){
        if (confirm(msg)) {
            formobj.action=action;
            formobj.submit();
        }else{
            return false;
        }
    }else{
        formobj.action=action;
        formobj.submit();
    }
}

function sendmailBack(form,act){
    form.action=act;
    form.submit();
}

function chksubmit(form){
    if(form.elements['body'].value.length<=0){
        alert('Please enter your message before you send it !');
        form.elements['body'].focus();
        return false;
    }

    for(i=1;i<=3;i++){
      obj=eval('form.file'+i);
      if(typeof(obj)=='object'){
		if(obj.value.length>0){
            if(!chkfiletype(obj.value)){
                alert("Sorry! The file you selected to be attached is not an Image file!\nPlease note all attachments should be JPG images and saved at 72 dpi (Dots Per Inch).\n");
                obj.focus();
                return false;
            }
        }
	  }
    }

    if(form.elements['sendagree'].checked==false){
        alert('You must agree to the terms of use and privacy policy!');
        form.elements['sendagree'].focus();
        return false;
    }

	if (typeof(form.sendbg)=='object'){
		if (form.elements['sendbg'].checked==false)
		{
			alert('Sorry,you did not give your permission to us to release my personal disclosure information to this lady!');
			form.elements['sendbg'].focus();
			return false;
		}		
	}


	if (form.elements['sendtimes'].value>0){
		 alert('Click the button only ONCE when sending out message!');	
		 return false;
	}else{
		form.elements['sendtimes'].value=form.elements['sendtimes'].value+1;
	}

	window.onbeforeunload = null;

    return true;
}

function chkfiletype(fn){
    len=fn.length;
    fn1=fn.substr(len-4,4).toLowerCase();
    fn2=fn.substr(len-5,5).toLowerCase();
    if(fn1=='.gif' || fn1=='.jpg' || fn2=='.jpge'){
        return true;
    }else{
		return false;
    }
}



function dispobj(obj){
	if(obj.style.display==""){
		obj.style.display="none";
	}else{
		obj.style.display="";
	}
}

function showOrHideLayer(showID,hideID){
	var showObj = document.getElementById(showID);
	var hideObj = document.getElementById(hideID);

	showObj.style.display="";
	hideObj.style.display="none";
}

function DisableEnterKey(){
	if(event.keyCode==13){
		  event.returnValue=false;
	}
}

//中英文字符長度
function StringLength(fData)
{
 var intLength=0;
 for (var i=0;i<fData.length;i++)
 {
	if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255)){
		intLength = intLength+3;
	}else{
		intLength = intLength+1;
	}
 }
 return intLength;
}

//截取混合字符串
function cutMixChar(str,mixLen)
{
 if(mixLen >= StringLength(str)){
	 return str;
 }else{

	var n=0;
	for (var i=0;i<str.length;i++){
		
		if ((str.charCodeAt(i) < 0) || (str.charCodeAt(i) > 255)){
			n = n + 3;
		}else{
			n = n + 1;
		}

		if(n>mixLen){
			var cutstr = str.substring(0,i);
			return cutstr;
		}
	}
 }
}

//控制字符串长度
function maxCharNum(objID,maxLen)
{
	var objValue = document.getElementById(objID).value;
	var strLength = StringLength(objValue);

	if(strLength>maxLen){
		alert("對不起，不能超過" + maxLen + "個字符長度");
		document.getElementById(objID).value = cutMixChar(objValue,maxLen);
	}
}

function checkallemfmail(){
	document.form1.ckmail.checked= !document.form1.ckmail.checked;
	if(document.form1.elements['chosemail[]']){
		chkCheckBox(document.form1.elements['chosemail[]'],document.form1.ckmail.checked);
	}
}

function gotoqpidnetwork(url,newwin){
	if(newwin){
		 window.open('/my/qpidnetwork.php?url='+url,"_blank",'');	
	}else{
		window.location.href='/my/qpidnetwork.php?url='+url;
	}	
}


function ordercredit(){
	gotoqpidnetwork('/payment/order.php',true);

	//创建DIV
	var div = document.createElement("div");
	div.id="_ordercreditsMask_";
	div.style.display="none"
    document.body.appendChild(div);


	var div2 = document.createElement("div");
	div2.id="_ordercreditsformMask_";
	div2.style.display="none";
	div2.style.width="400px";
	/*div2.style.height="80px";*/
	div2.style.zIndex="51";
	div2.style.border="3px #B22313 solid";

	div2.style.backgroundColor="#FFFFFF";
	div2.style.top="45%";
	div2.style.position="absolute";

	div2.innerHTML="<div align='right' style='background-color:#b22313; height:22px; padding-top:3px;width:400px'><a href='javascript:ordercreditfail()'><img src='/my/images/close2.jpg' width='14' height='14' border='0' /></a></div><div align='center' style='padding:25px;font-size:12px;width:400px'><table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'><tr><td width='55'><img src='/my/images/info.gif' align='absmiddle' /><br /></td><td align='left' style='font-size:13px;'>To add credits, please go to the ordering page (the pop-up window). When you finish, refresh the current page.  </td></tr></table><br /><a class='Link_Blue' href='javascript:window.location.reload()'>Click here to refresh &gt;&gt;</a></div>";
    document.body.appendChild(div2);


	var checkoutMaskObj=document.getElementById('_ordercreditsMask_');
	var updateformMaskObj=document.getElementById('_ordercreditsformMask_');
	checkoutMaskObj.style.backgroundColor="#c5c5c5";
	checkoutMaskObj.style.display = "inline";
	checkoutMaskObj.style.position ="absolute";
	checkoutMaskObj.style.zIndex="50";
	checkoutMaskObj.style.left="0px";
	checkoutMaskObj.style.top="0px";
	checkoutMaskObj.style.width=document.body.scrollWidth;
	checkoutMaskObj.style.height=document.body.scrollHeight;
	checkoutMaskObj.style.filter="alpha(opacity=50)";
	checkoutMaskObj.style.opacity="0.6";
	updateformMaskObj.style.left=(document.body.clientWidth-500)/2;
    checkoutMaskObj.style.display='inline';
    updateformMaskObj.style.display='inline';  
    window.scroll(0,0) ;

	window.onresize=function(){
		updateformMaskObj.style.left=(document.body.clientWidth-500)/2;
		checkoutMaskObj.style.width=document.body.scrollWidth;
	}

}


function ordercreditfail(){
	var checkoutMaskObj=document.getElementById('_ordercreditsMask_');
	var updateformMaskObj=document.getElementById('_ordercreditsformMask_');	
    checkoutMaskObj.style.display='none';
    updateformMaskObj.style.display='none';  
}


