// coded by turtles 2007
//
// http://www.turtle-media.com/
//
// all rights reserved
//
var root
root = 'http://www.daily7-daily10.com/'
//root = 'http://www.hong-kong-web-design.com/clients/daily7/'
//
////////////////////////////////////////////////////////////////////
// get  and set cookie script
function getC(c_name){ 
if (document.cookie.length>0){c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1){ c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) {c_end=document.cookie.length}; return unescape(document.cookie.substring(c_start,c_end))}} return ""}
// setPermCookie script
function setC(c_name, c_value){document.cookie =  c_name + '=' + c_value + '; expires=Thu, 2 Aug 2040 20:47:11 UTC; path=/'}
////////////////////////////////////////////////////////////////////
//showhide
function show(divid){document.getElementById(divid).style.display = "block";}
function showinline(divid){document.getElementById(divid).style.display = "inline"}
function hide(divid){document.getElementById(divid).style.display = "none"}
////////////////////////////////////////////////////////////////////
function redirect(url){	document.location = url}
function conf(url){if(confirm("Are you sure?")){redirect(url)}}
////////////////////////////////////////////////////////////////////
function msg(loc) {
    if(confirm("Are you sure you want to delete?"))
    {
        location = loc;
    }
}
function goback(loc) {
    location = loc;
}
//////////////////////////////////////////////////////////////////////
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

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("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

// Radio Button Validation
function checkRadio (frmName, rbGroupName) { 
 var radios = document[frmName].elements[rbGroupName]; 
 for (var i=0; i <radios.length; i++) { 
  if (radios[i].checked) { 
   return true; 
  } 
 } 
 return false; 
}                   
				  
function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateSubForm(){
	var addID1=document.signUpfrm.street1
	var addID2=document.signUpfrm.street2
	var fnameID=document.signUpfrm.firstName
	var lnameID=document.signUpfrm.lastName
	var snameID=document.signUpfrm.schoolName
	var dobID=document.signUpfrm.childDOB
	var sexID=document.signUpfrm.sex
	var typeID=document.signUpfrm.subs
			
	if ((addID1.value==null)||(addID1.value=="")){
		alert("Please enter your delivery address, Address 1")
		addID1.focus()
		return false
	}
	
	if ((addID2.value==null)||(addID2.value=="")){
		alert("Please enter your delivery address, Address 2")
		addID2.focus()
		return false
	}
		
	if ((fnameID.value==null)||(fnameID.value=="")){
		alert("Please enter your child's first name")
		fnameID.focus()
		return false
	}
	
	if ((lnameID.value==null)||(lnameID.value=="")){
		alert("Please enter your child's last name")
		lnameID.focus()
		return false
	}
	
	if ((snameID.value==null)||(snameID.value=="")){
		alert("Please enter your child's school name")
		snameID.focus()
		return false
	}
	
	if ((dobID.value==null)||(dobID.value=="")){
		alert("Please enter your child's date of birth")
		dobID.focus()
		return false
	}
	if (isDate(dobID.value)==false){
		dobID.focus()
		return false
	}
	if ((sexID.value==null)||(sexID.value=="")){
		alert("Please select your child's gender")
		sexID.focus()
		return false
	}
	////////////////////////////////////////////
	if ((typeID.value==null)||(typeID.value=="")){
		alert("Please choose a subscription type")
		typeID.focus()
		return false
	}
	
	return true	
	
	
}

function ValidateSubForm2(){
	var phoneID=document.signUpfrm.phone
	var emailID=document.signUpfrm.email
	var addressID=document.signUpfrm.address
	var countryID=document.signUpfrm.country
	var fnameID=document.signUpfrm.firstName
	var lnameID=document.signUpfrm.lastName	
	var dobID=document.signUpfrm.childDOB
	var genderID=document.signUpfrm.gender
	var snameID=document.signUpfrm.schoolName
	var typeID=document.signUpfrm.subs
	var cycleID=document.signUpfrm.cycle
	
	if ((typeID.value==null)||(typeID.value=="")){
		alert("Please choose a subscription.")
		typeID.focus()
		return false
	}
	
	if (!checkRadio("signUpfrm","cycle")) {
	  alert("Please select how you would like to be charged (Yearly or Monthly)."); 
	  return false
	}
	
	//if they've chosen a print subscription type, prompt for address
	if ((typeID.value == "d7-HK") || (typeID.value == "d10-HK") || (typeID.value == "mlp-HK") || (typeID.value == "mlp")){
		
		if ((countryID.value==null)||(countryID.value=="")){
			alert("You have selected a print subscription, please choose your country and enter your delivery address.")
			countryID.focus()
			return false
		}
		
		if ((addressID.value==null)||(addressID.value=="")){
			alert("You have selected a print subscription, please enter your delivery address.")
			addressID.focus()
			return false
		}
	}
	
	//if they've chosen a HK print subscription type, check country
	if ((typeID.value == "d7-HK") || (typeID.value == "d10-HK") || (typeID.value == "mlp-HK")){
		
		if (countryID.value!="HONG KONG"){
			alert("You have selected a HK only print subscription, your delivery address must be in Hong Kong.")
			countryID.focus()
			return false
		}
	}	
	
	if ((phoneID.value==null)||(phoneID.value=="")){
		alert("Please enter the guardian's contact phone number")
		phoneID.focus()
		return false
	}
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter the guardian's email address")
		emailID.focus()
		return false
	}
	
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	
	if ((fnameID.value==null)||(fnameID.value=="")){
		alert("Please enter your child's first name")
		fnameID.focus()
		return false
	}
	
	if ((lnameID.value==null)||(lnameID.value=="")){
		alert("Please enter your child's last name")
		lnameID.focus()
		return false
	}
	
	if ((dobID.value==null)||(dobID.value=="")){
		alert("Please enter your child's date of birth")
		dobID.focus()
		return false
	}
	if (isDate(dobID.value)==false){
		dobID.focus()
		return false
	}

	if ((snameID.value==null)||(snameID.value=="")){
		alert("Please enter your child's school name")
		snameID.focus()
		return false
	}

	if (!checkRadio("signUpfrm","gender")) {
	  alert("Please select your child's gender"); 
	  return false
	}	
	
	return true
 }

