// JavaScript Document
function MM_validateForm() { //v4.0
  if (document.getElementById){
    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=document.getElementById(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.\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); return false; }
    document.MM_returnValue = (errors == '');
/*
	if(errors == "")
	{
		return true;
	}else{
		return false;
	}
*/
} }

function checkTerms(ID){
	var tmp = document.getElementById(ID);
	if (tmp.checked==false){
		alert("You must agree to the terms and conditions first");
		return false;
	}
}

function confirmSubmit(message)
{
var agree=confirm(message);
if (agree)
	return true ;
else
	return false ;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function confirmDelete(Item){
	var deleteIt = confirm("Are you sure you want to delete " + Item + "?");
	return deleteIt;
}

function confirmPublish(){
	var deleteIt = confirm("Are you sure you want to publish this poll? Once published you cannot modify it!");
	return deleteIt;
}

function showhide(ID)
{
	if (document.getElementById(ID).style.display == ''){
		document.getElementById(ID).style.display = 'none';
	}else{
		document.getElementById(ID).style.display = '';
	}
}

function confirmSubmit(message)
{
var agree=confirm(message);
if (agree)
	return true ;
else
	return false ;
}



/* Hotels and Hospitality */

function addArrayValue(value){
	var seats = document.getElementById('seats');
	var seatNo = document.getElementById(value);
	
	if(seats.value.match(value)==null){
		seats.value = seats.value + value + ",";
		seatNo.style.color='blue';
	}else{
		removeArrayValue(value);
	}
}


function removeArrayValue(value){
	var seats = document.getElementById('seats');
	var seatNo = document.getElementById(value);
	
	var tmp = explode(",",seats.value);
	seats.value = "";
	
	for (var i = 0; i < tmp.length; i++){
		if (tmp[i] != value && tmp[i] != 0 && seats.value.match(value)==null){
			seats.value = seats.value + tmp[i] + ",";
		}
	} 
	
	seatNo.style.color='';

}




function explode( delimiter, string ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: kenneth
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
 
    var emptyArray = { 0: '' };
 
    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
 
    return string.toString().split ( delimiter.toString() );
}

function CalculateSpaces(people, ID, type, selected){
	var spaces = 0;
	if (selected == null){
		selected = 0;
	 }
	
	if (people % 2){
		people++;
	}
	
	spaces = (people) / 2;
	
	var div = document.getElementById('divparking' + type + '_' + ID);
	
	var temp = '<select name="parking' + type + '_' + ID + '" class="parking">';
	
	for (var i = 0; i <= spaces; i++){
		if (i == selected) {
			temp += '<option value="' + i + '" selected="selected">' + i + '</option>';
		} else {
			temp += '<option value="' + i + '">' + i + '</option>';
		}
	}
	
	temp += '</select>';

	if (temp != ""){
		div.innerHTML = temp;
	}

}



function printSelection(node){

  var content=node.innerHTML
  var pwin=window.open('','print_content','width=620,height=780,scrollbars=1');

  pwin.document.open();
  pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
  pwin.document.close();
 
//  setTimeout(function(){pwin.close();},8000);

}
