﻿// JScript File
var post_param="ctl00_ContentPlaceHolder1_";
var appName = navigator.appName;
function popupfrm(dest,popname,width,height)
{
	popup=window.open(dest,popname,"left="+ (((screen.width-width)/2)) + ",top=" + (((screen.height-height)/2)) +",width="+width+",height="+height+",resizable=no,menubar=0,scrollbars=yes,location=no,alwaysRaised=yes,status=yes");
	popup.focus()
}

function popupPrint(dest,popname)
{
    width=810;
    height=600;
	popup_print=window.open(dest,popname,"left="+ (((screen.width-width)/2)) + ",top=" + (((screen.height-height)/2)) +",width="+width+",height="+height+",resizable=no,menubar=1,scrollbars=yes,location=no,alwaysRaised=yes,status=yes");
	popup_print.focus();
}

function DigitOnly(obj)
{
    //46 = .
    if ((window.event.keyCode <= 47) || (window.event.keyCode > 57))
    {
        window.event.returnValue = false;
    }
}

function DigitOnlySingleDot(e,obj) {
   var KeyCode = (e.keyCode) ? e.keyCode : e.which;
   var CharCode = (e.charCode) ? e.charCode : 0;
   CharCode = (appName=="Microsoft Internet Explorer") ? -1 : CharCode;
   foundDot=0;
   if(obj.value.indexOf('.')>-1) foundDot=1;
   return ((KeyCode == 8) // backspace
        || (KeyCode == 9) // tab
        || (KeyCode == 37) // left arrow
        //|| (KeyCode == 39) // right arrow
        || ((KeyCode == 46) && (CharCode == 0)) // delete
        || (CharCode == 0)
        || ((KeyCode > 47) && (KeyCode < 58)) // 0 - 9
        || (KeyCode == 46) && (foundDot==0)
   );
}

function echeck(str) 
{
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
       alert("กรอก Email ไม่ถูกต้อง")
       return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
       alert("กรอก Email ไม่ถูกต้อง")
       return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("กรอก Email ไม่ถูกต้อง")
        return false
    }

     if (str.indexOf(at,(lat+1))!=-1){
        alert("กรอก Email ไม่ถูกต้อง")
        return false
     }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("กรอก Email ไม่ถูกต้อง")
        return false
     }

     if (str.indexOf(dot,(lat+2))==-1){
        alert("กรอก Email ไม่ถูกต้อง")
        return false
     }

     if (str.indexOf(" ")!=-1){
        alert("กรอก Email ไม่ถูกต้อง")
        return false
     }

     return true					
}

function ValidateForm(obj,obj2,obj3)
{
	var emailID=obj
	var mailname=obj2
	var mailAuthen=obj3

    if ((mailname.value==null)||(mailname.value=="")){
	    alert("กรุณากรอก ชื่อผู้ส่ง")
	    mailname.focus()
	    return false
	}
	if ((emailID.value==null)||(emailID.value=="")){
		alert("กรุณากรอก Email")
		emailID.focus()
		return false
	}
	if ((mailAuthen.value==null)||(mailAuthen.value=="")){
		alert("กรุณากรอกตัวอักษรตามภาพตัวอย่าง")
		mailAuthen.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		//emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

// alert

function checkAccept()
{
        if(confirm('คุณต้องการที่จะยืนยันการสั่งซื้อสินค้า ใช่หรือไม่?'))
        {
            return true;                     
        }
        else
        {
            return false;
        } 
}
