// JavaScript Document
function AddSureCharges(cardtype){
	var csur=0; 	var ffare=0; 
	if(cardtype!=0){
		if(cardtype=="Solo" || cardtype=="Switch" || cardtype=="DebitCard" || cardtype=="VisaElectron" || cardtype=="Maestro" || cardtype=="Delta"){
			jQuery("#surcharge").val('0.00');
			csur = "0.00";
		} else if(cardtype=="AmEx"){
			ffare = parseFloat(jQuery("#flightfare").val());
			csur=parseFloat(ffare) * 0.05;
			csur=Math.round(csur*Math.pow(10,2))/Math.pow(10,2);
			jQuery("#surcharge").val(csur.toFixed(2));
			//add 5%
		} else if(cardtype=="Visa"){
			ffare = parseFloat(jQuery("#flightfare").val());
			csur=parseFloat(ffare) * 0.03;
			csur=Math.round(csur*Math.pow(10,2))/Math.pow(10,2);
			jQuery("#surcharge").val(csur.toFixed(2));
			// add 3%
		} else if(cardtype=="MasterCard"){
			ffare = parseFloat(jQuery("#flightfare").val());
			csur=parseFloat(ffare) * 0.03;
			csur=Math.round(csur*Math.pow(10,2))/Math.pow(10,2);
			jQuery("#surcharge").val(csur.toFixed(2));
			//add 3%
		} else {
			ffare = parseFloat(jQuery("#flightfare").val());
			csur=parseFloat(ffare) * 0.02;
			csur=Math.round(csur*Math.pow(10,2))/Math.pow(10,2);
			jQuery("#surcharge").val(csur.toFixed(2));
			//add 2%
		}
	}
	ffare = parseFloat(jQuery("#flightfare").val());
	var netTotal = parseFloat(ffare)+parseFloat(csur)+2.50+1.50;
	jQuery("#totalfare").val(netTotal.toFixed(2));
}
function doBook(){
	if(jQuery("#LPhone").val()==''){
		if(jQuery("#MPhone").val()==''){
			alert('Please Enter your contact number');
			window.scroll(0,300);
			jQuery("#LPhone").focus();
			return false;
		}
	}
	if(jQuery("#forms_form").valid()){
		document.getElementById("forms_form").submit();
	}
}

function applyform(e){
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13){
		  doSearch();
	 }else{
          return true;
	 }
}
function domouseover(myid){
	jQuery(myid).css({color:'#fff',background:'#317398'});	
}
function domouseout(myid){
	jQuery(myid).css({color:'#333',background:'#fff'});	
}
function domouseover_state(myid){
	jQuery(myid).css({color:'#333',background:'#fff'});	
}
function domouseout_state(myid){
	jQuery(myid).css({color:'#333',background:'#EEFAFB'});	
}
function setCookie(sName, sValue){
  date = new Date();
  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT;";
  //GetCookie(sName,"Cookie Set: " + sName + "=" + sValue); //For debug output purposes.
}

function doScroll(usekey){
	
}
function getcookietime(sName, msg){
  var aCookie = document.cookie.split("; ");
  var out = "Cookie string: " + aCookie; //For debug output purposes.
  for (var i=0; i < aCookie.length; i++){
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) {
		return unescape(aCrumb[1]);
    }
  }
  return null;
}
 
function DelCookie(sName){
  document.cookie = sName + "=; expires=Fri, 21 Dec 1976 04:31:24 GMT;";
}