function ValidateForm2(){
	var subID=document.registerfrm.subId
	var dobID=document.registerfrm.childDOB

	
	if ((subID.value==null)||(subID.value=="")){
		alert("Please enter your Sub ID")
		subID.focus()
		return false
	}	
	
	if ((dobID.value==null)||(dobID.value=="")){
		alert("Please enter your child's D.O.B.")
		dobID.focus()
		return false
	}
	
	return true
 }


function ValidateContact1(){
	var nameID=document.contact1.pname
	var emailID=document.contact1.email
	
	if ((nameID.value==null)||(nameID.value=="")){
		alert("Please enter your name")
		document.contact1.pname.focus()
		return false
	}
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address")
		var emailID=document.contact1.email.focus()
		return false
	}
	
	if (echeck(emailID.value)==false){
		emailID.value=""
		var emailID=document.contact1.email.focus()
		return false
	}
	
	return true
 }

function ValidateContact2(){
	var nameID=document.contact2.pname
	var emailID=document.contact2.email
	
	if ((nameID.value==null)||(nameID.value=="")){
		alert("Please enter your name")
		document.contact2.pname.focus()
		return false
	}
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address")
		document.contact2.email.focus()
		return false
	}
	
	if (echeck(emailID.value)==false){
		emailID.value=""
		document.contact2.email.focus()
		return false
	}
	
	return true
 }
 
function ValidateCartForm1(){
	var countryID1=document.cartFrm1.country
	
	if ((countryID1.value==null)||(countryID1.value=="")){
		alert("Please choose your shipping country.")
		countryID1.focus()
		return false
	}

	//var addID1=document.cartFrm.address1
//	var addID2=document.cartFrm.address2
//	
//	if ((addID1.value==null)||(addID1.value=="")){
//		alert("Please enter your shipping address, Address 1")
//		addID1.focus()
//		return false
//	}
//	
//	if ((addID2.value==null)||(addID2.value=="")){
//		alert("Please enter your shipping address, Address 2")
//		addID2.focus()
//		return false
//	}
	
	return true
 } 
function ValidateSubRForm(){
	var subIdID=document.renewalfrm.subId
	var fnameID=document.renewalfrm.firstName
	var lnameID=document.renewalfrm.lastName
	var phoneID=document.renewalfrm.phone
	var amountID=document.renewalfrm.amount
	var addressID=document.renewalfrm.address
	var countryID=document.renewalfrm.country
	var typeID=document.renewalfrm.subs
			
	if ((subIdID.value==null)||(subIdID.value=="")){
		alert("Please enter your Subscriber ID, starting with A0, B0 or C0. Type NA if you don't have one.")
		subIdID.focus()
		return false
	}
	
	if ((fnameID.value==null)||(fnameID.value=="")){
		alert("Please enter your child's first name.")
		fnameID.focus()
		return false
	}
	
	if ((lnameID.value==null)||(lnameID.value=="")){
		alert("Please enter your child's last name.")
		lnameID.focus()
		return false
	}
	
	if ((phoneID.value==null)||(phoneID.value=="")){
		alert("Please enter your contact phone number.")
		phoneID.focus()
		return false
	}
	
	if (isInteger(phoneID.value) == false){
		alert("Phone number : only digits allowed.")
		phoneID.focus()
		return false
	}
	
	if ((countryID.value==null)||(countryID.value=="")){
		alert("Please choose your country and enter your delivery address.")
		countryID.focus()
		return false
	}
	
	if ((addressID.value==null)||(addressID.value=="")){
		alert("Please enter your delivery address.")
		addressID.focus()
		return false
	}
	
	if ((typeID.value==null)||(typeID.value=="")){
		alert("Please choose a subscription type")
		typeID.focus()
		return false
	}
		
	if ((amountID.value==null)||(amountID.value=="")){
		alert("Please enter the amount in HKD.")
		amountID.focus()
		return false
	}
	
	if (isInteger(amountID.value) == false){
		alert("Amount must be a number only.")
		amountID.focus()
		return false
	}


	
	return true	
	
	
}

