//scripts.js file
//May 2003 Ulric Whyte


// window open script
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//frame jumper for nav bar
function setFrame(frameName, frameSrc)
  {
    parent[frameName].location=(frameSrc + '.cfm');
  }
  
  
//new set frame  
function change_frames(file1, file2)
   {
   parent.nav.location=file1;
   parent.content.location=file2;
   }
  
 
// Macromedia Version
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Pull-Down Menu Navigation Function
 function PageChanger(page) {           
    location= page;       
    document.forms[0].sortby.options[0].selected=true;
    
    }
	
	
	
// rollover scripts
if (document.images)
{
aboutOn= new Image;
aboutOn.src="images/nav/about_ro.gif"

aboutOff= new Image; 
aboutOff.src="images/nav/about_off.gif";

classesOn= new Image;
classesOn.src="images/nav/classes_ro.gif";

classesOff= new Image; 
classesOff.src="images/nav/classes_off.gif";

infoOn= new Image; 
infoOn.src="images/nav/info_ro.gif";

infoOff= new Image; 
infoOff.src="images/nav/info_off.gif";

linksOn= new Image; 
linksOn.src="images/nav/links_ro.gif";

linksOff= new Image; 
linksOff.src="images/nav/links_off.gif";

contactOn= new Image; 
contactOn.src="images/nav/contact_ro.gif";

contactOff= new Image; 
contactOff.src="images/nav/contact_off.gif";

myOff= new Image; 
myOff.src="images/nav/mysore_off.gif";

myOn= new Image; 
myOn.src="images/nav/mysore_ro.gif";
}

function on(pic)  {

		if (document.images)
					{
					document.images[pic].src=eval(pic +"On.src");
					}
}

function off(pic) {
		if (document.images)
				{
						document.images[pic].src=eval(pic +"Off.src");
				}
}



// form validation object finder
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// validation script for all other forms
//validation for login pages
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number without spaces.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

var clickedOnTandC = false;

function validate() {
 if (document.forms[0].FirstName.value    != "" &&
     document.forms[0].LastName.value   != "" &&
     document.forms[0].Address1.value != "" &&
	 document.forms[0].City.value != "" &&
	 document.forms[0].Postcode.value != "" &&
     document.forms[0].Email.value   != "" &&
	// document.forms[0].Email1.value  != "" &&
     document.forms[0].Phone.value  != "") {

     // Email confirmation ok?
        // if (document.forms[0].Email.value != document.forms[0].Email1.value) {
        //  alert("Please confirm your email address and ensure both email addresses match.");
        //   return(false);
        // }

     // Email syntax ok?
     if (document.forms[0].Email.value.indexOf(".") == -1 ||
         document.forms[0].Email.value.indexOf("@") == -1) {
        alert("Please enter a valid email address.");
        return(false);
     }


/*
	 // Phone Number
     // Declaring required variables
     var digits = "0123456789";
     // non-digit characters which are allowed in phone numbers
     var phoneNumberDelimiters = "()- ";
     // characters which are allowed in international phone numbers
     // (a leading + is OK)
     var validWorldPhoneChars = phoneNumberDelimiters + "+";
     // Minimum no of digits in an international phone no.
     var minDigitsInIPhoneNumber = 10;
*/

/*
     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++)
         {   
            // Check that current character isn't whitespace.
            var c = s.charAt(i);
            if (bag.indexOf(c) == -1) returnString += c;
         }
          return returnString;
       }*/

/* 
   function checkInternationalPhone(strPhone){
         s=stripCharsInBag(strPhone,validWorldPhoneChars);
         return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
    }
*/
    
	var Phone=document.forms[0].Phone
	
	if ((Phone.value==null)||(Phone.value=="") || isNaN(Phone.value)){
		alert("Please Enter Phone Number Without SPACES or PREFIXES")
		Phone.focus()
		return false
	}
	
	
/*
if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
*/
	  

     // Terms & Conditions accepted?
     if (!clickedOnTandC) {
        alert("Please click on the Terms & Conditions field below, read and then " +
              "agree\nbefore proceeding. Thank you.");
        return(false);
     }

    
 } else {
     alert("Please complete all REQUIRED fields before proceeding to Bookings Page!.");
     return(false);
 }
return true
}