function setcookietime(sName,sValue,duration){
  date = new Date();
  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT;";
}
function DisableReturnFun(){
	if (document.getElementById("ReturnJourney").checked==true){
		jQuery("#EndDate").attr("disabled","");
		jQuery("#sw_EndDate_picker").css("display","");
	}
	if (document.getElementById("OneWay").checked==true){
		jQuery("#EndDate").attr("disabled","disabled");
		jQuery("#EndDate").val('');
		jQuery("#sw_EndDate_picker").css("display","none");
	}
}
function checkDate(){
	var depary=document.getElementById("serverDate").value.split('-');
	var depdt=depary[1] + '/' + depary[0] + '/' + depary[2];
	var idt=new Date(depdt);
	idt.setDate(idt.getDate() + 1);	
	var enddt=document.getElementById("StartDate").value.split('-');
	var enddt=enddt[1] + '/' + enddt[0] + '/' + enddt[2];
	var tdt=new Date(enddt);
	if (idt>=tdt){
		alert('For within 48 hour Departure, Please call our 24 hour Sale Support Team on the above Number');
		return false;
	}
	return true;
}
function changedate(){
	var depary=document.getElementById("StartDate").value.split('-');
	var depdt=depary[1] + '/' + depary[0] + '/' + depary[2];
	var idt=new Date(depdt);
	var offset = (-(idt.getTimezoneOffset()/60));
	var off = -7 - offset;
	idt.setHours(idt.getHours()+off);
	idt.setDate(idt.getDate() + parseInt(11,10));
	var year = idt.getFullYear();
	var month = idt.getMonth()+1;
	var date = idt.getDate();
	var monthString=0;	var dateString =0;
	if (month.toString().length<2){
		monthString = "0" + month;
	} else {
		monthString = month;
	}
	if(date.toString().length < 2){
		dateString = "0" + date;
	} else {
		dateString = date;
	}
	document.getElementById("EndDate").value=dateString+ '-' + monthString + '-' + year;
}

function doSearch(){
	if(checkDate()){
		if(jQuery("#DestinationTo_").val()=='' || document.getElementById("DestinationTo_").value==''){
			alert('Destination must be filled');
			jQuery("#DestinationTo_").focus();
			return;
		}
		if(jQuery("#DestinationTo").val()=='' || document.getElementById("DestinationTo").value==''){
			alert('Destination not match!');
			jQuery("#DestinationTo_").focus();
			return;
		}
		jQuery("#Java_sDate").html(document.getElementById("StartDate").value);
		jQuery("#Java_eDate").html(document.getElementById("EndDate").value);
		jQuery("#Java_dfrom").html(document.getElementById("DestinationFrom").value);
		jQuery("#Java_dto").html(document.getElementById("DestinationTo_").value);
		jQuery("#showarea_0").show();
		jQuery("#hidearea_0").hide();
		jQuery("#hidearea_1").hide();
		jQuery("#hidearea_2").hide();
		document.getElementById("frmlist").submit();
	}
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

//Valided the Form
function ValidForm(frmName){
	//Search for all Input Area with isreq=1
		jQuery.validator.addMethod("field", function(value, element) {
			return value != 0;
		}, "&nbsp;");
		jQuery("#form1").validate({
			errorPlacement: function(error, element) { 
				error.appendTo(element.next() ); 
			},			
			invalidHandler: function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? 'You missed 1 field. It has been highlighted below'
						: 'You missed ' + errors + ' fields.  They have been highlighted below';					
						jQuery("div.error span.msg").html(message);
					alert(message);
				} else {
					jQuery("div.error").hide();
				}
			},
			onkeyup: false,
			success: function(label) { 
				label.html("&nbsp;").toggleClass("valid"); 
	        },debug:true
		});
	if(jQuery("#form1").valid()){
		document.getElementById("form1").submit();
	}
}
function trim(strText) {
    // this will get rid of leading spaces
	if(strText.length == 0) return
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);	

   return strText;
}
function doBooking(myID){
	var TTable = document.getElementById('Row_'+myID);
	var xtr='';
	for(var i=0;i<(TTable.rows.length)-1;i++){
		if(i==1){
			xtr += '<tr class="heading">'+TTable.rows[i].innerHTML+'</tr>';
		} else {
			xtr += '<tr>'+TTable.rows[i].innerHTML+'</tr>';
		}
	}
	jQuery('#selItem').val(xtr);
	document.getElementById("frmMain").submit();
}
function checkemail(emailid){
if (document.layers||document.getElementById||document.all)
var testresults
var invalidaddress=new Array()
invalidaddress[0]="zdnetmail";
//extend or shorten this list if neccessary
    var invalidcheck=0;
    var str=document.getElementById(emailid).value
    var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
        if (filter.test(str)){
            var tempstring=str.split("@")
            tempstring=tempstring[1].split(".");
            for (i=0;i<invalidaddress.length;i++){
                if (tempstring[0]==invalidaddress[i])
                    invalidcheck=1;
                }
                if (invalidcheck!=1){
                    return ""
                } else {
                    return "* Please enter a valid <u>Official</u> <b>Email</b> address.<br />";
                }
        } else {
           return "* Please enter a valid <b>Email</b> address.<br />";
        }
}

