//Standard site functions
function fnChangeImage(Obj, Img){
	Obj.src = '../images/'+Img;
}

function fnSubmitForm(Obj1, IPValue){
		Obj1.mode.value = IPValue;
		Obj1.submit();
}

function fnSubmitItem(obj){
	var i
	for (i=0; i<document.all.item(obj).options.length; i++){
			document.all.item(obj).options[i].selected = true
	}
	
	return true;
}


function fnProfileSubmitForm(IPValue){
		document.frmProfile.mode.value = IPValue;
		document.frmProfile.submit();
}

function fnCheckKeyPress(Obj, Obj1, IPValue){
	if (Obj == 13){
		Obj1.mode.value = IPValue;
		Obj1.submit();
	}
}


function fnReturnRegistration(){
	if (window.top!=window.self) 
	{
		window.top.location="http://www.maia.com.sc/default.asp"
	}
	
	window.close();
}

function fnStatusChange(Obj){
	window.status = Obj
}

function fbreakout(obj){
	if (window.top!=window.self) 
	{
		window.top.location=obj
	}
}

function addCatItem(obj, obj1, obj2, obj3){
	var i
	
	for (i=0; i<document.all.item(obj1).options.length; i++){
		if (document.all.item(obj1).options[i].selected==true){
			addNewItem(obj, obj3, obj2, document.all.item(obj1).options[i].value, document.all.item(obj1).options[i].text)
		}
	}	
}

function addNewItem(obj, obj1, obj2, id, name){
	var i
	addOption = true
	for (i=0; i<document.all.item(obj2).options.length; i++){
		if(document.all.item(obj2).options[i].value == id){
			addOption = false
		}
	}
	
	if (addOption == true){
		document.all.item(obj2).options[document.all.item(obj2).options.length] = new Option(name, id)

		if (obj == 'event' || obj == 'categories'){
			if (document.all.item(obj2).options.length == 1){
				document.all.item(obj1).value = id
			}else{
				document.all.item(obj1).value = document.all.item(obj1).value +','+id
			}
		}
	}
}

function removeCatItem(obj, obj1, obj2){
	var i
	var oElements
	var CatID
	var SelCat
	for (i=0; i<document.all.item(obj2).options.length; i++){
		if (document.all.item(obj2).options[i].selected==true){
			CatID = document.all.item(obj2).options[i].value
			document.all.item(obj2).options.remove(i)
		}
	}
	
	if (obj == 'event' || obj == 'categories'){
		for (i=0; i<document.all.item(obj2).options.length; i++){
			document.all.item(obj2).options[i].selected = true
		}
		
		oElements = document.all.item(obj2).value.split(",");
		document.all.item(obj1).value = "";
		for (i=0;i<oElements.length;i++){
			if (oElements.length == 1){
				document.all.item(obj1).value = oElements[i]
			}else{
				document.all.item(obj1).value = document.all.item(obj1).value +','+oElements[i]
			}
		}
	}
	
	if (obj == 'request'){
		document.location.replace("default.asp?cid=7&rid="+CatID)
	}
}

