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 chktranslator(form){

    if(typeof(form.rmethod)=='object'){
        if(typeof(form.mailtype)=='object'){
            if(form.mailtype.value=="reply"){
                if(form.rmethod.value==''){
                    alert("請選擇女士回復本信的方式!");
                    return false;
                }
            }
        }else{
            if (form.rmethod.options[form.rmethod.selectedIndex].value==""){
                alert("請選擇女士回復本信的方式!");
                form.rmethod.focus();
                return false;
            }
        }
    }


    if(typeof(form.checkcomment)=='object'){
        if(form.checkcomment.value=="Y"){
            if(form.lady_tel.value==''){
                alert("請填入您聯繫女士的所用的電話號碼/電子郵箱!");
                form.lady_tel.focus();
                return false;
            }
        }
    }


    if(typeof(form.sendtimes)=='object'){
        if(form.sendtimes.value>0){
            if(typeof(form.sendmailsub)=='object'){
                form.sendmailsub.disabled=true;
            }
            if(typeof(form.messagesub)=='object'){
                form.messagesub.disabled=true;
            }

            alert("Click the button only ONCE when sending out message!");
            return false;
        }
        form.sendtimes.value=form.sendtimes.value+1;
    }

    return true;
}

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);
	}
}