function checkUKTelephone(telephoneNumber) {
  // Convert into a string and check that we were provided with something
  if(telephoneNumber=="012345678" || telephoneNumber=="0123456789" || telephoneNumber=="01234567890" || telephoneNumber=="01111111111"){
	  telNumberErrorNo = 5;
	  return false
  }
  if(telephoneNumber=="0222222222" || telephoneNumber=="02222222222" || telephoneNumber=="01212121212" || telephoneNumber=="0333333333" || telephoneNumber=="03333333333"){
	  telNumberErrorNo = 5;
	  return false
  }
  if(telephoneNumber=="04444444444" || telephoneNumber=="04444444444" || telephoneNumber=="05555555555" || telephoneNumber=="055555555555"){
	  telNumberErrorNo = 5;
	  return false
  }
  if(telephoneNumber=="06666666666" || telephoneNumber=="066666666666" || telephoneNumber=="07777777777" || telephoneNumber=="07777777777"){
	  telNumberErrorNo = 5;
	  return false
  }
  if(telephoneNumber=="0888888888" || telephoneNumber=="088888888888" || telephoneNumber=="09999999999" || telephoneNumber=="099999999999"){
	  telNumberErrorNo = 5;
	  return false
  }
  var telnum = telephoneNumber + " ";
  if (telnum.length == 1)  {
     telNumberErrorNo = 1;
     return false
  }
  telnum.length = telnum.length - 1;
  
  // Don't allow country codes to be included (assumes a leading "+")
  var exp = /^(\+)[\s]*(.*)$/;
  if (exp.test(telnum) == true) {
     telNumberErrorNo = 2;
     return false;
  }
  
  // Remove spaces from the telephone number to help validation
  while (telnum.indexOf(" ")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
  }
  
  // Remove hyphens from the telephone number to help validation
  while (telnum.indexOf("-")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
  }  
  
  // Now check that all the characters are digits
  exp = /^[0-9]{10,12}$/;
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 3;
     return false;
  }
  
  // Now check that the first digit is 0
  exp = /^0[0-9]{9,10}$/;
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 4;
     return false;
  }
	
	// Disallow numbers allocated for dramas.
	 
  // Array holds the regular expressions for the drama telephone numbers
  var tnexp = new Array ();
	tnexp.push (/^(0113|0114|0115|0116|0117|0118|0121|0131|0141|0151|0161)(4960)[0-9]{3}$/);
	tnexp.push (/^02079460[0-9]{3}$/);
	tnexp.push (/^01914980[0-9]{3}$/);
	tnexp.push (/^02890180[0-9]{3}$/);
	tnexp.push (/^02920180[0-9]{3}$/);
	tnexp.push (/^01632960[0-9]{3}$/);
	tnexp.push (/^07700900[0-9]{3}$/);
	tnexp.push (/^08081570[0-9]{3}$/);
	tnexp.push (/^09098790[0-9]{3}$/);
	tnexp.push (/^03069990[0-9]{3}$/);
	
	for (var i=0; i<tnexp.length; i++) {
    if ( tnexp[i].test(telnum) ) {
      telNumberErrorNo = 5;
      return false;
    }
	}
  
  // Finally check that the telephone number is appropriate.
  exp = (/^(01|02|03|05|070|071|072|073|074|075|07624|077|078|079)[0-9]+$/);
	if (exp.test(telnum) != true) {
     telNumberErrorNo = 5;
     return false;
  }
  
  // Telephone number seems to be valid - return the stripped telehone number  
  return telnum;
}
var telNumberErrorNo = 0;
var telNumberErrors = new Array ();
telNumberErrors[0] = "Valid UK telephone number";
telNumberErrors[1] = "Telephone number not provided";
telNumberErrors[2] = "UK telephone number without the country code, please";
telNumberErrors[3] = "UK telephone numbers should contain 10 or 11 digits";
telNumberErrors[4] = "The telephone number should start with a 0";
telNumberErrors[5] = "The telephone number is either invalid or inappropriate";