function fnValidate(obj){
	if (document.getElementById('cboTitle').value == ""){
		alert("Please provide your title.");
		document.getElementById('cboTitle').focus();
		return false;
	}
	
	if (document.getElementById('txtFirstName').value == ""){
		alert("Please provide a first name.");
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if (document.getElementById('txtLastName').value == ""){
		alert("Please provide a last name.");
		document.getElementById('txtLastName').focus();
		return false;
	}
	
	if (document.getElementById('txtContactNo').value == ""){
		alert("Please provide a contact number.");
		document.getElementById('txtContactNo').focus();
		return false;
	}
	
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address.");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
}

function fnValidateRequest(obj){
	if (document.getElementById('txtFirstName').value == ""){
		alert("Please provide a first name");
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if (document.getElementById('txtLastName').value == ""){
		alert("Please provide a last name");
		document.getElementById('txtLastName').focus();
		return false;
	}
	
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
	
	if (document.getElementById('cboLocal').value == ""){
		alert("Please select your location");
		document.getElementById('cboLocal').focus();
		return false;
	}
	
	if (document.getElementById('cboProdSel').value == ""){
		alert("Please ensure that you have at least one product category you would be interested in.");
		document.getElementById('cboProdSel').focus();
		return false;
	}
}

function fnFPwdValidate(obj){
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}
}

function fnRegValidate(obj){
	if (document.getElementById('txtCompanyName').value == ""){
		alert("Please provide your company name");
		document.getElementById('txtCompanyName').focus();
		return false;
	}
	
	if (document.getElementById('txtContactPerson').value == ""){
		alert("Please provide a contact persons name");
		document.getElementById('txtContactPerson').focus();
		return false;
	}
	
	if (document.getElementById('txtContactNo').value == ""){
		alert("Please provide a contact persons number");
		document.getElementById('txtContactNo').focus();
		return false;
	}
	
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
}

function fnBookingValidate(obj){
	if (document.getElementById('txtFirstName').value == ""){
		alert("Please provide your first name");
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if (document.getElementById('txtSurname').value == ""){
		alert("Please provide your surname");
		document.getElementById('txtSurname').focus();
		return false;
	}
	
	var addr = document.getElementById('txtEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}
	
	if (document.getElementById('cboCountry').value == ""){
		alert("Please provide your country name.");
		document.getElementById('cboCountry').focus();
		return false;
	}
	
	if (document.getElementById('txtContact').value == ""){
		alert("Please provide your contact number");
		document.getElementById('txtContact').focus();
		return false;
	}
	
	if (document.getElementById('txtLanguage').value == ""){
		alert("Please provide your preferred language");
		document.getElementById('txtLanguage').focus();
		return false;
	}
	
	/*if (document.getElementById('txtCCNumber').value == ""){
		alert("Please provide a credit card number in order to validate this enquiry");
		document.getElementById('txtCCNumber').focus();
		return false;
	}
	
	if (document.getElementById('cboCCType').value == ""){
		alert("Please provide a credit card type in order to validate this enquiry");
		document.getElementById('cboCCType').focus();
		return false;
	}
	
	var cardNumber
	var cardType
	var isValid = false;
	var ccCheckRegExp = /[^\d ]/;
	
	cardNumber = document.all('txtCCNumber').value
	cardType = document.all('cboCCType').value.toLowerCase()
	
	isValid = !ccCheckRegExp.test(cardNumber);
	if (!isValid){
		alert("The card number you have entered seems to be invalid\r\nPlease ensure that you only insert numbers.");
		document.all('txtCCNumber').focus();
	}
	
	if (isValid)
	{
	var cardNumbersOnly = cardNumber.replace(/ /g,"");
	var cardNumberLength = cardNumbersOnly.length;
	var lengthIsValid = false;
	var prefixIsValid = false;
	var prefixRegExp;
	
	switch(cardType)
	{
	  case "mastercard":
		lengthIsValid = (cardNumberLength == 16);
		prefixRegExp = /^5[1-5]/;
		break;
	
	  case "visa":
		lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
		prefixRegExp = /^4/;
		break;
	
	  case "amex":
		lengthIsValid = (cardNumberLength == 15);
		prefixRegExp = /^3(4|7)/;
		break;
		
	  case "diners":
		lengthIsValid = (cardNumberLength == 14);
		prefixRegExp = /^3(00|01|02|03|04|05|6|8)/;
		break;
	
	  default:
		prefixRegExp = /^$/;
		alert("We do not accept the card type you have entered.");
	}
	
	prefixIsValid = prefixRegExp.test(cardNumbersOnly);
	if (!prefixIsValid){
		alert("The card number you have entered seems to be invalid.");
		document.all('txtCCNumber').focus();
	}
	isValid = prefixIsValid && lengthIsValid;
	}
	
	if (isValid)
	{
	var numberProduct;
	var numberProductDigitIndex;
	var checkSumTotal = 0;
	
	for (digitCounter = cardNumberLength - 1; 
	  digitCounter >= 0; 
	  digitCounter--)
	{
	  checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
	  digitCounter--;
	  numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
	  for (var productDigitCounter = 0;
		productDigitCounter < numberProduct.length; 
		productDigitCounter++)
	  {
		checkSumTotal += 
		  parseInt(numberProduct.charAt(productDigitCounter));
	  }
	}
	
	isValid = (checkSumTotal % 10 == 0);
	}
	
	if (!isValid){
		alert("The card number you have entered seems to be invalid.\r\nPlease ensure that you have captured the number of digits correctly.");
		document.all('txtCCNumber').focus();
	}
	
	return isValid;*/
	
	return true;
}

function fnAddfavourite(){
   if (document.all){
      window.external.AddFavorite
      ("http://www.maia.com.sc","MAIA Spa and Resort")
   }
}

function fnPreload(){ 
  var args = fnPreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function showStatus(sMsg) {
    window.status = sMsg ;
    return true ;
}


function fnChildPolicy(){
	window.open('/default.asp?cid=7','Children','width=650,height=442,scrollbars=0,resizable=1')
}

function fnDecemberPolicy(){
	window.open('/default.asp?cid=9','December','width=650,height=442,scrollbars=0,resizable=1')
}

function fnAirlines(){
	window.open('/default.asp?cid=14','December','width=650,height=442,scrollbars=0,resizable=1')
}

function fnPromotions(){
	window.open('/default.asp?cid=15','December','width=670,height=800,scrollbars=1,resizable=1')
}

function fnTerms(){
	window.open('/default.asp?cid=13','December','width=650,height=520,scrollbars=0,resizable=1')
}

function fnLoadDays(obj,obj1,obj2){
	var month
	var date

	while (document.all.item(obj1).options.length > 0){
		for (i=0; i<document.all.item(obj1).options.length; i++){
				document.all.item(obj1).options[i] = null;
		}
	}

	date = new Date();
	month = obj.substring(0,3).toLowerCase();
	day = date.getDate();
	
	if (month == "jan" || month == "mar" || month == "may" || month == "jul" || month == "aug" || month == "oct" || month == "dec"){
		for (i=1; i<=31; i++){
			if (i <= 9){
				text = "0"+i
			}else{
				text = i
			}
			id = i
			document.all.item(obj1).options[document.all.item(obj1).options.length] = new Option(text, id)
		}
	}else if (month == "apr" || month == "jun" || month == "sep" || month == "nov"){
		for (i=1; i<=30; i++){
			if (i <= 9){
				text = "0"+i
			}else{
				text = i
			}
			id = i
			document.all.item(obj1).options[document.all.item(obj1).options.length] = new Option(text, id)
		}
	}else{
		if (date.getYear()%4 == 0){
			for (i=1; i<=29; i++){
				if (i <= 9){
					text = "0"+i
				}else{
					text = i
				}
				id = i
				document.all.item(obj1).options[document.all.item(obj1).options.length] = new Option(text, id)
			}
		}else{
			for (i=1; i<=28; i++){
				if (i <= 9){
					text = "0"+i
				}else{
					text = i
				}
				id = i
				document.all.item(obj1).options[document.all.item(obj1).options.length] = new Option(text, id)
			}
		}
	}
	
	if (obj2 != ''){
		for (i=0; i<document.all.item(obj1).options.length; i++){
			if (document.all.item(obj1).options[i].value == document.all.item(obj2).value){
				document.all.item(obj1).options[i].selected = true;
				break;
			}
		}
	}
}

function fnLoadMonth(obj,obj1,obj2,obj3){
	var month
	var date

	for (i=0; i<document.all.item(obj1).options.length; i++){
		if (document.all.item(obj1).options[i].value.toLowerCase() == obj.toLowerCase()){
			document.all.item(obj1).options[i].selected = true;
			break;
		}
	}
	
	if (obj3 == 1){
		fnLoadDays(obj,obj2)
	}
}

function fnLoadCheckoutDay(obj, obj1){
	for (i=0; i<document.all.item(obj1).options.length; i++){
		if (document.all.item(obj1).options[i].value == obj){
			document.all.item(obj1).options[i].selected = true;
			break;
		}
	}
}

function fnLoadTotalDays(obj){
	if (document.all.item(obj).options.length == 0){
		for (i=1;i<=31;i++){
			if (i<=9){
				document.all.item(obj).options[document.all.item(obj).options.length] = new Option('0'+i, '0'+i)
			}else{
				document.all.item(obj).options[document.all.item(obj).options.length] = new Option(i, i)
			}
		}
	}
}