
function openCAL(field) {
    mywin = window.open("http://www.ticket-universe.com/includes/calendar.php?field="+field,"cal",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=212,height=192');
}
function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }
 
var win=null;

function NewWindow(mypage,myname,w,h,scroll,pos){

	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}

	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}

	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}


function isallwhite(strText)
{
    a = 0;
    cr="";
    var white=" ";
    while (a < (strText.length))
    {
        cr = strText.substring(a,a+1);
        if (white.indexOf(cr) == -1)
            return false;
        a++;
    }
    return true;
}

function DateValidation(field,type)
{
    strDay="";strMonth="";strDate="";strYear="";
    month=0;day=0;year=0;
    strDate=field.value;
    firstslash = 0;lastslash = 0;
    valid = true;
    if (isallwhite(field.value) == false)
    {
        firstslash = strDate.indexOf("/");
        lastslash = strDate.lastIndexOf("/");
        strMonth=strDate.substring(0,firstslash);
        strDay=strDate.substring(firstslash + 1,lastslash);
        strYear=strDate.substring(lastslash + 1,strDate.length);
        if (isNaN(month=parseInt(strMonth, 10)))
        {
            alert(field.value + " is not a valid date. Please use the format MM/DD/YYYY when entering a date. Please re-enter " +type+".");
            valid = false;
        }
        if ((isNaN(day=parseInt(strDay, 10))) && (valid == true))
        {
            alert(field.value + " is not a valid date. Please use the format MM/DD/YYYY when entering a date. Please re-enter " +type+".");
            valid = false;
        }
        if ((isNaN(year=parseInt(strYear,10))) && (valid == true))
        {
            alert(field.value + " is not a valid date. Please use the format MM/DD/YYYY when entering a date. Please re-enter " +type+".");
            valid = false;
        }
        if (((month < 1) || (month > 12) || (year < 1000) || (year > 9999)) && (valid == true))
        {
            alert(field.value + " is not a valid date. Please use the format MM/DD/YYYY when entering a date. Please re-enter " +type+".");
            valid = false;
        }
        if ((((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12))) && ((day < 1) || (day > 31)) && (valid == true))
        {
            alert(field.value + " is not a valid date. Please use the format MM/DD/YYYY when entering a date. Please re-enter " +type+".");
            valid = false;
        }
        if ((((month == 4) || (month == 6) || (month == 9) || (month == 11)) && ((day < 1) || (day > 30))) && (valid == true))
        {
            alert(field.value + " is not a valid date. Please use the format MM/DD/YYYY when entering a date. Please re-enter " + type +".");
            valid = false;
        }
        if ((month == 2) && (valid == true))
        {
            if(((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0)))
            {
                if((day < 1) || (day > 29))
                {
                    alert(field.value + " is not a valid date. Please use the format MM/DD/YYYY when entering a date. Please re-enter " + type +".");
                    valid = false;
                }
            }
            else
            {
                if((day < 1) || (day > 28))
                {
                    alert(field.value + " is not a valid date. Please use the format MM/DD/YYYY when entering a date. Please re-enter " + type +".");
                    valid = false;
                }
            }
        }
        if(valid == false)
        {
            field.focus();
            field.select();
        }
        else if (valid == true)
        {

            if(strMonth.length == 1)
                strMonth = "0" + strMonth;
            if(strDay.length == 1)
                strDay = "0" + strDay;
            field.value = strMonth + "/" + strDay + "/" + strYear;
        }
    }
    else
        field.value = "";
}



function popvars(){
	var query=window.location.search.substring(1);
	var vars=query.split("&");
	for (var i=0;i<vars.length;i++){
		var pair=vars[i].split("=");
		var feildname=pair[0];
		var feildvalue=pair[1];
		if (document.exceptions[feildname]){
			document.exceptions[feildname].value=decodehtml(feildvalue);
		}
	}
}

function decodehtml(string){
	string=string.replace(/%20/g," ");
	return string;
}

function validate(){
	
	var name;
	var argv=validate.arguments;
	var argc=argv.length;
	var x;
	var form="exceptions";
	for (var i=0; i< argc; i++){
		x=argv[i];
		if (document[form][x].value==''){
			switch (x){
				case 'email':
					 name='Email Address';
				break;
				case 'pax':
				  name='Number of Passengers';
				break;
				case 'custom_10depart_city':
					name='Departure City';
				break;
				case 'custom_11dest_city':
					name='Destination City';
				break;
				case 'custom_120depart_month':
					name='Departure Month';
				break;
				case 'custom_121depart_day':
					name='Departure Day';
				break;
				case 'custom_123depart_year':
					name='Departure Year';
				break;
				case 'custom_132return_month':
					name='Return Month';
				break;
				case 'custom_133return_day':
					name='Return Day';
				break;
				case 'custom_134return_year':
					name='Return Year';
				break;
				case "custom_58Group_Name":
					name="Group Name";
				break;
				case "custom_130return_from_city":
					name="Return from City";
				break;
				case "custom_131return_to_city":
					name="Return to City";
				break;
				
				default:
					name=x;
				break;
			}
			alert("Please fill in the "+name);
			return false;
		}
	}
	if (document.exceptions.first_name.value==''){
		alert("Please fill in the First Name field.");
		return false;
	}// check that the name field is valued
	
	if  (document.exceptions.last_name.value==''){
		alert("Please fill in the Last Name field.");
		return false;
	}
	if (document.exceptions.custom_60phone.value==''){
		alert("Please fill in your telephone number.");
		return false;
	}
	if (document.exceptions.email.value==''){
		alert("Please fill in your email address.");
		return false;
	} 
	if (!isValidEmail(document.exceptions.email.value)){
		alert("Your Email Address is Invalid.");
		return false;
	}
	if (document.exceptions.email.value!=document.exceptions.confirmemail.value){
		alert ("Your Email Addresses didn't match please confirm your email address again");
		return false;
	}
	
	document.exceptions.submit();
	
}

function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function getrefferal(){
	var query=window.location.search.substring(1);
	var vars=query.split("&");

	for (var i=0;i<vars.length;i++){
		var pair=vars[i].split("=");
		if (pair[0]=="referrerID"){
			document.form1.referrerID.value=pair[1];
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function InboundDest( ) {
	document.form1.txtOutboundDepCity.value = document.form1.txtOutboundDepCity.value.toUpperCase()
	document.form1.txtInboundDestCity.value = document.form1.txtOutboundDepCity.value
}

function InboundDep() {
	document.form1.txtOutboundDestCity.value = document.form1.txtOutboundDestCity.value.toUpperCase()
	document.form1.txtInboundDepCity.value = document.form1.txtOutboundDestCity.value
}

function checkpassengers(){
	if (document.form1.infantno.value > document.form1.adultno.value ){
		alert('There cannot be more than 1 INFANT per ADULT');
		return;
	}
	if (document.form1.txtOutboundDepCity.value ==''){
		alert('DEPARTURE for departure Itinerary is required')
		return;
	}
	if (document.form1.txtOutboundDestCity.value ==''){
		alert('DESTINATION for departure Itinerary is required')
		return;
	}
	document.form1.submit();
}
