


//****begin country POPup Div. by Otto 17/01/2012 *****//

//is this line is not commented it will didable the selectCOUNTRY /MARKETarea popup div;
// try{  
// Set_Cookie('CountryAreaPopup', 'true', '', '/', '', ''); 
// }
//catch (err){}
    
function SetCountryAndCurrency(sCountry, sCurency) {

    $("SetCurrencyHeader").setValue(sCurency);
    $("CountryOrigin").setValue(sCountry);
	ContinueMarketarea();
}

function ContinueMarketarea() {
    $("CountryMarketAreaPopup").hide();
    //SetCountryAndCurrency();
    ChangeOrigin();
    remeberSettings(document.getElementById("setDefault_checkbox"));
}
function remeberSettings(sett) {
    if (sett.checked) {
        Set_Cookie('CountryAreaPopup', 'false', '', '/', '', '');
        //if (Get_Cookie('CountryAreaPopup')) alert('CountryAreaPopup='+Get_Cookie('CountryAreaPopup'));
    }
    else {
        Delete_Cookie('CountryAreaPopup', '/', '');
        //(Get_Cookie('CountryAreaPopup')) ? alert(Get_Cookie('CountryAreaPopup')) :
    }
   
}
//* modified function(s)  GetIP() called by all pages onLoad event
//****end country POPup Div.  *****//



 function submitmailingList(){
    $("Newsletter").submit();
  }

 function clearMe(formfield){
  if (formfield.defaultValue==formfield.value){
   formfield.value = ""}

  }
 function returnMe(formfield){
   if (formfield.value==""){
   formfield.value = formfield.defaultValue}
  }

var DateFrom = "";
var DateTo = "";
var bookingID = 0;


    function openEnquire(){
        emailwindow=dhtmlmodal.open('Project', 'iframe', '/modalfiles/enquiry.aspx?iD='+CruiseID + '&O=' + EmailViewOffer, '', 'width=450px,height=450px,center=1,resize=0,scrolling=0')
    }

	function openMailingList(){
        emailwindow=dhtmlmodal.open('Project', 'iframe', '/modalfiles/enquiry.aspx?iD='+CruiseID + '&O=' + EmailViewOffer, '', 'width=450px,height=450px,center=1,resize=0,scrolling=0')
    }
function loadCalandersRQ () {
	Calendar.setup({
            inputField: "DateFromRQ",
            ifFormat: "%d/%m/%Y",
            button: "calanderDateFromRQ"
        });
    Calendar.setup({
            inputField: "DateToRQ",
            ifFormat: "%d/%m/%Y",
            button: "calanderDateToRQ"
        });
}


   function GetSourceRQ() {
    $("whereRQ").update("");
        ajaxOptions = {
            method: "post",
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateSourceLinesRQ(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the Destination Feedback.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("/AjaxCalls/GetSource.aspx", ajaxOptions);
    }
    function generateSourceLinesRQ(lineData){
        lineData.each(function(line){
            generateSourceLineRQ(line);
        });
    }
    function generateSourceLineRQ(line){  
        var opt1 = new Element("option", {"value":line.Source}).update(line.Source);
        $("whereRQ").insert(opt1);
    }




function Searchforme(){
error = "";
if(validateRequestFormA()){
        
        DateFrom = $("DateFromRQ").getValue();
        DateTo = $("DateToRQ").getValue();

        $("Request_1").hide();
        $("Request_2").show();
        } else {
         alert(error);
        };
}

    function ViewThumb(ID){
        $("DestImage").src = ID;
    }

    function ViewYachtThumb(ID){
        $("YachtImage").src = ID;
    }
    function ViewCountryThumb(ID){
        $("CountryImage").src = ID;
    }
    
function Searchforme2(){
error = "";
if(validateRequestFormB()){
        
        DateFrom = $("DateFrom").getValue();
        DateTo = $("DateTo").getValue();

        $("Request_1a").hide();
        $("Request_2a").show();
        } else {
         alert(error);
        };
}

function LoadDatesTop(){
        Calendar.setup({
            inputField: "DateFromRQ",
            ifFormat: "%d/%m/%Y",
            button: "calanderDateFromRQ"
        });

        Calendar.setup({
            inputField: "DateToRQ",
            ifFormat: "%d/%m/%Y",
            button: "calanderDateToRQ"
        });
}

function SendMessage (from, to, cc, bcc, subject, message, attachments, path){
    var Email = "";
    Email += "&from=" + from;
    Email += "&to=" + to;
    Email += "&CC=" + cc;
    Email += "&BCC=" + bcc;
    Email += "&subject=" + subject;
    Email += "&message=" + message;
    Email += "&attachments=" + attachments;
    Email += "&attachmentsPath=" + path;
    
    
    ajaxOptions = {
        method: "post",
        parameters: Email,
        onSuccess: function(transport){
            //alert("The email to "+to+", was sent");
        }.bind(this),
        onFailure: function(){
            alert("There was a problem sending the email to "+to+", please check your email address");

        }.bind(this),
        onComplete: function(){
        }.bind(this)
    };
    new Ajax.Request("AjaxCalls/Email.aspx", ajaxOptions);
    

}

function SendName(){
        error = "";
        if(validateEnquireForm()){
            var data = "";
            var message = "";
            var customerString = "";
            var password = "";
            
            data = "";
            data += "&FullName=" + $("fullname").getValue();
            data += "&Type=" + $("YachtType").getValue();
            data += "&Email=" + $("Email").getValue();
            data += "&Tel=" + $("DayPhone").getValue();
            data += "&Cabins=" + $("cabins").getValue();
            data += "&Size=" + $("size").getValue();
            data += "&Area="  + $("area").getValue();
            data += "&DateFrom=" + $("DateFrom").getValue();
            data += "&DateTo=" + $("DateTo").getValue();
            data += "&Town=" + $("town").getValue();
            data += "&Hear=" + $("where").getValue();
            data += "&Comments=" + $("comments").getValue();           
            data += "&Currency=" + $("currency").getValue();
            data += "&Offer=" + $("offer").getValue();
            
            
            //mailViewPrice = data.FullPrice;
            //EmailViewOffer = data.OfferPrice;
            data += "&Country=" + MyCountryCode;
            data += "&CharterID=" + "";
            data += "&UserID=" + userID;
            data += "&DaysRequired=" + "";
            
            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                    var data = transport.responseText.evalJSON();
                      password = data.Password;
                    
                      customerString += "<p>Dear "+ $("fullname").getValue() ;
                      customerString += "<br />Many thanks for contacting us through our website. We will check the availability now and get back to you as soon as possible. Please note that it can sometimes take a little time to receive a response from the operators so please bear with us.";
                      customerString += "<br />For all future enquiries and bookings you may make you can save having to complete all your details again by logging in with this email address and the password " + password + ". Should you wish to change the password to one you find easier to remember you can do so by logging in at www.latesail.com/login.asp and editing your details.";
                      customerString += "<br />Should you wish to speak to a member of our sales team you can contact them on 08450 60 50 50. Please note our opening times are Monday to Friday, 9 to 5.30.";
                      customerString += "<br />Regards";
                      customerString += "<br />The LateSail team</p>";
                   
                      message += "<p><strong>Below is the response from a LATESAIL Enquiry</strong><br />";
                      message += "submitted by "  + $("fullname").getValue() + "</p>";
                  
                        message += "<p>FullName " + $("fullname").getValue() + "</p>";
                        message += "<p>Email " + $("Email").getValue() + "</p>";
                        message += "<p>Tel " + $("DayPhone").getValue() + "</p>";
                        message += "<p>Cabins " + $("cabins").getValue() + "</p>";
                        message += "<p>Size " + $("size").getValue() + "</p>";
                        message += "<p>Area "  + $("area").getValue() + "</p>";
                        message += "<p>DateFrom " + $("DateFrom").getValue() + "</p>";
                        message += "<p>DateTo " + $("DateTo").getValue() + "</p>";
                        message += "<p>Town " + $("town").getValue() + "</p>";
                        message += "<p>Hear " + $("where").getValue() + "</p>";
                        message += "<p>Comments " + $("comments").getValue() + "</p>";           
                        message += "<p>Currency " + $("currency").getValue() + "</p>";
                        message += "<p>Offer " + $("offer").getValue() + "</p>";
                  
                             
                        //send email to sales
                            SendMessage ($("Email").getValue(), "info@latesail.co.uk", "", "", "LateSail name your price enquiry", message, "", "")
  	                    //send email to customer
  	                        SendMessage ("info@latesail.co.uk", $("Email").getValue(), "", "", "Your LateSail enquiry", customerString, "", "")


                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the request");
                }.bind(this),
                onComplete: function(){
                    window.location = "/namecomplete.aspx"
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EnquirySaveNew.aspx", ajaxOptions);          
        }else{
            alert(error);
            
        }
    }
	
	function SendName2(){
        error = "";
        if(validateEnquireForm()){
            var data = "";
            var message = "";
            var customerString = "";
            var password = "";
            
            data = "";
            data += "&FullName=" + $("fullname").getValue();
            data += "&Type=" + $("YachtType").getValue();
            data += "&Email=" + $("Email").getValue();
            data += "&Tel=" + $("DayPhone").getValue();
            data += "&Cabins=" + $("cabins").getValue();
            data += "&Size=" + $("size").getValue();
            data += "&Area="  + $("area").getValue();
            data += "&DateFrom=" + $("DateFrom").getValue();
            data += "&DateTo=" + $("DateTo").getValue();
            data += "&Town=" + $("town").getValue();
            data += "&Hear=" + $("where").getValue();
            data += "&Comments=" + $("comments").getValue();           
            
            
            
            
            //mailViewPrice = data.FullPrice;
            //EmailViewOffer = data.OfferPrice;
            data += "&Country=" + MyCountryCode;
            data += "&CharterID=" + "";
            data += "&UserID=" + userID;
            data += "&DaysRequired=" + "";
            
            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                    var data = transport.responseText.evalJSON();
                      password = data.Password;
                    
                      customerString += "<p>Dear "+ $("fullname").getValue() ;
                      customerString += "<br />Many thanks for contacting us through our website. We will check the availability now and get back to you as soon as possible. Please note that it can sometimes take a little time to receive a response from the operators so please bear with us.";
                      customerString += "<br />For all future enquiries and bookings you may make you can save having to complete all your details again by logging in with this email address and the password " + password + ". Should you wish to change the password to one you find easier to remember you can do so by logging in at www.latesail.com/login.asp and editing your details.";
                      customerString += "<br />Should you wish to speak to a member of our sales team you can contact them on 08450 60 50 50. Please note our opening times are Monday to Friday, 9 to 5.30.";
                      customerString += "<br />Regards";
                      customerString += "<br />The LateSail team</p>";
                   
                      message += "<p><strong>Below is the response from a LATESAIL Enquiry</strong><br />";
                      message += "submitted by "  + $("fullname").getValue() + "</p>";
                  
                        message += "<p>FullName " + $("fullname").getValue() + "</p>";
                        message += "<p>Email " + $("Email").getValue() + "</p>";
                        message += "<p>Tel " + $("DayPhone").getValue() + "</p>";
                        message += "<p>Cabins " + $("cabins").getValue() + "</p>";
                        message += "<p>Size " + $("size").getValue() + "</p>";
                        message += "<p>Area "  + $("area").getValue() + "</p>";
                        message += "<p>DateFrom " + $("DateFrom").getValue() + "</p>";
                        message += "<p>DateTo " + $("DateTo").getValue() + "</p>";
                        message += "<p>Town " + $("town").getValue() + "</p>";
                        message += "<p>Hear " + $("where").getValue() + "</p>";
                        message += "<p>Comments " + $("comments").getValue() + "</p>";           
                        
                        
                  
                             
                        //send email to sales
                            SendMessage ($("Email").getValue(), "info@latesail.co.uk", "", "", "LateSail send me a quote enquiry", message, "", "")
  	                    //send email to customer
  	                        SendMessage ("info@latesail.co.uk", $("Email").getValue(), "", "", "Your LateSail enquiry", customerString, "", "")
							//SendMessage ("info@latesail.co.uk", "rohan@bagshots.com", "", "", "Your LateSail enquiry", customerString, "", "")

                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the request");
                }.bind(this),
                onComplete: function(){
                    window.location = "/namecomplete.aspx"
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EnquirySaveNew.aspx", ajaxOptions);          
        }else{
            alert(error);
            
        }
    }

function InviteCrew(){
		var Emails = new Array();
        Emails = $("invite-list").getValue().split(",")


  for (i=0; i < Emails.length; i++) {

            var data = "";
            var message = "";
            var EmailLink = "http://www.latesail.com/CrewInputDetails.asp\?id\=" + bookingID + "\&e\=" + userID;
            
            //alert(EmailLink)
            
		    message += "<html>"
		    message += "<head>"
		    message += "<style>"
		    message += "body{font-size:12px;text-align:left;font-family:Verdana,Arial,Helvetica,sans-serif;}"
		    message += "h1{font-size:16px;margin:0px 0px 10px 0px;}"
		    message += "p{margin:0px 0px 10px 0px;font-weight:normal;}"
		    message += ".disclaimer{font-size:10px;}"
		    message += "</style>"
		    message += "</head>"
		    message += "<body>"
		    message += "<h1>Invitation to join " + InvoiceName + "\'s Crew</h1>"
		    message += "<p><strong>" +InvoiceName+ " has invited you to join their crew.</strong>"
		    message += "<p><a href=\"" + EmailLink + "\" title=\"Input your details\">Please click this link to input your details</a><p>"
		    message += "<p class=\"disclaimer\"><em>This email has been sent to you via <a href=\"http://www.latesail.com\" title=\"LateSail.com - Worldwide Discounted Yacht Charters\">LateSail.com</a> at " +InvoiceName+ "'s request.</em></p>"
		    message += "</body>"
		    message += "</html>"
		    
		   // alert(message)
                     
            //send email to customer
  	        SendMessage ("info@latesail.co.uk", Emails[i], "", "", "Invitation to join charter crew", escape(message), "", "")
            
           } 
           alert("An invitation has been sent to the following email addresses : " + $("invite-list").getValue()) 
    }
    

function SendToLatesail(){
            var data = "";
            var message = "";
            var EmailLink = "http://www.latesail.com/CrewInputDetails.asp\?id\=" + bookingID + "\&e\=" + userID;
            
            
            
            data = "";
            data += "&BookingID=" + bookingID;           
            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                    var data = transport.responseText.evalJSON();

                    //alert(EmailLink)
                                
 

                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the request");
                }.bind(this),
                onComplete: function(){
                    
                
                
                
                
                
                
		                        message += "<html>"
		                        message += "<head>"
		                        message += "<style>"
		                        message += "body{font-size:12px;text-align:left;font-family:Verdana,Arial,Helvetica,sans-serif;}"
		                        message += "h1{font-size:16px;margin:0px 0px 10px 0px;}"
		                        message += "p{margin:0px 0px 10px 0px;font-weight:normal;}"
		                        message += ".disclaimer{font-size:10px;}"
		                        message += "</style>"
		                        message += "</head>"
		                        message += "<body>"
		                        message += "<h1>Attached is the crew list and certificates submitted for booking " + bookingID + "</h1>"
		                        message += "</body>"
		                        message += "</html>"
                    		    
                    		    
                    		    alert("Your crew list has been sent to Latesail") 
                    		    
		                       // alert(message)
                                //send email to customer
  	                           SendMessage ("info@latesail.co.uk", "admin@latesail.co.uk", "", "", "Completed Crew List for Booking "+bookingID, escape(message), "\\CrewLists\\ls"+bookingID+".txt,\\CrewLists\\"+bookingID+".txt"+BookingCerts, "")
                                               
                        
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/SaveCrewListFile.aspx", ajaxOptions);       
            
            
            
            
    }



function SendEnquire(){
        error = "";
        if(validateEnquireForm()){
            var data = "";
            var message = "";
            var customerString = "";
            var operatorString = "";
            var password = "";
            var operatorEmail = "";
            var yachtInfo = "";
            
            var MyDate = "";
            var MyName = "";
            var MyDays = "";
            var MyEmail = "";
            var MyPhone = "";
            var MyTown = "";
            var MyHear = "";
            var MyComments = "";
            
            if ($("fullname").getValue() == "Name*") {MyName = ""} else {MyName = $("fullname").getValue()}
            if ($("Email").getValue() == "Email Address*") {MyEmail = ""} else {MyEmail = $("Email").getValue()}
            if ($("DayPhone").getValue() == "Day Time Phone Number*") {MyPhone = ""} else {MyPhone = $("DayPhone").getValue()}
            if ($("DateFrom").getValue() == "Start Date*") {MyDate = ""} else {MyDate = $("DateFrom").getValue()}
            if ($("town").getValue() == "Home Town*") {MyTown = ""} else {MyTown = $("town").getValue()}
            if ($("where").getValue() == "Where did you hear about LateSail?") {MyHear = ""} else {MyHear = $("where").getValue()}
            if ($("comments").getValue() == "Comments") {MyComments = ""} else {MyComments = escape($("comments").getValue())}
            
            if ($("NoDays").getValue() == "Number of Days Required*") {MyDays = ""} else {MyDays = $("NoDays").getValue()}
            
            
            
            
            data = "";
            data += "&FullName=" + MyName;
            data += "&Type=" + ""; 
            data += "&Email=" + MyEmail;
            data += "&Tel=" + MyPhone;
            data += "&Size=" + "";
            data += "&Cabins=" + "";
            data += "&Area="  + "";
            data += "&DateFrom=" + MyDate;
            data += "&DateTo=" + "";
            data += "&Town=" + MyTown;
            data += "&Hear=" + MyHear;
            data += "&Comments=" + MyComments;           
            data += "&Currency=" + "1";
            data += "&Offer=" + EmailViewOffer;            
            //mailViewPrice = data.FullPrice;
            //EmailViewOffer = data.OfferPrice;
            data += "&Country=" + MyCountryCode;
            data += "&CharterID=" + CruiseID;
            data += "&UserID=" + userID;
            data += "&DaysRequired=" + MyDays;
            
            
            
          message += "<p><strong>Below is the response from a LATESAIL Enquiry</strong><br />";
          message += "submitted by "  + MyName + "<p>";
      
          message += "<p>Start Date "  + $("DateFrom").getValue() + "<p>";
          message += "<p>Name "   + MyName + "<p>";
          message += "<p>Email "  + MyEmail + "<p>";
          message += "<p>Phone "  + MyPhone + "<p>";
          message += "<p>Town "  + MyTown + "<p>";
          message += "<p>Hear "  + MyHear + "<p>";
          message += "<p>Comments "  + MyComments + "<p>";
          message += "<p>Charter "  + CruiseID + "<p>";
          message += "<p>Viewed Full Price "  + EmailViewPrice + "<p>";
          message += "<p>Viewed Offer Price "  + EmailViewOffer + "<p>";
          message += "<p>Currency "  + MyCurrency + "<p>";
          message += "<p>No Days "  + MyDays + "<p>";
            
            
          //send email to sales
          SendMessage ($("Email").getValue(), "info@latesail.co.uk", "", "", "LateSail availability request", message, "", "")
            
            
            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                    var data = transport.responseText.evalJSON();
                      password = data.Password;
                      operatorEmail = data.OperatorEmail
                      yachtInfo = data.yachtInfo;
                      

                      
                      operatorString += "<p>Is the following Boat still available from - " + $("DateFrom").getValue() + " (DD/MM/YYYY) for " + $("NoDays").getValue() + " days</p>";
                      operatorString += "<p>Client Name: " + MyName + "</p>";
	                  operatorString += yachtInfo ;
	                  operatorString += "<p>Please advise ASAP</p>";
	                  operatorString += "<p>LateSail Ltd<br>";
	                  operatorString += "www.lateSail.com<br>";
	                  operatorString += "Lombard House, 12 to 17 Upper Bridge Street, Canterbury, Kent CT1 2NF</p>";
	                  operatorString += "<p>Telephone +44(0) 1227 47 99 00</p>";
                    
                      customerString += "<p>Dear "+ MyName ;
                      customerString += "<br />Many thanks for contacting us through our website. We will check the availability now and get back to you as soon as possible. Please note that it can sometimes take a little time to receive a response from the operators so please bear with us.";
                      customerString += "<br />For all future enquiries and bookings you may make you can save having to complete all your details again by logging in with this email address and the password " + password + ". Should you wish to change the password to one you find easier to remember you can do so by logging in at www.latesail.com/login.asp and editing your details.";
                      customerString += "<br />Should you wish to speak to a member of our sales team you can contact them on 08450 60 50 50. Please note our opening times are Monday to Friday, 9 to 5.30.";
                      customerString += "<br />Regards";
                      customerString += "<br />The LateSail team</p>";

                           //send email to customer                      
                     SendMessage ("info@latesail.co.uk", $("Email").getValue(), "", "", "LateSail availability request", customerString, "", "")
                                //send email to company                            
  	                 SendMessage ("info@latesail.co.uk", operatorEmail, "", "", "LateSail availability request", operatorString, "", "")
  	                             
                      
                      
                      
                      
 
                        

                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the request");
                }.bind(this),
                onComplete: function(){
                    window.location = "/enquirecomplete.aspx"
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EnquirySaveNew.aspx", ajaxOptions);          
        }else{
            alert(error);
            
        }
    }
function validateEnquireFormModal(){
        var valid = true;
        var StartDate = window.frames['_iframe-Project'].document.forms['form1'].elements['DateFrom'].value;
        var Name = window.frames['_iframe-Project'].document.forms['form1'].elements['fullname'].value;
        var Email = window.frames['_iframe-Project'].document.forms['form1'].elements['Email'].value;
        var Tel = window.frames['_iframe-Project'].document.forms['form1'].elements['DayPhone'].value;
        var Town = window.frames['_iframe-Project'].document.forms['form1'].elements['town'].value;  
        var NoDays = window.frames['_iframe-Project'].document.forms['form1'].elements['NoDays'].value;  
        if(StartDate.length == 0 || StartDate == "Start Date*"){valid = false; generateFormErrorEntry2("Please enter a start date")}
        if(Tel.length == 0 || Tel == "Day Time Phone Number*"){valid = false; generateFormErrorEntry2("Please enter a telephone number")}
        if(Name.length == 0 || Name == "Name*"){valid = false; generateFormErrorEntry2("Please enter your full name")}
        if(Email.length == 0 || Email == "Email Address*"){valid = false; generateFormErrorEntry2("Please enter a valid email address")}
        if(Town.length == 0 || Town == "Home Town*"){valid = false; generateFormErrorEntry2("Please enter a town")}
        if(IsNumeric(NoDays)==false){valid = false; generateFormErrorEntry2("Please enter a number only for number of days")}
        return valid;
    }
function SendEnquireModal(){
        error = "";
        if(validateEnquireFormModal()){
            var data = "";
            var message = "";
            var customerString = "";
            var operatorString = "";
            var password = "";
            var operatorEmail = "";
            var yachtInfo = "";
            
            var MyDate = "";
            var MyName = "";
            var MyDays = "";
            var MyEmail = "";
            var MyPhone = "";
            var MyTown = "";
            var MyHear = "";
            var MyComments = "";
            
                      
            if (window.frames['_iframe-Project'].document.forms['form1'].elements['fullname'].value == "Name*") {MyName = ""} else {MyName = window.frames['_iframe-Project'].document.forms['form1'].elements['fullname'].value}
            if (window.frames['_iframe-Project'].document.forms['form1'].elements['Email'].value == "Email Address*") {MyEmail = ""} else {MyEmail = window.frames['_iframe-Project'].document.forms['form1'].elements['Email'].value}
            if (window.frames['_iframe-Project'].document.forms['form1'].elements['DayPhone'].value == "Day Time Phone Number*") {MyPhone = ""} else {MyPhone = window.frames['_iframe-Project'].document.forms['form1'].elements['DayPhone'].value}
            if (window.frames['_iframe-Project'].document.forms['form1'].elements['DateFrom'].value == "Start Date*") {MyDate = ""} else {MyDate = window.frames['_iframe-Project'].document.forms['form1'].elements['DateFrom'].value}
            if (window.frames['_iframe-Project'].document.forms['form1'].elements['town'].value == "Home Town*") {MyTown = ""} else {MyTown = window.frames['_iframe-Project'].document.forms['form1'].elements['town'].value}
            if (window.frames['_iframe-Project'].document.forms['form1'].elements['where'].value == "Where did you hear about LateSail?") {MyHear = ""} else {MyHear = window.frames['_iframe-Project'].document.forms['form1'].elements['where'].value}
            if (window.frames['_iframe-Project'].document.forms['form1'].elements['comments'].value == "Comments") {MyComments = ""} else {MyComments = escape(window.frames['_iframe-Project'].document.forms['form1'].elements['comments'].value)}
            if (window.frames['_iframe-Project'].document.forms['form1'].elements['NoDays'].value == "Number of Days Required*") {MyDays = ""} else {MyDays = window.frames['_iframe-Project'].document.forms['form1'].elements['NoDays'].value}
            
            
            
            
            data = "";
            data += "&FullName=" + MyName;
            data += "&Type=" + ""; 
            data += "&Email=" + MyEmail;
            data += "&Tel=" + MyPhone;
            data += "&Size=" + "";
            data += "&Cabins=" + "";
            data += "&Area="  + "";
            data += "&DateFrom=" + MyDate;
            data += "&DateTo=" + "";
            data += "&Town=" + MyTown;
            data += "&Hear=" + MyHear;
            data += "&Comments=" + MyComments;           
            data += "&Currency=" + "1";
            data += "&Offer=" + EmailViewOffer;            
            //mailViewPrice = data.FullPrice;
            //EmailViewOffer = data.OfferPrice;
            data += "&Country=" + MyCountryCode;
            data += "&CharterID=" + CruiseID;
            data += "&UserID=" + userID;
            data += "&DaysRequired=" + MyDays;
            
            
            
          message += "<p><strong>Below is the response from a LATESAIL Enquiry</strong><br />";
          message += "submitted by "  + MyName + "<p>";
      
          message += "<p>Start Date "  + MyDate + "<p>";
          message += "<p>Name "   + MyName + "<p>";
          message += "<p>Email "  + MyEmail + "<p>";
          message += "<p>Phone "  + MyPhone + "<p>";
          message += "<p>Town "  + MyTown + "<p>";
          message += "<p>Hear "  + MyHear + "<p>";
          message += "<p>Comments "  + MyComments + "<p>";
          message += "<p>Charter "  + CruiseID + "<p>";
          message += "<p>Viewed Full Price "  + EmailViewPrice + "<p>";
          message += "<p>Viewed Offer Price "  + EmailViewOffer + "<p>";
          message += "<p>Currency "  + MyCurrency + "<p>";
          message += "<p>No Days "  + MyDays + "<p>";
            
            
          //send email to sales
          SendMessage (MyEmail, "info@latesail.co.uk", "", "", "LateSail availability request", message, "", "")
            
            
            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                    var data = transport.responseText.evalJSON();
                      password = data.Password;
                      operatorEmail = data.OperatorEmail
                      yachtInfo = data.yachtInfo;
                      

                      
                      operatorString += "<p>Is the following Boat still available from - " + MyDate + " (DD/MM/YYYY) for " + MyDays + " days</p>";
                      operatorString += "<p>Client Name: " + MyName + "</p>";
	                  operatorString += yachtInfo ;
	                  operatorString += "<p>Please advise ASAP</p>";
	                  operatorString += "<p>LateSail Ltd<br>";
	                  operatorString += "www.lateSail.com<br>";
	                  operatorString += "Lombard House, 12 to 17 Upper Bridge Street, Canterbury, Kent CT1 2NF</p>";
	                  operatorString += "<p>Telephone +44(0) 1227 47 99 00</p>";
                    
                      customerString += "<p>Dear "+ MyName ;
                      customerString += "<br />Many thanks for contacting us through our website. We will check the availability now and get back to you as soon as possible. Please note that it can sometimes take a little time to receive a response from the operators so please bear with us.";
                      customerString += "<br />For all future enquiries and bookings you may make you can save having to complete all your details again by logging in with this email address and the password " + password + ". Should you wish to change the password to one you find easier to remember you can do so by logging in at www.latesail.com/login.asp and editing your details.";
                      customerString += "<br />Should you wish to speak to a member of our sales team you can contact them on 08450 60 50 50. Please note our opening times are Monday to Friday, 9 to 5.30.";
                      customerString += "<br />Regards";
                      customerString += "<br />The LateSail team</p>";
                   

                      
                      

                           //send email to customer                      
                     SendMessage ("info@latesail.co.uk", MyEmail, "", "", "LateSail availability request", customerString, "", "")
                                //send email to company                            
  	                 SendMessage ("info@latesail.co.uk", operatorEmail, "", "", "LateSail availability request", operatorString, "", "")
  	                             
                      
                      
                      
                      
 
                        

                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the request");
                }.bind(this),
                onComplete: function(){
                    window.location = "/enquirecomplete.aspx"
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EnquirySaveNew.aspx", ajaxOptions);          
        }else{
            alert(error);
            
        }
    }
    
function IsNumeric(input)
{
   return (input - 0) == input && input.length > 0;
}


function EditBookingCrewList(ID, CrewNo){
            var data = "";
            data = "";
            data += "&CrewID=" + $(ID).getValue() ;
            data += "&CrewNo=" + CrewNo ;
            data += "&BookingID=" + bookingID;
            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                    var data = transport.responseText.evalJSON();
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the crew member");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/BookingSaveCrew.aspx", ajaxOptions);          
    }
    
function SaveFlightDetails(){
            var data = "";
            data = "";
            data += "&arrivaldate=" + $("arrivaldate").getValue() ;
            data += "&arrivaltime=" + $("arrivaltime").getValue() ;
            data += "&airport=" + $("arrival-airport").getValue() ;
            data += "&flight=" + $("arrival-flight").getValue() ;
            data += "&BookingID=" + bookingID;

            
            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                    var data = transport.responseText.evalJSON();
                      

                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the flight details");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/BookingSaveFlight.aspx", ajaxOptions);          
    }
    
    
    
    
    
    
    

function SendRequestQuote2(){
        error = "";
        if(validateRequestForm2()){
            var data = "";
            var message = "";
            var customerString = "";
            var password = "";
            
            
        if (MyCurrency == "&pound;") {
            MyCurrency = 1;
        }
        if (MyCurrency == "£") {
            MyCurrency = 1;
        }
        if (MyCurrency == "US$") {
            MyCurrency = 2;
        }
        if (MyCurrency == "Euro") {
            MyCurrency = 3;
        }
        if (MyCurrency == "AUS$") {
            MyCurrency = 4;
        }
        if (MyCurrency == "CAN$") {
            MyCurrency = 5;
        }
            
            

            
            
            
            data = "";
            data += "&FullName=" + $("FindMe-Fullname").getValue();
            data += "&Type=" + $("YachtType").getValue();
            data += "&Email=" + $("FindMe-Email").getValue();
            data += "&Tel=" + $("FindMe-DayPhone").getValue();
            data += "&Cabins=" + "";
            data += "&Size=" + $("MinyachtSize").getValue() + " to " + $("MaxyachtSize").getValue();
            data += "&Area="  + $("FindMe-Area").getValue();
            data += "&DateFrom=" + DateFrom;
            data += "&DateTo=" + DateTo;
            data += "&Town=" + "";
            data += "&Hear=" + "";
            data += "&Comments=" + "";           
            data += "&Currency=" + "1";
            
            data += "&Offer=" + 0;
            data += "&Country=" + MyCountryCode;
            data += "&CharterID=" + 0;
            data += "&UserID=" + userID;
            data += "&DaysRequired=" + "0";
            

            
            
            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                    var data = transport.responseText.evalJSON();
                      password = data.Password;
                    
                      customerString += "<p>Dear "+ $("FindMe-Fullname").getValue() ;
                      customerString += "<br />Many thanks for contacting us through our website. We will check the availability now and get back to you as soon as possible. Please note that it can sometimes take a little time to receive a response from the operators so please bear with us.";
                      customerString += "<br />For all future enquiries and bookings you may make you can save having to complete all your details again by logging in with this email address and the password " + password + ". Should you wish to change the password to one you find easier to remember you can do so by logging in at www.latesail.com/login.asp and editing your details.";
                      customerString += "<br />Should you wish to speak to a member of our sales team you can contact them on 08450 60 50 50. Please note our opening times are Monday to Friday, 9 to 5.30.";
                      customerString += "<br />Regards";
                      customerString += "<br />The LateSail team</p>";
                   
                      message += "<p><strong>Below is the response from a LATESAIL Enquiry</strong><br />";
                      message += "submitted by "  + $("FindMe-Fullname").getValue() + "<p>";
                  
                      message += "<p>Yacht type "  + $("YachtType").getValue() + "<p>";
                      message += "<p>Yacht size "  + $("MinyachtSize").getValue() + " to " + $("MaxyachtSize").getValue() + "<p>";
                      message += "<p>Date from "  + DateFrom + "<p>";
                      message += "<p>Date to "  + DateTo + "<p>";
                      message += "<p>Area "  + $("FindMe-Area").getValue() + "<p>";
                      message += "<p>Full name "  + $("FindMe-Fullname").getValue() + "<p>";
                      message += "<p>Email "  + $("FindMe-Email").getValue() + "<p>";
                      message += "<p>Tel "  + $("FindMe-DayPhone").getValue() + "<p>";
                             
                        //send email to sales
                            SendMessage ($("FindMe-Email").getValue(), "info@latesail.co.uk", "", "", "LateSail request quotes", message, "", "")
  	                    //send email to customer
  	                        SendMessage ("info@latesail.co.uk", $("FindMe-Email").getValue(), "", "", "Your LateSail enquiry", customerString, "", "")

                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the request");
                }.bind(this),
                onComplete: function(){
                    window.location = "/requestcomplete.aspx"
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EnquirySaveNew.aspx", ajaxOptions);          
        }else{
            alert(error);
            
        }
    }

function SendRequestQuote(){
        error = "";
        if(validateRequestForm()){
            var data = "";
            var message = "";
            var customerString = "";
            var password = "";
            
            
        if (MyCurrency == "&pound;") {
            MyCurrency = 1;
        }
        if (MyCurrency == "£") {
            MyCurrency = 1;
        }
        if (MyCurrency == "US$") {
            MyCurrency = 2;
        }
        if (MyCurrency == "Euro") {
            MyCurrency = 3;
        }
        if (MyCurrency == "AUS$") {
            MyCurrency = 4;
        }
        if (MyCurrency == "CAN$") {
            MyCurrency = 5;
        }
            
            
            data = "";
            data += "&FullName=" + $("fullnameRQ").getValue();
            data += "&Type=" + $("YachtTypeRQ").getValue();
            data += "&Email=" + $("EmailRQ").getValue();
            data += "&Tel=" + $("DayPhoneRQ").getValue();
            data += "&Cabins=" + "";
            data += "&Size=" + $("MinyachtSizeRQ").getValue() + " to " + $("MaxyachtSizeRQ").getValue();
            data += "&Area="  + $("AreaRQ").getValue();
            data += "&DateFrom=" + DateFrom;
            data += "&DateTo=" + DateTo;
            data += "&Town=" + "";
            data += "&Hear=" + $("whereRQ").getValue();
            data += "&Comments=" + "";           
            data += "&Currency=" + "1";
            
            data += "&Offer=" + 0;
            data += "&Country=" + MyCountryCode;
            data += "&CharterID=" + 0;
            data += "&UserID=" + userID;
            data += "&DaysRequired=" + "0";
            

            
            
            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                    var data = transport.responseText.evalJSON();
                      password = data.Password;
                    
                      customerString += "<p>Dear "+ $("fullnameRQ").getValue() ;
                      customerString += "<br />Many thanks for contacting us through our website. We will check the availability now and get back to you as soon as possible. Please note that it can sometimes take a little time to receive a response from the operators so please bear with us.";
                      customerString += "<br />For all future enquiries and bookings you may make you can save having to complete all your details again by logging in with this email address and the password " + password + ". Should you wish to change the password to one you find easier to remember you can do so by logging in at www.latesail.com/login.asp and editing your details.";
                      customerString += "<br />Should you wish to speak to a member of our sales team you can contact them on 08450 60 50 50. Please note our opening times are Monday to Friday, 9 to 5.30.";
                      customerString += "<br />Regards";
                      customerString += "<br />The LateSail team</p>";
                   
                      message += "<p><strong>Below is the response from a LATESAIL Enquiry</strong><br />";
                      message += "submitted by "  + $("fullnameRQ").getValue() + "<p>";
                  
                      message += "<p>Yacht type "  + $("YachtTypeRQ").getValue() + "<p>";
                      message += "<p>Yacht size "  + $("MinyachtSizeRQ").getValue() + " to " + $("MaxyachtSizeRQ").getValue() + "<p>";
                      message += "<p>Date from "  + DateFrom + "<p>";
                      message += "<p>Date to "  + DateTo + "<p>";
                      message += "<p>Area "  + $("AreaRQ").getValue() + "<p>";
                      message += "<p>Full name "  + $("fullnameRQ").getValue() + "<p>";
                      message += "<p>Email "  + $("EmailRQ").getValue() + "<p>";
                      message += "<p>Tel "  + $("DayPhoneRQ").getValue() + "<p>";
                             
                        //send email to sales
                            SendMessage ($("EmailRQ").getValue(), "info@latesail.co.uk", "", "", "LateSail request quotes", message, "", "")
  	                    //send email to customer
  	                        SendMessage ("info@latesail.co.uk", $("EmailRQ").getValue(), "", "", "Your LateSail enquiry", customerString, "", "")

                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the request");
                }.bind(this),
                onComplete: function(){
                    window.location = "/requestcomplete.aspx"
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EnquirySaveNew.aspx", ajaxOptions);          
        }else{
            alert(error);
            
        }
    }
     function validateEnquireForm(){
        var valid = true;

        var StartDate = $("DateFrom").getValue();
        //var NumberDays = $("NoDays").getValue();
        var Name = $("fullname").getValue();      
        var Email = $("Email").getValue();
        var Tel = $("DayPhone").getValue();
        var Town = $("town").getValue();   
        
        if(StartDate.length == 0 || StartDate == "Start Date*"){valid = false; generateFormErrorEntry2("Please enter a start date")}
        //if(NumberDays.length == 0){valid = false; generateFormErrorEntry2("Please enter a number of days for your charter")}
        if(Tel.length == 0 || Tel == "Day Time Phone Number*"){valid = false; generateFormErrorEntry2("Please enter a telephone number")}
        if(Name.length == 0 || Name == "Name*"){valid = false; generateFormErrorEntry2("Please enter your full name")}
        if(Email.length == 0 || Email == "Email Address*"){valid = false; generateFormErrorEntry2("Please enter a valid email address")}
        if(Town.length == 0 || Town == "Home Town*"){valid = false; generateFormErrorEntry2("Please enter a town")}
        
        if(IsNumeric($("NoDays").getValue())==false){valid = false; generateFormErrorEntry2("Please enter a number only for number of days")}
        
             
        
        
        
        return valid;
    }

 function validateRequestForm(){
        var valid = true;

        var Name = $("fullnameRQ").getValue();
        var Email = $("EmailRQ").getValue();
        var Tel = $("DayPhoneRQ").getValue();      
        
        if(Name.length == 0){valid = false; generateFormErrorEntry2("Please enter your full name")}
        if(Email.length == 0){valid = false; generateFormErrorEntry2("Please enter a valid email address")}
        if(Tel.length == 0){valid = false; generateFormErrorEntry2("Please enter a telephone number")}
        
        return valid;
    }
    
 function validateRequestForm2(){
        var valid = true;

        var Name = $("FindMe-Fullname").getValue();
        var Email = $("FindMe-Email").getValue();
        var Tel = $("FindMe-DayPhone").getValue();  
          
        
        if(Name.length == 0){valid = false; generateFormErrorEntry2("Please enter your full name")}
        if(Email.length == 0){valid = false; generateFormErrorEntry2("Please enter a valid email address")}
        if(Tel.length == 0){valid = false; generateFormErrorEntry2("Please enter a telephone number")}
        
        return valid;
    }
    
     function validateRequestFormA(){
        var valid = true;

        var DateFrom = $("DateFromRQ").getValue();
        var DateTo = $("DateToRQ").getValue();   
        
        if(DateFrom.length == 0){valid = false; generateFormErrorEntry2("Please enter a date from")}
        if(DateTo.length == 0){valid = false; generateFormErrorEntry2("Please enter a date to")}
        
        return valid;
    }
    
     function validateRequestFormB(){
        var valid = true;

        var DateFrom = $("DateFrom").getValue();
        var DateTo = $("DateTo").getValue();   
        
        if(DateFrom.length == 0){valid = false; generateFormErrorEntry2("Please enter a date from")}
        if(DateTo.length == 0){valid = false; generateFormErrorEntry2("Please enter a date to")}
        
        return valid;
    }

var error = "";
    function generateFormErrorEntry2(message){
        error += message + "\n"
    }
var SearchCharterType = "";
function GetCountryOffers(ID, SearchField){
        $("CountryCharters").update("");
        var CharterType = 1;
        ajaxOptions = {
                method: "post",
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();

                   
                   
            if (LinkCharterType) {
                        CharterType = LinkCharterType; 
                        SearchCharterType = LinkCharterType;
            } else {
                   if (data.CharterType.length != 0) {
                        CharterType = data.CharterType; 
                        SearchCharterType = data.CharterType;
                   };
              }  
                   
                   
  
                   
                   
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem getting search criteria");
                }.bind(this),
                onComplete: function(){
                        ajaxOptions = {
                        method: "post",
                        parameters: {"CharterType": CharterType, "Code": MyCountryCode, "Currency":MyCurrency, "Country":ID, "SearchField":SearchField},
                        onSuccess: function(transport){
                            var data = transport.responseText.evalJSON();
                            generateCountryOfferLines(data)
                        }.bind(this),
                        onFailure: function(){
                            alert("There was a problem fetching the special offers.");
                        }.bind(this),
                        onComplete: function(){
                           
                        
                            switch(SearchCharterType)
	                        {
	                            
		                        case "1":
		                            $("CharterListDescription").update("Current Bareboat Charters");
			                        break;
		                        case "2":
		                            $("CharterListDescription").update("Current Cabin Charters");
			                        break;
		                        case "3":
		                            $("CharterListDescription").update("Current Crewed Charters");
			                        break;
		                        case "4":
		                            $("CharterListDescription").update("Current Flotilla Charters");
			                        break;
			                    }
                            
                           
                        }.bind(this)
                        };
                        new Ajax.Request("AjaxCalls/GetCountryOffers.aspx", ajaxOptions);
                }.bind(this)
            };
         new Ajax.Request("AjaxCalls/getCharterType.aspx", ajaxOptions);
    }
    function generateCountryOfferLines(lineData){
        lineData.each(function(line){
            generateCountryOfferLine(line);
        });
    }
    function generateCountryOfferLine(line){
       
     //$("FindMe-Area").value = line.CountryName;
     $("AreaRQ").value = line.CountryName; 
     
     
    var thisFullPrice = 0;
    var thisOfferPrice = 0; 
    var thisPerson = 0;
        var a1 = new Element("a", {"href":"CruiseDetail.aspx?CruiseID="+ line.CruiseID, "title":"Click to view details about this charter"});
        var div1 = new Element("div", {"class":"ResultLine", "style":"background-color:" + CellColour + ";"});
            var div2 = new Element("div", {"class":"ResultLocation"}).update(line.CountryName);
            var div3 = new Element("div", {"class":"ResultBase"}).update(line.Base);
            var div4 = new Element("div", {"class":"ResultYacht"});
            var a2 = new Element("a", {"href":"javaScript:openWindow('yachtpopup.asp?id="+ line.YachtID + "')", "title":"yacht details"}).update(line.YachtName);
            div4.insert(a2)
            var div5 = new Element("div", {"class":"ResultStart"}).update(line.StartDate);
            var div6 = new Element("div", {"class":"ResultEnd"}).update(line.EndDate);
            var div7 = new Element("div", {"class":"ResultDays"}).update(line.NoDays);
            var div8 = new Element("div", {"class":"ResultType"});
            var div11 = new Element("div", {"class":"ResultDiscount"}).update(line.Difference + "%");
        var MyPerPersonshow = false;
        var MyPlane = false;
        if (MyPerPerson > 0) {
            if (line.PerPerson > 0) {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0) + "pp";
                thisPerson = line.PerPerson;
                MyPerPersonshow = true;
                MyPlane = true;
            } else {
                thisFullPrice = parseFloat(line.FullPrice/MyPerPerson).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice/MyPerPerson).toFixed(0) + "pp";
                thisPerson = MyPerPerson;
                MyPerPersonshow = true;
            }
        } else {
            if (line.PerPerson > 0) {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0) + "pp";
                thisPerson = line.PerPerson;
                MyPerPersonshow = true;
                MyPlane = true;
            } else {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0);
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0);
                thisPerson = 0;
                MyPerPersonshow = false;
            }
        };
        
            var div9 = new Element("div", {"class":"ResultPrice"}).update(line.currencyChar + '' + thisFullPrice);
            var div10 = new Element("div", {"class":"ResultOffer"}).update(line.currencyChar + '' + thisOfferPrice);
        
        var div21 = new Element("div", {"class":"PerPersonNumber", "title":"Price per person based on " +thisPerson+ " people sharing"}).update("  x "+thisPerson);
        var div23 = new Element("div", {"class":"PerYachtNumber", "title":"Price per yacht"}).update("");
        var div25 = new Element("div", {"class":"Plane", "title":"Price includes flights"}).update("");
        
        if (MyPerPersonshow) {
        div8.insert(div21);
            if (MyPlane) {
            div8.insert(div25);
            }
        } else {
        div8.insert(div23);
        }        
        //div1.insert(div2);
        div1.insert(div3);
        div1.insert(div4);
        div1.insert(div5);
        div1.insert(div6);
        div1.insert(div7);
        div1.insert(div8);
        div1.insert(div9);
        div1.insert(div10);
        div1.insert(div11);
        a1.insert(div1);
        $("CountryCharters").insert(a1);
        
        
       if (CellColour == "#C7D1D7" ) {
            CellColour = "#E1E5E8"
            } else {
            CellColour = "#C7D1D7"
            }  
     
     /*
     
        var tr1 = new Element("tr");
        var td1 = new Element("td", {"style":"width:130px;"});
        var p1 = new Element("p").update(line.Base);
        var td2 = new Element("td", {"style":"width:110px;"});
        var p2 = new Element("p").update(line.CompanyCode);
        var td3 = new Element("td", {"style":"width:130px;"});
        var p3 = new Element("p");
        var a3 = new Element("a", {"href":"javaScript:openWindow('yachtpopup.asp?id="+ line.YachtID + "')", "title":"yacht details"}).update(line.YachtName);
        var td4 = new Element("td", {"style":"width:75px;"});
        var p4 = new Element("p").update(line.StartDate);
        var td5 = new Element("td", {"style":"width:75px;"});
        var p5 = new Element("p").update(line.EndDate);
        var td11 = new Element("td", {"style":"width:30px;"});
        var p11 = new Element("p").update(line.NoDays); 
        
        
        var td6 = new Element("td", {"style":"width:90px;"});
        var td10 = new Element("td", {"style":"width:100px;"});
        
        var MyPerPersonshow = false;
        var MyPlane = false;
        if (MyPerPerson > 0) {
            if (line.PerPerson > 0) {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0) + "pp";
                thisPerson = line.PerPerson;
                MyPerPersonshow = true;
                MyPlane = true;
            } else {
                thisFullPrice = parseFloat(line.FullPrice/MyPerPerson).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice/MyPerPerson).toFixed(0) + "pp";
                thisPerson = MyPerPerson;
                MyPerPersonshow = true;
            }
        } else {
            if (line.PerPerson > 0) {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0) + "pp";
                thisPerson = line.PerPerson;
                MyPerPersonshow = true;
                MyPlane = true;
            } else {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0);
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0);
                thisPerson = 0;
                MyPerPersonshow = false;
            }
        };
  
  
        var div1 = new Element("div", {"class":"PerPersonNumber", "title":"Price per person based on " +thisPerson+ " people sharing"}).update("  x "+thisPerson);
        var div2 = new Element("div", {"class":"PerPersonNumber", "title":"Price per person based on " +thisPerson+ " people sharing"}).update("  x "+thisPerson); 
 
        var div3 = new Element("div", {"class":"PerYachtNumber", "title":"Price per yacht"}).update("");
        var div4 = new Element("div", {"class":"PerYachtNumber", "title":"Price per yacht"}).update("");
        
        var div5 = new Element("div", {"class":"Plane", "title":"Price includes flights"}).update("");
        var div6 = new Element("div", {"class":"Plane", "title":"Price includes flights"}).update("");
        
        
        
        var p6 = new Element("p").update(line.currencyChar + '' + thisFullPrice);
        
        
   
        var td7 = new Element("td", {"style":"width:90px;"});
        var p7 = new Element("p").update(line.currencyChar + '' + thisOfferPrice);
        var td8 = new Element("td", {"style":"width:60px;"});
        var p8 = new Element("p").update(line.Difference + "%");
        var td9 = new Element("td", {"style":"width:80px;"});       



        //var a9 = new Element("a", {"href":"Cruiseenquire.aspx?CruiseID="+ line.CruiseID, "title":"Click to enquire about this charter"});
        //var img9 = new Element("img", {"src":"../Img/Enquire.gif", "border":"0"});
        var a9 = new Element("a", {"title":line.Notes,"href":"CruiseDetail.aspx?CruiseID="+ line.CruiseID}).update("notes");
        var a10 = new Element("a", {"href":"CruiseDetail.aspx?CruiseID="+ line.CruiseID, "title":"Click to view details about this charter"}).update(" details");
        
        //a9.insert(img9);
        
        td1.insert(p1);
        td2.insert(p2);
        p3.insert(a3);
        td3.insert(p3);
        td4.insert(p4);
        td5.insert(p5);
        td11.insert(p11);
        
        if (MyPerPersonshow) {
        td10.insert(div1);
            if (MyPlane && SearchCharterType != "2") {
            td10.insert(div5);
            }
        } else {
        td10.insert(div3);
        }
        td6.insert(p6);
        td7.insert(p7);

        td8.insert(p8);
        
        td9.insert(a10);
if (line.Notes.length > 0) {td9.insert(" | ");td9.insert(a9)}
        tr1.insert(td1);
        //tr1.insert(td2);
        tr1.insert(td3);
        tr1.insert(td4);
        tr1.insert(td5);
        tr1.insert(td11);
        tr1.insert(td10);
        
        tr1.insert(td6);
        tr1.insert(td7);
        tr1.insert(td8);
        tr1.insert(td9);
        
        $("CountryCharters").insert(tr1);
        
    
     */
        
        
    }


function getPassword() {
    $("login-div").hide();
    $("password-div").show();
}
function getLogin() {
    $("password-div").hide();
    $("login-div").show();
}

var EmailViewPrice = "";
var EmailViewOffer = "";
var startDate = "";
var endDate = "";
var actualDays = "";
var noOfDays = "";
var MyPerPerson = false;

function GetEnquiryCharterDetails(ID){
$("EnquiryLine").update();
            ajaxOptions = {
                method: "post",
                parameters: {"CruiseID": ID, "currencyID": MyCurrency},
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                   if (data.CompanyID != 0) {
                   CountryID = data.CountryID
                    var tr1 = new Element("tr");
                    var tr2 = new Element("tr");
                    
                    var td1 = new Element("td").update(data.CompanyCode);
                    var td2 = new Element("td").update(data.Base);
                    var td3 = new Element("td").update(data.YachtName);
                    var td4 = new Element("td").update(data.StartDate);
                    var td5 = new Element("td").update(data.EndDate);
                    var td6 = new Element("td").update(data.currencyChar + data.FullPrice);
                    var td7 = new Element("td").update(data.currencyChar + data.OfferPrice);
                    
                    
                    
                    
                    
                    EmailViewPrice = data.currencyChar + data.FullPrice;
                    EmailViewOffer = data.currencyChar + data.OfferPrice;
                    
                    startDate = data.StartDate;
                    endDate = data.EndDate;
                    actualDays = data.NoDays;
                    
                   // noOfDays = DateDiff("d",startDate,endDate)
                    
                    noOfDays = data.DateDiff;
                    
                    if (noOfDays != actualDays) {
	                    $("Starting").show();
                    } else {
	                    $("Starting").hide();
	                };
                    
                    tr1.insert(td1);
                    tr1.insert(td2);
                    tr1.insert(td3);
                    tr1.insert(td4);
                    tr1.insert(td5);
                    tr1.insert(td6);
                    tr1.insert(td7);

                    $("EnquiryLine").insert(tr1);
                        
                        
                        
                        
                   };
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem getting the charter details");
                }.bind(this),
                onComplete: function(){
                    
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/GetCharterDetails.aspx", ajaxOptions);
    }









function ViewDestinationFeedback(ID) {
    $("FeedbackRatings").update("");
        ajaxOptions = {
            method: "post",
            parameters: {"CountryID": ID},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateDestinationFeedbackLines(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the Destination Feedback.");
            }.bind(this),
            onComplete: function(){
                $("Feedbacker").show();
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetDestinationFeedback.aspx", ajaxOptions);
    }
    function generateDestinationFeedbackLines(lineData){
        lineData.each(function(line){
            generateDestinationFeedbackLine(line);
        });
    }
    function generateDestinationFeedbackLine(line){  
        var tr1 = new Element("tr");
        var tr2 = new Element("tr");
        var td1 = new Element("td");
        var img1 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img2 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img3 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img4 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img5 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img6 = new Element("img", {"src":"/images/star3.gif","alt":"star"});
        var img7 = new Element("img", {"src":"/images/star3.gif","alt":"star"});
        var img8 = new Element("img", {"src":"/images/star3.gif","alt":"star"});
        var img9 = new Element("img", {"src":"/images/star3.gif","alt":"star"});
        var img10 = new Element("img", {"src":"/images/star3.gif","alt":"star"});

        if (line.RatingID >= 1) {
            td1.insert(img1);
        } else {
            td1.insert(img6);
        };
        if (line.RatingID >= 2) {
            td1.insert(img2);
        } else {
            td1.insert(img7);
        };
        if (line.RatingID >= 3) {
            td1.insert(img3);
        } else {
            td1.insert(img8);
        };
        if (line.RatingID >= 4) {
            td1.insert(img4);
        } else {
            td1.insert(img9);
        };
        if (line.RatingID == 5) {
            td1.insert(img5);
        } else {
            td1.insert(img10);
        };
        var td2 = new Element("td");
        var p2 = new Element("p").update(line.Descript);
        td2.insert(p2);
        tr1.insert(td1);
        tr2.insert(td2);
        $("FeedbackRatings").insert(tr1);
        $("FeedbackRatings").insert(tr2);
    }
function ViewYachtFeedback(ID) {
    $("FeedbackRatings").update("");
        ajaxOptions = {
            method: "post",
            parameters: {"YachtID": ID},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateYachtFeedbackLines(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the Yacht Feedback.");
            }.bind(this),
            onComplete: function(){
                $("Feedbacker").show();
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetYachtFeedback.aspx", ajaxOptions);
    }
    function generateYachtFeedbackLines(lineData){
        lineData.each(function(line){
            generateYachtFeedbackLine(line);
        });
    }
    function generateYachtFeedbackLine(line){  
        var tr1 = new Element("tr");
        var tr2 = new Element("tr");
        var td1 = new Element("td");
        var img1 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img2 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img3 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img4 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img5 = new Element("img", {"src":"/images/star1.gif","alt":"star"});
        var img6 = new Element("img", {"src":"/images/star3.gif","alt":"star"});
        var img7 = new Element("img", {"src":"/images/star3.gif","alt":"star"});
        var img8 = new Element("img", {"src":"/images/star3.gif","alt":"star"});
        var img9 = new Element("img", {"src":"/images/star3.gif","alt":"star"});
        var img10 = new Element("img", {"src":"/images/star3.gif","alt":"star"});

        if (line.RatingID >= 1) {
            td1.insert(img1);
        } else {
            td1.insert(img6);
        };
        if (line.RatingID >= 2) {
            td1.insert(img2);
        } else {
            td1.insert(img7);
        };
        if (line.RatingID >= 3) {
            td1.insert(img3);
        } else {
            td1.insert(img8);
        };
        if (line.RatingID >= 4) {
            td1.insert(img4);
        } else {
            td1.insert(img9);
        };
        if (line.RatingID == 5) {
            td1.insert(img5);
        } else {
            td1.insert(img10);
        };
        var td2 = new Element("td");
        var p2 = new Element("p").update(line.Descript);
        td2.insert(p2);
        tr1.insert(td1);
        tr2.insert(td2);
        $("FeedbackRatings").insert(tr1);
        $("FeedbackRatings").insert(tr2);
    }
        
        
        
        
        
        
        
        
    function CloseYachtFeedback() {
		$("Feedbacker").hide();
        } 

var offerprice = 0;

function GetCharterDetails(ID){
$("CharterDetail").update();
$("CharterDesc").update();
$("EnquiryButton").update();
            ajaxOptions = {
                method: "post",
                parameters: {"CruiseID": ID, "currencyID": MyCurrency},
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                   if (data.CompanyID != 0) {
                   CountryID = data.CountryID
                    var br1 = new Element("br");
                    var br2 = new Element("br");
                    var br3 = new Element("br");
                    var br4 = new Element("br");
                    var br5 = new Element("br");
                    var br6 = new Element("br");
                    var br7 = new Element("br");
                    var br8 = new Element("br");
                    var br9 = new Element("br");
                    var br10 = new Element("br");
                    var br11 = new Element("br");
                    var br12 = new Element("br");
                    var br13 = new Element("br");
                    var br14 = new Element("br");
                    
                    
                    
                    var p1 = new Element("p");
                    
                    var strong1 = new Element("strong").update("Offer Code: ");
                    var strong14 = new Element("strong").update("Base: ");
                    var strong2 = new Element("strong").update("Yacht: ");
                    
                    var a1 = new Element("a", {"href":"javascript:ViewYachtFeedback("+ data.YachtID + ")", "title":"View Yacht Feedback"}).update("View Feedback");
                    
                    var strong3 = new Element("strong").update("Full Price: ");
                    var strong4 = new Element("strong").update("Offer Price: ");
                    var strong5 = new Element("strong").update("Start Date: ");
                    var strong6 = new Element("strong").update("End Date: ");
                    var strong7 = new Element("strong").update("Number of Days: ");
                    
                    //var image1 = new Element("img", {"src":data.ImgLayout,"style":"margin:20px 20px 20px 0px"});
                                       
                                       
                    EmailViewPrice = data.currencyChar + data.FullPrice;
                    EmailViewOffer = data.currencyChar + data.OfferPrice;
                    
                    
                    var Saving = data.currencyChar + (data.FullPrice - data.OfferPrice).toFixed(2)
                    
                    
                    $("EnquiryButton").insert("ENQUIRE NOW<br/>SAVE " + Saving +"!");
                    
                    
                    p1.insert(strong1);
                    p1.insert(ID + "  ");
                    p1.insert(br1);
                    p1.insert(strong14);
                    p1.insert(data.Base + "  ");
                    p1.insert(br14);
                    p1.insert(strong2);
                    if (data.FeedBackRating != 0) {
                    p1.insert(data.YachtName + " ");
                    p1.insert("  (Rated at " + data.FeedBackRating + "% - ");
                    p1.insert(a1);
                    p1.insert(")");
                    } else {
                    p1.insert(data.YachtName + " ");
                    p1.insert("  (Yet to be Rated)");
                    };                    
                    p1.insert(br2);
                    p1.insert(strong3);
                    p1.insert(data.currencyChar + data.FullPrice + "  ");
                    p1.insert(br3);
                    p1.insert(strong4);
                    offerprice = data.OfferPrice;
                
                    if (MyCurrency) {
                        MyCurrency = MyCurrency;
                    } else {
                        MyCurrency = data.currencyChar;
                    }
                    p1.insert(data.currencyChar + data.OfferPrice);
                    p1.insert(br4);
                    p1.insert(strong5);
                    p1.insert(data.StartDate + "  ");
                    

                    
                    p1.insert(br5);
                    p1.insert(strong6);
                    p1.insert(data.EndDate);
                    p1.insert(br6);
                    p1.insert(strong7);
                    p1.insert(data.NoDays + "  ");
                    p1.insert(br7);
                    
                    
                    
                    var p2 = new Element("p");
                    
                    var strong8 = new Element("strong").update("Notes: ");
                    var strong9 = new Element("strong").update("Start Time: ");
                    var strong10 = new Element("strong").update("Finish Time: ");
                    var strong11 = new Element("strong").update("Included: ");
                    var strong12 = new Element("strong").update("Extras: ");
                    var strong13 = new Element("strong").update("Options: ");
                    

                    p2.insert(strong8);
                    p2.insert(data.Notes);
                    p2.insert(br8);
                    
                    p2.insert(strong9);
                    p2.insert(data.StartTime);
                    p2.insert(br9);
                    p2.insert(strong10);
                    p2.insert(data.FinishTime);
                    p2.insert(br10);
                    p2.insert(strong11);
                    p2.insert(data.Included);
                    p2.insert(br11);
                    p2.insert(strong12);
                    p2.insert(data.Extras);
                    p2.insert(br12);
                    p2.insert(strong13);
                    p2.insert(data.Options);
                    p2.insert(br13);

                    
                    $("CharterDesc").insert(p1);
                    $("CharterDetail").insert(p2);
                    
                    var d = new Date(data.StartDate);

                    $("DateFrom").value = d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear();
                    $("NoDays").value = data.NoDays; 
                    
                   } else {
                   $("CharterDesc").update("<h1>This yacht charter has been snapped up already\!</h1><p>Sorry this charter is no longer available please <a href=\"http://www.latesail.com\" title=\"Yacht charter last minute discounted deals\">click here to look at our other yacht charter specials</a></p>")
                   };
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem getting the charter details");
                }.bind(this),
                onComplete: function(){
                    GetDestinationPage()
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/GetCharterDetails.aspx", ajaxOptions);
    }
    
    

    
    
    
function getYachtImage(ID){
     $("BoatImages").update("");
        ajaxOptions = {
            method: "get",
            parameters: {"YachtID":ID},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateFiles(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the images.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("/AjaxCalls/GetFileList.aspx", ajaxOptions);
    }
    function generateFiles(lineData){
        lineData.each(function(line){
            generateFileList(line);
        });
    }
    function generateFileList(line){
        var image1 = new Element("img", {"src":line.FileURL,"style":"margin:20px 20px 20px 0px"});
        $("BoatImages").insert(image1);
     }

function GetDestinationPage(){
            ajaxOptions = {
                method: "post",
                parameters: {"CountryID": CountryID},
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                   if (data.DestinationName != 0) {
                        DestinationDesc = data.Notes;
                        DestinationName = data.CountryName;
                        
                        MyFile = data.CountryName.replace("/","").replace(/ /g,"") + ".html";
                        
                        $("DestinationName").innerHTML = "Yacht Charter Destination - " + DestinationName;
                        var a1 = new Element("a", {"href":"javascript:ViewDestinationFeedback("+ CountryID + ")", "title":"View Destination Feedback"}).update("View Feedback");
                    
                        if (data.FeedBackRating != 0) {
                            $("DestinationRating").update("");
                            $("DestinationRating").insert("Rated at " + data.FeedBackRating + "% - ");
                            $("DestinationRating").insert(a1);
                        } else {
                            $("DestinationRating").update("Yet to be Rated");
                            }; 
                            
                                                	
                          if (document.getElementsByName('title')) {
                            document.getElementsByName('title').innerHTML = document.getElementsByName('title').innerHTML + " from " + DestinationName
                          }
                          if (document.getElementsByName('description')) {
                            document.getElementsByName('description').insert(" " + DestinationName)
                          }
                          if (document.getElementsByName('keywords')) {
                            document.getElementsByName('keywords').insert(" " + DestinationName)
                          }
                          
                          
                    
                        
                   };
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem getting cookie");
                }.bind(this),
                onComplete: function(){
                    //GetFileContents();
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/getDestination.aspx", ajaxOptions);
    }

function CheckLogin(){
            ajaxOptions = {
                method: "post",
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                   if (data.UserID.length != 0) {
                        userID = data.UserID;
                        getUserInfo(userID);
                        GetMenu();
                   } else {
                   $("MyLogin").show();
                   }
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem getting cookie");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/getcookie.aspx", ajaxOptions);
    }



	function ViewPDF(Type, ID){
		document.getElementById("PDF").action = "/Admin2/QuotePDF/View.aspx";
		document.getElementById("dob").value = ID; 
		document.getElementById("type").value = Type;
		document.getElementById("PDF").submit();
	}
	

	
    function closeEdit(){
        if (document.getElementById("Project")) {document.getElementById("Project").style.display = "none";}
	    document.getElementById("interVeil").style.display = "none";
	}

	
var CellColour = "alt";


    function ViewCrew(ID){
        emailwindow=dhtmlmodal.open('Project', 'iframe', '/modalfiles/crewmen.aspx?CrewmanID='+ID+'&EnquiryID='+userID, '', 'width=450px,height=450px,center=1,resize=0,scrolling=0')
    
        //Effect.BlindDown($("CrewPool_" + ID));
        //$("Down_" + ID).hide();
        //$("Up_" + ID).show();
    }
    function HideCrew(ID){
        EditFriend(ID);
        Effect.BlindUp($("CrewPool_" + ID));
        $("Down_" + ID).show();
        $("Up_" + ID).hide();
    }
    
    function getBookingCrew(ID){
        ajaxOptions = {
            method: "post",
            parameters: {"BookingID": ID},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateBookingCrewLines(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the crew pool.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetCrewList.aspx", ajaxOptions);
    }
    function generateBookingCrewLines(lineData){
        lineData.each(function(line){
            generateBookingCrewLine(line);
        });
    }
    function generateBookingCrewLine(line){
        $("crew-"+line.CrewPosition+"-id").value = line.CrewID;
        CheckCerts(line.CrewID, "crew-"+line.CrewPosition+"-certificate");
    }
    
    
    function AddCrew(ID){
        ajaxOptions = {
            method: "post",
            parameters: {"ClientID": userID},
            onSuccess: function(transport){
            getCrewPool(ID);  
            }.bind(this),
            onFailure: function(){
                alert("There was a problem adding a crew member.");
            }.bind(this),
            onComplete: function(){
                              
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/AddtoFriendsList.aspx", ajaxOptions);
    }
    
    
    
    
    function DeleteCrew(ID, Booking){
            ajaxOptions = {
                method: "post",
                parameters: {
                "FriendID": ID
                },            
                onSuccess: function(transport){
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem deleting your crew member.");
                }.bind(this),
                onComplete: function(){
                 getCrewPool(Booking);
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/DeleteFriend.aspx", ajaxOptions);
    }
    
    
    function UploadDoc(ID){
        $("customerID").value = ID;
        $("uploaddiv").show("");
    } 
    
    
    function EditFriend(ID){
            ajaxOptions = {
                method: "post",
                parameters: {
                "FriendID": ID,
                "EnquiryID": userID,
                "Name": $("FriendName_"+ID).getValue(),
                "Address": $("FriendAddress_"+ID).getValue(),
                "Telephone": $("FriendTelephone_"+ID).getValue(),
                "Email": $("FriendEmail_"+ID).getValue(),
                "DOB": $("FriendDOB_"+ID).getValue(),
                "Nationality": $("FriendNationality_"+ID).getValue(),
                "PassportNumber": $("FriendPassportNumber_"+ID).getValue(),
                "PassportExpiry": $("FriendPassportExpiry_"+ID).getValue()
                },            
                onSuccess: function(transport){
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem fetching the crew pool.");
                }.bind(this),
                onComplete: function(){
                   
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EditFriend.aspx", ajaxOptions);
    } 
    
    function EditUser(){
            ajaxOptions = {
                method: "post",
                parameters: {
                "EnquiryID": userID,
                "Name": $("fullname").getValue(),
                "Address": $("Address").getValue(),
                "Town": $("town").getValue(),
                "County": $("County").getValue(),
                "Postcode": $("Postcode").getValue(),
                "Country": $("Country").getValue(),
                "Email": $("Email").getValue(),
                "Tel": $("DayPhone").getValue(),
                "Password": $("Password").getValue()
                },            
                onSuccess: function(transport){
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving your details.");
                }.bind(this),
                onComplete: function(){
                   
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EditUser.aspx", ajaxOptions);
    } 

    function getCrewPool(ID){
        $("CrewPool").update("");
        //alert($("CrewPool").innerHTML);
        ajaxOptions = {
            method: "post",
            parameters: {"ClientID": userID},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateCrewPoolLines(data, ID)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the crew pool.");
            }.bind(this),
            onComplete: function(){
                $("MyDetails").hide("");
                $("ManageCrew").show("");
                getBookingCrew(ID);
                
                var a1 = new Element("a", {"href":"javascript:AddCrew("+ID+")", "title":"Add Crew Member"}).update("Add Crew Member");
                $("CrewPool").insert(a1);
                
                //alert($("CrewPool").innerHTML);
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetFriendsList.aspx", ajaxOptions);
    }
    function generateCrewPoolLines(lineData, ID){
        var i=1;
        for (i=1;i<=12;i=i+1)
            {
            $("crew-"+i+"-id").update("");
            }
        i=1;
        for (i=1;i<=12;i=i+1)
            {
            var op1 = new Element("option", {"value":0}).update("n/a");
            $("crew-"+i+"-id").insert(op1);
            }
        lineData.each(function(line){
            generateCrewPoolLine(line, ID);
        });
    }
    function generateCrewPoolLine(line, ID){

        var div1 = new Element("div");
        var div2 = new Element("div", {"id":"CrewPool_" + line.FriendID, "style":"display:none;", "class": CellColour});
        
        var tab1 = new Element("table", {"cellspacing":"0", "cellpadding":"0", "style":"border:0px;font-size:10px;"});
        var bod1 = new Element("tbody");  
        
 
        
        var tr1 = new Element("tr");
        
        var td1 = new Element("td", {"class": CellColour});
        //var cb = new Element("input", {"style":"border:0px;", "type": "checkbox", "name": "FriendID", "id": "FriendID_" + line.FriendID, "value": line.FriendID});
        //td1.insert(cb);
        var td2 = new Element("td", {"class": CellColour, "style":"width:200px;"});
        var Name ="Name";
        if (line.Name.length > 0){Name = line.Name};
        var input7 = new Element("input", {"style":"width:150px;", "type": "text", "name": "FriendName", "id": "FriendName_" + line.FriendID, "value": Name});

        td2.insert(input7);

        var td3 = new Element("td", {"class": CellColour}).update(line.Complete);
        var td4 = new Element("td", {"class": CellColour});
        var a1 = new Element("a", {"href":"javascript:DeleteCrew("+ line.FriendID + ", "+ID+")", "title":"Edit Crew"}).update("Delete");
        var a2 = new Element("a", {"id":"Down_"+ line.FriendID, "href":"javascript:ViewCrew("+ line.FriendID + ")", "title":"View full Details"}).update("View"); 
        var a3 = new Element("a", {"id":"Up_"+ line.FriendID, "style":"display:none", "href":"javascript:HideCrew("+ line.FriendID + ")", "title":"View full Details"}).update("Save"); 
        var a4 = new Element("a", {"href":"javascript:UploadDoc("+ line.FriendID + ")", "title":"upload certificate"}).update("Upload Certificate");
        td4.insert(a1);
        td4.insert("&nbsp;|&nbsp;");
        td4.insert(a2);
        td4.insert(a3);
        td4.insert("&nbsp;|&nbsp;");
         td4.insert(a4);
        tr1.insert(td1);
        tr1.insert(td2);
        tr1.insert(td3);
        tr1.insert(td4);
        
        
        bod1.insert(tr1);
        tab1.insert(bod1);
        
        div1.insert(tab1);
        
        var p1 = new Element("p", {"style":"margin-left:20px;"})
        
        var Address ="Address";
        if (line.Address.length > 0){Address = line.Address}
        var input1 = new Element("input", {"onchange":"EditFriend(" + line.FriendID+")", "style":"width:300px;",  "type": "text", "name": "FriendAddress", "id": "FriendAddress_" + line.FriendID, "value": Address});
        var Telephone ="Telephone";
        if (line.Telephone.length > 0){Telephone = line.Telephone}
        var input2 = new Element("input", {"onchange":"EditFriend(" + line.FriendID+")", "style":"width:300px;", "type": "text", "name": "FriendTelephone", "id": "FriendTelephone_" + line.FriendID, "value": Telephone});
        var Email ="Email";
        if (line.Email.length > 0){Email = line.Email}
        var input3 = new Element("input", {"onchange":"EditFriend(" + line.FriendID+")", "style":"width:300px;", "type": "text", "name": "FriendEmail", "id": "FriendEmail_" + line.FriendID, "value": Email});
        var DOB ="DOB (DD/MM/YYYY)";
        if (line.DOB.length > 0){DOB = line.DOB}
        var input4 = new Element("input", {"onchange":"EditFriend(" + line.FriendID+")", "style":"width:300px;", "type": "text", "name": "FriendDOB", "id": "FriendDOB_" + line.FriendID, "value": DOB, "title": DOB});
        var Nationality ="Nationality";
        if (line.Nationality.length > 0){Nationality = line.Nationality}
        var input5 = new Element("input", {"onchange":"EditFriend(" + line.FriendID+")", "style":"width:300px;", "type": "text", "name": "FriendNationality", "id": "FriendNationality_" + line.FriendID, "value": Nationality});
        var PassportNumber ="Passport Number";
        if (line.PassportNumber.length > 0){PassportNumber = line.PassportNumber}
        var input6 = new Element("input", {"onchange":"EditFriend(" + line.FriendID+")", "style":"width:300px;", "type": "text", "name": "FriendPassportNumber", "id": "FriendPassportNumber_" + line.FriendID, "value": PassportNumber});
        var PassportExpiry ="Passport Expiry";
        if (line.PassportExpiry.length > 0){PassportExpiry = line.PassportExpiry}
        var input8 = new Element("input", {"onchange":"EditFriend(" + line.FriendID+")", "style":"width:300px;", "type": "text", "name": "FriendPassportExpiry", "id": "FriendPassportExpiry_" + line.FriendID, "value": PassportExpiry});
        
        
        div2.insert(input1);
        div2.insert("<br />");
        div2.insert(input2);
        div2.insert("<br />");
        div2.insert(input3);
        div2.insert("<br />");
        div2.insert(input4);
        div2.insert("<br />");
        div2.insert(input5);
        div2.insert("<br />");
        div2.insert(input6);
        div2.insert("<br />");
        div2.insert(input8);
        div2.insert("<br />");
        
        if (CellColour == "alt" ) {
            CellColour = ""
            } else {
            CellColour = "alt"
            } 
                
        $("CrewPool").insert(div1);
        $("CrewPool").insert(div2);
        
        
        var i=1;
        for (i=1;i<=12;i=i+1)
            {
            var op1 = new Element("option", {"value":line.FriendID}).update(line.Name);
            $("crew-"+i+"-id").insert(op1);
            }
        
        $("FriendName_" + line.FriendID).onchange = "EditFriend(" + line.FriendID+")";
        
        
    }

	function manageCrew(ID){
	    bookingID = ID;
		getCrewPool(ID);
		getFlightDetails(ID);
	}

function getFlightDetails(id){
            var data = "";
            data += "&BookingID=" + id;

            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                    if ($("arrivaldate")) {$("arrivaldate").value = data.arrivaldate;};
                    if ($("arrivaltime")) {$("arrivaltime").value = data.arrivaltime;};
                    if ($("arrival-airport")) {$("arrival-airport").value = data.airport;};
                    if ($("arrival-flight")) {$("arrival-flight").value = data.flight;};
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem getting flight details");
                }.bind(this),
                onComplete: function(){
                    
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/getBookingFlightDetails.aspx", ajaxOptions);
    }

var userID = 0;

function getBookings(){
        $("Bookings").update("");
        ajaxOptions = {
            method: "post",
            parameters: {"ClientID": userID},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateBookingLines(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the booking list.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetBookings.aspx", ajaxOptions);
    }
    function generateBookingLines(lineData){
        lineData.each(function(line){
            generateBookingLine(line);
        });
    }
    function generateBookingLine(line){
        var p1 = new Element("p", {"style":"padding-top:0px;margin-top:0px;font-weight:bold;"}).update(line.Yacht + " at " + line.Base + " from " + line.StartDate + " to " + line.EndDate + " ");
        var a1 = new Element("a", {"href":"javascript:manageCrew("+ line.BookingID + ")", "title":"Manage Crew"}).update("Manage Crew");
        var a2 = new Element("a", {"href":"javascript:ViewPDF(1, "+ line.BookingID + ")", "title":"Download Invoice"}).update("Invoice"); 
        var a3 = new Element("a", {"href":"javascript:ViewPDF(2, "+ line.BookingID + ")", "title":"Download Booking Form"}).update("Booking Form");
        var a4 = new Element("a", {"href":"javascript:Feedback("+ line.BookingID + ")", "title":"Review"}).update("Review");
        
        
        var a5 = new Element("a", {"href":line.BaseInfo, "title":"Base Info", "target":"_blank"}).update("Base Info");
        
        var a6 = new Element("a", {"href":line.Contract, "title":"Contract", "target":"_blank"}).update("Contract");
        
        
        p1.insert(a1);
        p1.insert("&nbsp;|&nbsp;");
        p1.insert(a2);
        p1.insert("&nbsp;|&nbsp;");
        p1.insert(a3);
        p1.insert("&nbsp;|&nbsp;");
        
        if (line.BaseInfo.length > 0) {
        p1.insert(a5);
        p1.insert("&nbsp;|&nbsp;");
        }
        if (line.Contract.length > 0) {
        p1.insert(a6);
        p1.insert("&nbsp;|&nbsp;");
        }
        var today = new Date();
        var end = new Date(line.EndDate);
        
        if(end < today)
        {
        p1.insert(a4);
        }
             
        $("Bookings").insert(p1);
        
    }
var InvoiceName = "";

function getUserInfo(id){
            var data = "";
            data += "&userID=" + id;

            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                    if ($("fullname")) {$("fullname").value = data.InvoiceName; InvoiceName = data.InvoiceName};
                    if ($("Address")) {$("Address").value = data.Addressline1;};
                    if ($("County")) {$("County").value = data.County;};
                    if ($("Postcode")) {$("Postcode").value = data.Postcode;};
                    if ($("Country")) {$("Country").value = data.Country;};
                    if ($("Email")) {$("Email").value = data.email;};
                    if ($("DayPhone")) {$("DayPhone").value = data.daytelephone;};
                    if ($("town")) {$("town").value = data.town;};
                    if ($("Password")) {$("Password").value = data.Password;};		        
                    if ($("MyName")) {$("MyName").innerHTML = data.InvoiceName;};
                    if ($("MyLogin")) {$("MyLogin").hide();};
                    if ($("MyDetails")) {$("MyDetails").show();getBookings();};	
                    
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem login");
                }.bind(this),
                onComplete: function(){
                    
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/getUserInfo.aspx", ajaxOptions);
    }

    function forgotten(){
        if(validateForgotten()){
            var data = "";
            data += "&username=" + $("recover").getValue();

            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                   if (data.password != 0) {
                         var Email = "";
                                Email += "&from=" + "registrations@latesail.com"
                                Email += "&to=" + $("recover").getValue();
                                Email += "&CC=" + "";
                                Email += "&BCC=" + "";
                                Email += "&subject=" + "Latesail.com Password Recovery";
                                Email += "&message=" + "<h1>Password Recovery</h1><p>Your Latesail.com password is '" + data.password + "'.</p>";
                                Email += "&attachments=" + "";
                                Email += "&attachmentsPath=" + "";
                                ajaxOptions = {
                                    method: "post",
                                    parameters: Email,
                                    onSuccess: function(transport){
                                        alert("A reminder has been sent to you registered email address");
                                    }.bind(this),
                                    onFailure: function(){
                                        alert("There was a problem sending the email");
                                    }.bind(this),
                                    onComplete: function(){
                                    }.bind(this)
                                };
                                new Ajax.Request("AjaxCalls/Email.aspx", ajaxOptions);
                   } else {
                        var list = $("forgotten-errors");
                        list.update("");
                        generateFormErrorEntry(list, "This email address was not registered");
                        $("forgotten-errors").show();
                   }
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem login");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/recover.aspx", ajaxOptions);
        }else{
            $("forgotten-errors").show();
        }
    }

   function validateForgotten(){
        var valid = true;
        var list = $("forgotten-errors");
        var Email = $("recover").getValue();
        list.update("");
        if(Email.length == 0){valid = false; generateFormErrorEntry(list, "Please enter your email address")}
        return valid;
    }


    function login(){
        if(validateLogin()){
            var data = "";
            data += "&username=" + $("un").getValue();
            data += "&password=" + $("pw").getValue();

            ajaxOptions = {
                method: "post",
                parameters: data,
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                   userID = data.EnquiryID;
                   if (userID.length != 0) {
                        getUserInfo(userID);
                        $("MyLogin").hide();
                        $("MyDetails").show();
                        GetMenu();
                   } else {
                        var list = $("login-errors");
                        list.update("");
                        generateFormErrorEntry(list, "This email address and password are not recognised");
                        $("forgotten-errors").show();
                   }
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem login");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/Login.aspx", ajaxOptions);
        }else{
            $("login-errors").show();
        }
    }
    
function logout(){
            ajaxOptions = {
                method: "post",
                onSuccess: function(transport){
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem login");
                }.bind(this),
                onComplete: function(){
                    window.location = "/Login.aspx";
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/Loginout.aspx", ajaxOptions);
        }
    

   function validateLogin(){
        var valid = true;
        var list = $("login-errors");
        var Email = $("un").getValue();
        var Password = $("pw").getValue();
        list.update("");
        if(Email.length == 0){valid = false; generateFormErrorEntry(list, "Please enter your email address")}
        if(Password.length == 0){valid = false; generateFormErrorEntry(list, "Please enter a password")}
        return valid;
    }

    function generateFormErrorEntry(list, error){
        error = error + "<br />"
        list.insert(error);
    }

    function sendCommand(command){
			$("command").value;
			commandField.value = command;
			document.forms["login-form"].submit();
    }
    
    
    function SaveSearchCriteria(){
        if ($("SortCharterType")) {
            $("SortCharterType").value = $("CharterType").getValue();
        }
    
    
            if(window.MyCurrency != 'undefined' ) {
                MyCurrency = MyCurrency
            } else {MyCurrency = 1}
            
            ajaxOptions = {
                method: "post",
                parameters: {"CharterType": $("CharterType").getValue(), 
                "YachtType": $("YachtType").getValue(),
                "MinyachtSize": $("MinyachtSize").getValue(),
                "MaxyachtSize": $("MaxyachtSize").getValue(),
                "DayFrom": $("DayFrom").getValue(),
                "MonthFrom": $("MonthFrom").getValue(),
                "YearFrom": $("YearFrom").getValue(),
                "DayTo": $("DayTo").getValue(),
                "MonthTo": $("MonthTo").getValue(),
                "YearTo": $("YearTo").getValue(),
                "SearchCurrency": MyCurrency,
                "PriceFrom": $("PriceFrom").getValue(),
                "PriceTo": $("PriceTo").getValue()},            
                onSuccess: function(transport){
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the search criteria.");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EditSearch.aspx", ajaxOptions);
    }
    
    
    function SaveSearchCriteria(){
            if(window.MyCurrency != 'undefined' ) {
                MyCurrency = MyCurrency
            } else {MyCurrency = 1}

            ajaxOptions = {
                method: "post",
                parameters: {"CharterType": $("CharterType").getValue(), 
                "YachtType": $("YachtType").getValue(),
                "MinyachtSize": $("MinyachtSize").getValue(),
                "MaxyachtSize": $("MaxyachtSize").getValue(),
                "DayFrom": $("DayFrom").getValue(),
                "MonthFrom": $("MonthFrom").getValue(),
                "YearFrom": $("YearFrom").getValue(),
                "DayTo": $("DayTo").getValue(),
                "MonthTo": $("MonthTo").getValue(),
                "YearTo": $("YearTo").getValue(),
                "SearchCurrency": MyCurrency,
                "PriceFrom": $("PriceFrom").getValue(),
                "PriceTo": $("PriceTo").getValue()},            
                onSuccess: function(transport){
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem saving the search criteria.");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EditSearch.aspx", ajaxOptions);
    }

    function ChangeOrigin() {

	    //*  part of popupdiv solution *//
		try{ 
            Set_Cookie('CountryofOrigin', $("CountryOrigin").getValue(), '', '/', '', '');
            Set_Cookie('SearchCurrency', $("SetCurrencyHeader").getValue(), '', '/', '', '');
        } catch(err){}
		
	    //*  end part of popupdiv solution *//
		
            ajaxOptions = {
                method: "post",
                parameters: {"CountryOrigin": $("CountryOrigin").getValue() 
                },            
                onSuccess: function(transport){
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem changing your country of origin.");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EditCountryOrigin.aspx", ajaxOptions);
    }
    function ChangeCurrencyCookie(){
            ajaxOptions = {
                method: "post",
                parameters: {"SearchCurrency": $("SetCurrencyHeader").getValue() 
                },            
                onSuccess: function(transport){
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem changing your currency.");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EditCurrencyCookie.aspx", ajaxOptions);
    }
    
    
    function CharterSearch(ID){
        var sPath = window.location.pathname;
        var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);    
    if (sPage == "FullSearch.aspx") {
        $("Order").value = ID;
        $("Search").value = "1";
         $("c").value = MyCurrency;
         
            if(window.MyCurrency) {
                MyCurrency = MyCurrency
            } else {MyCurrency = 1}

            ajaxOptions = {
                method: "post",
                parameters: {"CharterType": $("CharterType").getValue(), 
                "YachtType": $("YachtType").getValue(),
                "MinyachtSize": $("MinyachtSize").getValue(),
                "MaxyachtSize": $("MaxyachtSize").getValue(),
                "DayFrom": $("DayFrom").getValue(),
                "MonthFrom": $("MonthFrom").getValue(),
                "YearFrom": $("YearFrom").getValue(),
                "DayTo": $("DayTo").getValue(),
                "MonthTo": $("MonthTo").getValue(),
                "YearTo": $("YearTo").getValue(),
                "SearchCurrency": MyCurrency,
                "PriceFrom": $("PriceFrom").getValue(),
                "PriceTo": $("PriceTo").getValue()},            
                onSuccess: function(transport){
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem fetching the crew pool.");
                }.bind(this),
                onComplete: function(){
                       GetSearchCharters();
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/EditSearch.aspx", ajaxOptions);
    } else {
        window.location = "/FullSearch.aspx"
    }
        
    }
    
    
function GetSearchCriteriaNew(){
            ajaxOptions = {
                method: "post",
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                   if (data.CharterType.length != 0) {
                        $("CharterType").value = data.CharterType; 
                        $("YachtType").value = data.YachtType; 
                        $("MinyachtSize").value = data.MinyachtSize; 
                        $("MaxyachtSize").value = data.MaxyachtSize; 
                        $("DayFrom").value = data.DayFrom; 
                        $("MonthFrom").value = data.MonthFrom; 
                        $("YearFrom").value = data.YearFrom; 
                        $("DayTo").value = data.DayTo; 
                        $("MonthTo").value = data.MonthTo; 
                        $("YearTo").value = data.YearTo; 
                        $("SearchCurrency").value = data.SearchCurrency; 
                        
                        $("PriceFrom").value = data.PriceFrom;
                        $("PriceTo").value = data.PriceTo;
                        }
                if ($("SortCharterType")) {
                        if(data.CharterType.length > 0) {
                            $("SortCharterType").value  = data.CharterType; 
			                $("SortDate").value = 1;
			            }
                    }
                    GetCountriesNew();
 
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem getting search criteria");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/getSearch.aspx", ajaxOptions);
    }
    
    

    
    function GetSearchCriteria(){
            ajaxOptions = {
                method: "post",
                onSuccess: function(transport){
                   var data = transport.responseText.evalJSON();
                   if (data.CharterType.length != 0) {
                        $("CharterType").value = data.CharterType; 
                        if ($("BareboatTab")) {
                        	switch(data.CharterType)
	                        {
	                            
		                        case "1":
		                            $("BareboatTab").className = "destination-tabs-on";
			                        $("CabinTab").className = "destination-tabs-off";
			                        $("CrewedTab").className = "destination-tabs-off";
			                        $("FlotillaTab").className = "destination-tabs-off";
			                        break;
		                        case "2":
		                            $("BareboatTab").className = "destination-tabs-off";
			                        $("CabinTab").className = "destination-tabs-on";
			                        $("CrewedTab").className = "destination-tabs-off";
			                        $("FlotillaTab").className = "destination-tabs-off";
			                        break;
		                        case "3":
		                            $("BareboatTab").className = "destination-tabs-off";
			                        $("CabinTab").className = "destination-tabs-off";
			                        $("CrewedTab").className = "destination-tabs-on";
			                        $("FlotillaTab").className = "destination-tabs-off";
			                        break;
		                        case "4":
		                            $("BareboatTab").className = "destination-tabs-off";
			                        $("CabinTab").className = "destination-tabs-off";
			                        $("CrewedTab").className = "destination-tabs-off";
			                        $("FlotillaTab").className = "destination-tabs-on";
			                        break;
			                    }
			                    
	                        }
                        
                        GetCountries();
                        
                        $("YachtType").value = data.YachtType; 
                        $("MinyachtSize").value = data.MinyachtSize; 
                        $("MaxyachtSize").value = data.MaxyachtSize; 
                        $("DayFrom").value = data.DayFrom; 
                        $("MonthFrom").value = data.MonthFrom; 
                        $("YearFrom").value = data.YearFrom; 
                        $("DayTo").value = data.DayTo; 
                        $("MonthTo").value = data.MonthTo; 
                        $("YearTo").value = data.YearTo; 
                        $("SearchCurrency").value = data.SearchCurrency; 
                        $("PriceFrom").value = data.PriceFrom;
                        $("PriceTo").value = data.PriceTo;
                        
                   } else {
                      
                        GetCountries();
        var currentTime = new Date()
        var month = currentTime.getMonth() + 1
        var day = currentTime.getDate()
        var year = currentTime.getFullYear()
                   
                   
                        $("DayFrom").value = day; 
                        $("MonthFrom").value = month; 
                        $("YearFrom").value = year; 
                   };
                }.bind(this),
                onFailure: function(){
                    alert("There was a problem getting search criteria");
                }.bind(this),
                onComplete: function(){
                }.bind(this)
            };
            new Ajax.Request("AjaxCalls/getSearch.aspx", ajaxOptions);
    }

    function ViewPerYacht(){
        MyPerPerson = "";
        $("PerPersonCrew").value="";
        $("BackPerYacht1").hide();
        $("BackPerYacht2").hide();
        loadinnerpage();
    }

    function ViewPerPerson(){
        MyPerPerson = $("PerPersonCrew").getValue();
        $("BackPerYacht1").show();
        $("BackPerYacht2").show();
        loadinnerpage();
    }
    function SetCharterCurrencyFlag(){
        SetCurrencyFlag($("SetCurrencyHeader").getValue())
        
    }
    function SetCurrencyFlag(Flag){
    if (IsNumeric(Flag) == true) {
            if ($("SetCurrencyHeader")) {
                $("SetCurrencyHeader").value = Flag;
                ChangeCurrencyCookie();
            };
        
        };
        MyCurrency = Flag;
        loadinnerpage();
    }
    
        function onlinepayment() {
        emailwindow=dhtmlmodal.open('onlinepayment', 'iframe', '/ordering/customerdetails.asp', '', 'width=380px,height=300px,center=1,resize=0,scrolling=0')
        }
    
    function GetMenu(){
        var replaceStr = "?c=" + MyCurrency + "&";
        var p1 = new Element("p");
        var a1 = new Element("a", {"href":"/"+replaceStr, "title":"Special offers from latesail", "tabindex":"1"}).update("Home");
        var a2 = new Element("a", {"href":"/FullSearch.aspx"+replaceStr, "title":"Search", "tabindex":"2"}).update("Search");
        var a3 = new Element("a", {"href":"/how.aspx"+replaceStr, "title":"How it works", "tabindex":"3"}).update("How It Works");
        var a4 = new Element("a", {"href":"/who.aspx"+replaceStr, "title":"Who We Are", "tabindex":"4"}).update("About us");
        var a5 = new Element("a", {"href":"/faq.aspx"+replaceStr, "title":"FAQs", "tabindex":"5"}).update("FAQ's");
        var a6 = new Element("a", {"href":"/plans.aspx"+replaceStr, "title":"Yacht Plans", "tabindex":"6"}).update("Yacht Plans");
        var a7 = new Element("a", {"href":"/getquote.aspx"+replaceStr, "title":"Request a Quote from latesail", "tabindex":"7"}).update("Request a Quote");
        var a8 = new Element("a", {"href":"/contactdetails.aspx"+replaceStr, "title":"Contact latesail", "tabindex":"8"}).update("Contact");
        var a9 = new Element("a", {"href":"/name.aspx"+replaceStr, "title":"Name Your Price", "tabindex":"9"}).update("Name Your Price");
		var a10 = new Element("a", {"href":"/getquote.aspx"+replaceStr, "title":"Request a Quote", "tabindex":"10"}).update("Request a Quote");
        var a11 = new Element("a", {"href":"javascript:onlinepayment()", "title":"Online Payment", "tabindex":"11"}).update("Online Payment");
        var a12 = new Element("a", {"href":"/news2.asp", "title":"News", "tabindex":"12"}).update("News");
		var a13 = new Element("a", {"href":"/top20.aspx", "title":"Top 20", "tabindex":"13"}).update("Top20");//Not Listed
        
        
        if (userID.length > 0 && userID > 0) {
        var a10 = new Element("a", {"href":"/Login.aspx"+replaceStr, "title":"My Details", "tabindex":"10"}).update("My Details");
        } else {
        var a10 = new Element("a", {"href":"/Login.aspx"+replaceStr, "title":"Login", "tabindex":"10"}).update("Login");
        }
        p1.insert(a1);
        p1.insert(" | ");
        p1.insert(a2);
        p1.insert(" | ");
        p1.insert(a3);
        p1.insert(" | ");
        p1.insert(a4);
        p1.insert(" | ");
        p1.insert(a5);
        p1.insert(" | ");
        p1.insert(a6);
        p1.insert(" | ");
        p1.insert(a7);
        p1.insert(" | ");
        p1.insert(a8);
        p1.insert(" | ");
        p1.insert(a9);
        p1.insert(" | ");
		
        p1.insert(a11);
        p1.insert(" | ");
        p1.insert(a12);
        p1.insert(" | ");
        p1.insert(a10);
		
        
 
        
        $("menu").update(p1);

        
        var h1 = new Element("h1").update(PageDesc);
        
        
        //$("PageName").update(h1);
        //$("PageBanner").style.backgroundImage = "url("+PageName+")";
   
     
   
        var SearchCurrency = "&pound;"
        var CurrentCurrency = "UK Pounds Sterling";
        if (MyCurrency == 1) {
            SearchCurrency = "&pound;";
            CurrentCurrency = "UK Pounds sterling";
        }
        if (MyCurrency == 2) {
            SearchCurrency = "US$";
            CurrentCurrency = "US dollars";
        }
        if (MyCurrency == 3) {
            SearchCurrency = "Euro";
            CurrentCurrency = "Euros";
        }
        if (MyCurrency == 4) {
            SearchCurrency = "AUS$";
            CurrentCurrency = "Australian dollars";
        }
        if (MyCurrency == 5) {
            SearchCurrency = "CAN$";
            CurrentCurrency = "Canadian dollars";
        }
        
     
        
        if ($("SearchCurrency")) {
        $("SearchCurrency").update(SearchCurrency);
        }
        
        if ($("CurrentCurrency")) {
        $("CurrentCurrency").innerHTML = (CurrentCurrency);
        }

    }
var SortIcon = 0;
var SortList = "";

function ViewCharterSort(List){
var ID = "img_" + List;
if (SortIcon.length > 0) {
   $(SortIcon).src = "/images/open.png";
}
if (SortIcon != ID) {
SortIcon = ID;
$(SortIcon).src = "/images/close.png";
} else {
SortIcon = "";
}

if (SortList.length > 0) {
   Effect.BlindUp($(SortList));
}
if (SortList != List) {
SortList = List;
Effect.BlindDown($(SortList));
} else {
SortList = "";
}
}


function GetCountriesNew(){
        if ($("CharterType")) {
            $("CharterType").value = $("SortCharterType").getValue();
            SaveSearchCriteria();
        }
        var SortDate = $("SortDate").getValue();
        ajaxOptions = {
            method: "post",
            parameters: {"Code": MyCountryCode, "CharterType": $("SortCharterType").getValue(), "DateRange": SortDate},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                var replaceStr = "?c=" + MyCurrency + "&";
                $("ChartersByCountry").update(data.Body.replace(/\?/gi,replaceStr));
                
                var MySortList = "";
                
                
                if (SortList.length > 0) {MySortList = SortList;} else {MySortList = "Caribbean";};
                SortList = "";
                SortIcon = 0;
                ViewCharterSort(MySortList);
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the country list A.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetCountryList2.aspx", ajaxOptions);
    }
 
 
    function GetCountries(){
        ajaxOptions = {
            method: "post",
            parameters: {"Code": MyCountryCode, "CharterType": $("CharterType").getValue()},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                var replaceStr = "?c=" + MyCurrency + "&";
                $("ChartersByCountry").update(data.Body.replace(/\?/gi,replaceStr));
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the country list B.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetCountryList.aspx", ajaxOptions);
    }
    function GetFileContents(){
    
    if (MyFile.length != 0) {
        var CountryCode = "GB";
        if (MyCountryCode == "US" || MyCountryCode == "CA") {
            CountryCode = "US";
        }
        ajaxOptions = {
            method: "get",
            onSuccess: function(transport){
                var data = transport.responseText;
                
                $("EditContent").update(data);    
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the file.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("content/"+CountryCode+"/"+MyFile, ajaxOptions);
        }
    }
    function GetSearch(){
        var i=0;
        var currentTime = new Date()
        var month = currentTime.getMonth() + 1
        var day = currentTime.getDate()
        var year = currentTime.getFullYear()

        // yacht size from
        var op1 = new Element("option", {"value":"0"}).update("Any");
        $("MinyachtSize").update(op1);
        i=27;
        for (i=27;i<=65;i=i+2)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("MinyachtSize").insert(op1);
            }
        var op1 = new Element("option", {"value":"66"}).update("Over 65");
        $("MinyachtSize").insert(op1);
        // yacht size to
        var op1 = new Element("option", {"value":"999"}).update("Any");
        $("MaxyachtSize").update(op1);
        i=27;
        for (i=27;i<=65;i=i+2)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("MaxyachtSize").insert(op1);
            }
        var op1 = new Element("option", {"value":"66"}).update("Over 65");
        $("MaxyachtSize").insert(op1);
        // Day from
        $("DayFrom").update("");
        i=1;
        for (i=1;i<=31;i=i+1)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("DayFrom").insert(op1);
            }
        $("DayFrom").value = day;
        
        // Day to
        $("DayTo").update("");
        i=1;
        for (i=1;i<=31;i=i+1)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("DayTo").insert(op1);
            }
            $("DayTo").value = day;
         // Year from
        $("YearFrom").update("");
        i=2011;
        for (i=2011;i<=2012;i=i+1)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("YearFrom").insert(op1);
            }
        $("YearFrom").value = year;
        
         // Year to
        $("YearTo").update("");
        i=2011;
        for (i=2011;i<=2012;i=i+1)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("YearTo").insert(op1);
            }
            $("YearTo").value = year;
        // Price from
        var op1 = new Element("option", {"value":"0"}).update("Any");
        $("PriceFrom").update(op1);
        i=250;
        for (i=250;i<=10000;i=i+50)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("PriceFrom").insert(op1);
            }
        // Price to
        var op1 = new Element("option", {"value":"10000"}).update("Any");
        $("PriceTo").update(op1);
        i=250;
        for (i=250;i<=10000;i=i+50)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("PriceTo").insert(op1);
            }
        $("MonthFrom").value = month;
        $("MonthTo").value = month+1;
            
    GetSearchCriteria();
            
            
            
            
            
    }
    
    
    function GetSearchNew(){
        var i=0;
        var currentTime = new Date()
        var month = currentTime.getMonth() + 1
        var day = currentTime.getDate()
        var year = currentTime.getFullYear()

        // yacht size from
        var op1 = new Element("option", {"value":"0"}).update("Any");
        $("MinyachtSize").update(op1);
        i=27;
        for (i=27;i<=65;i=i+2)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("MinyachtSize").insert(op1);
            }
        var op1 = new Element("option", {"value":"66"}).update("Over 65");
        $("MinyachtSize").insert(op1);
        // yacht size to
        var op1 = new Element("option", {"value":"999"}).update("Any");
        $("MaxyachtSize").update(op1);
        i=27;
        for (i=27;i<=65;i=i+2)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("MaxyachtSize").insert(op1);
            }
        var op1 = new Element("option", {"value":"66"}).update("Over 65");
        $("MaxyachtSize").insert(op1);
        // Day from
        $("DayFrom").update("");
        i=1;
        for (i=1;i<=31;i=i+1)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("DayFrom").insert(op1);
            }
        $("DayFrom").value = day;
        
        // Day to
        $("DayTo").update("");
        i=1;
        for (i=1;i<=31;i=i+1)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("DayTo").insert(op1);
            }
            $("DayTo").value = day;
         // Year from
        $("YearFrom").update("");
        i=2011;
        for (i=2011;i<=2012;i=i+1)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("YearFrom").insert(op1);
            }
        $("YearFrom").value = year;
        
         // Year to
        $("YearTo").update("");
        i=2011;
        for (i=2011;i<=2012;i=i+1)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("YearTo").insert(op1);
            }
            $("YearTo").value = year;
        // Price from
        var op1 = new Element("option", {"value":"0"}).update("Any");
        $("PriceFrom").update(op1);
        i=250;
        for (i=250;i<=10000;i=i+50)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("PriceFrom").insert(op1);
            }
        // Price to
        var op1 = new Element("option", {"value":"10000"}).update("Any");
        $("PriceTo").update(op1);
        i=250;
        for (i=250;i<=10000;i=i+50)
            {
            var op1 = new Element("option", {"value":i}).update(i);
            $("PriceTo").insert(op1);
            }
        $("MonthFrom").value = month;
        $("MonthTo").value = month+1;
            
    GetSearchCriteriaNew();
            
            

            
    }
    
    
    
    function GetIps(){


        ajaxOptions = {
            method: "post",
            onSuccess: function(transport) {

                if (TestUSA) {
                    MyCountryCode = "US";
                    MyCountryName = "UNITED STATES";
                    MyCurrency = "2";
                } else {

                    var data = transport.responseText.evalJSON();
                    //alert(data.Code);
                    if (data.Code) { MyCountryCode = data.Code; }
                    if (data.Country) { MyCountryName = data.Country; }
                    if (data.Country) { MyCurrency = data.Currency; }


                }

                if (MyCountryCode == "US") {
                    MyCurrency = "2";
                };
                if (MyCountryCode == "CA") {
                    MyCurrency = "5";
                };
                if (MyCountryCode == "") {
                    MyCountryCode = "GB";
                    MyCurrency = "1";
                };

                if (MyCurrency == "") {
                    MyCurrency = "1";
                    SetCurrencyFlag('1');
                } else {
                    SetCurrencyFlag(MyCurrency);
                };
                if ($("CountryOrigin")) {
                    $("CountryOrigin").value = MyCountryCode;
                }
                if ($("SetCurrencyHeader")) {
                    $("SetCurrencyHeader").value = MyCurrency;
                }


				//* country areapopup div by Otto 17/01/2012 */
				//* 
				//* the next part will try to show/hide the country/marketArea selection popup div  base on the cookie called CountryAreaPopup
				//*
								
                /*     (Get_Cookie('CountryAreaPopup')) ? alert(Get_Cookie('already set CountryAreaPopup, so not showing again.')) :
						alert('CountryAreaPopup show, no cookie is set. (first time or cookie deleted)');
                */

               
			   try
			   {
                if (Get_Cookie('CountryAreaPopup')) {
                    if (Get_Cookie('CountryofOrigin'))
                        $("CountryMarketAreaPopup").hide();
                    else
                        $("CountryMarketAreaPopup").show();
                }
                else
				{
                    $("CountryMarketAreaPopup").show();
				}
				$("detected_countryCode").innerHTML=$("CountryOrigin").value;

				
				}catch (err)
				{ //* try catch is needed to not break the site pages where CountryMarketAreaPopup div doesn't exist *//
				}
				
				
                loadpage();

            } .bind(this),
            onFailure: function() {
                MyCountryCode = "GB";
                MyCurrency = "1";
                //alert("There was a problem fetching the country IP.");
				loadpage();
            } .bind(this),
            onComplete: function() {
                if ($("mode")) {
                    $("mode").value = MyCountryCode;

                }
            } .bind(this)
        };
        new Ajax.Request("AjaxCalls/GetIP.aspx", ajaxOptions);
    }
function GetYachtPlans(){
        $("EditContent").update("");
        ajaxOptions = {
            method: "post",
            parameters: {"Code": MyCountryCode, "Currency":MyCurrency},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateYachtPlanLines(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the yacht plans.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetYachtPlans.aspx", ajaxOptions);
    }
    function generateYachtPlanLines(lineData){
        lineData.each(function(line){
            generateYachtPlanLine(line);
        });
    }
    var strPreviousYachtType = ""
    function generateYachtPlanLine(line){  
        if (line.YachtType != strPreviousYachtType) {
            var h2 = new Element("h2", {"style":"clear:both;"}).update(line.YachtType);
            $("EditContent").insert(h2);
        }
        var div1 = new Element("div", {"class":"yachtlist"});
        var a1 = new Element("a", {"href":"javaScript:openWindow('yachtpopup.asp?id="+ line.YachtID + "')", "title":"yacht details"}).update(line.YachtName);
        
	    strPreviousYachtType = line.YachtType
    
    
     
        div1.insert(a1);
                
        $("EditContent").insert(div1);
        
    }

var CellColour = "#C7D1D7";
function GetSpecialOffers(){
        $("CharterSpecialOffers").update("");
        ajaxOptions = {
            method: "post",
            parameters: {"Code": MyCountryCode, "Currency":MyCurrency},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateSpecialOfferLines(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the special offers.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetSpecialOffers.aspx", ajaxOptions);
    }
function GetTop20Offers(){
        $("CharterSpecialOffers").update("");
        ajaxOptions = {
            method: "post",
            parameters: {"Code": MyCountryCode, "Currency":MyCurrency},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateSpecialOfferLines(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the special offers.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetTop20Offers.aspx", ajaxOptions);
    }
    function generateSpecialOfferLines(lineData){
        lineData.each(function(line){
            generateSpecialOfferLine(line);
        });
    }
    function generateSpecialOfferLine(line){ 
    var thisFullPrice = 0;
    var thisOfferPrice = 0; 
    var thisPerson = 0;
        var a1 = new Element("a", {"href":"CruiseDetail.aspx?CruiseID="+ line.CruiseID, "title":"Click to view details about this charter"});
        var div1 = new Element("div", {"class":"ResultLine", "style":"background-color:" + CellColour + ";"});
            var div2 = new Element("div", {"class":"ResultLocation"}).update(line.CountryName);
            var div3 = new Element("div", {"class":"ResultBase"}).update(line.Base);
            var div4 = new Element("div", {"class":"ResultYacht"});
            var a2 = new Element("a", {"href":"javaScript:openWindow('yachtpopup.asp?id="+ line.YachtID + "')", "title":"yacht details"}).update(line.YachtName);
            div4.insert(a2)
            var div5 = new Element("div", {"class":"ResultStart"}).update(line.StartDate);
            var div6 = new Element("div", {"class":"ResultEnd"}).update(line.EndDate);
            var div7 = new Element("div", {"class":"ResultDays"}).update(line.NoDays);
            var div8 = new Element("div", {"class":"ResultType"});
            var div11 = new Element("div", {"class":"ResultDiscount"}).update(line.Difference + "%");
        var MyPerPersonshow = false;
        var MyPlane = false;
        if (MyPerPerson > 0) {
            if (line.PerPerson > 0) {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0) + "pp";
                thisPerson = line.PerPerson;
                MyPerPersonshow = true;
                MyPlane = true;
            } else {
                thisFullPrice = parseFloat(line.FullPrice/MyPerPerson).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice/MyPerPerson).toFixed(0) + "pp";
                thisPerson = MyPerPerson;
                MyPerPersonshow = true;
            }
        } else {
            if (line.PerPerson > 0) {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0) + "pp";
                thisPerson = line.PerPerson;
                MyPerPersonshow = true;
                MyPlane = true;
            } else {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0);
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0);
                thisPerson = 0;
                MyPerPersonshow = false;
            }
        };
        
            var div9 = new Element("div", {"class":"ResultPrice"}).update(line.currencyChar + '' + thisFullPrice);
            var div10 = new Element("div", {"class":"ResultOffer"}).update(line.currencyChar + '' + thisOfferPrice);
        
        var div21 = new Element("div", {"class":"PerPersonNumber", "title":"Price per person based on " +thisPerson+ " people sharing"}).update("  x "+thisPerson);
        var div23 = new Element("div", {"class":"PerYachtNumber", "title":"Price per yacht"}).update("");
        var div25 = new Element("div", {"class":"Plane", "title":"Price includes flights"}).update("");
        
        if (MyPerPersonshow) {
        div8.insert(div21);
            if (MyPlane) {
            div8.insert(div25);
            }
        } else {
        div8.insert(div23);
        }        
        div1.insert(div2);
        div1.insert(div3);
        div1.insert(div4);
        div1.insert(div5);
        div1.insert(div6);
        div1.insert(div7);
        div1.insert(div8);
        div1.insert(div9);
        div1.insert(div10);
        div1.insert(div11);
        a1.insert(div1);
        $("CharterSpecialOffers").insert(a1);
        
        
       if (CellColour == "#C7D1D7" ) {
            CellColour = "#E1E5E8"
            } else {
            CellColour = "#C7D1D7"
            }  
    }
function GetSearchCharters(){
        $("Charters").update("");
        //var MyOrder = qs.Order;
        var MyOrder = "FullPrice";
        
         if(MyCurrency != 'undefined' ) {
                MyCurrency = MyCurrency
            } else {MyCurrency = 1}
        
        if (qs.Order) {MyOrder = qs.Order}
        if ($("Order").getValue().length > 0 ) {MyOrder = $("Order").getValue()}
        ajaxOptions = {
            method: "post",
            parameters: {
            "CharterType": $("CharterType").getValue(),
            "Code": MyCountryCode, 
            "Currency":MyCurrency,
            "Order": MyOrder,
            "YachtType":$("YachtType").getValue(),
            "MinYachtSize":$("MinyachtSize").getValue(),
            "MaxYachtSize":$("MaxyachtSize").getValue(),
            "DayFrom":$("DayFrom").getValue(),
            "MonthFrom":$("MonthFrom").getValue(),
            "YearFrom":$("YearFrom").getValue(),
            "DayTo":$("DayTo").getValue(),
            "MonthTo":$("MonthTo").getValue(),
            "YearTo":$("YearTo").getValue(),
            "PriceFrom":$("PriceFrom").getValue(),
            "PriceTo":$("PriceTo").getValue()
            },
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateSearchCharterLines(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the charters.");
            }.bind(this),
            onComplete: function(){
                location.href = "#SearchResultArea";
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetSearchCharters.aspx", ajaxOptions);
    }
    function generateSearchCharterLines(lineData){
        lineData.each(function(line){
            generateSearchCharterLine(line);
        });
    }
    function generateSearchCharterLine(line){ 
    var thisFullPrice = 0;
    var thisOfferPrice = 0; 
    var thisPerson = 0;
        var a1 = new Element("a", {"href":"CruiseDetail.aspx?CruiseID="+ line.CruiseID, "title":"Click to view details about this charter"});
        var div1 = new Element("div", {"class":"ResultLine", "style":"background-color:" + CellColour + ";"});
            var div2 = new Element("div", {"class":"ResultLocation"}).update(line.CountryName);
            var div3 = new Element("div", {"class":"ResultBase"}).update(line.Base);
            var div4 = new Element("div", {"class":"ResultYacht"});
            var a2 = new Element("a", {"href":"javaScript:openWindow('yachtpopup.asp?id="+ line.YachtID + "')", "title":"yacht details"}).update(line.YachtName);
            div4.insert(a2)
            var div5 = new Element("div", {"class":"ResultStart"}).update(line.StartDate);
            var div6 = new Element("div", {"class":"ResultEnd"}).update(line.EndDate);
            var div7 = new Element("div", {"class":"ResultDays"}).update(line.NoDays);
            var div8 = new Element("div", {"class":"ResultType"});
            var div11 = new Element("div", {"class":"ResultDiscount"}).update(line.Discount + "%");
        var MyPerPersonshow = false;
        var MyPlane = false;
        if (MyPerPerson > 0) {
            if (line.PerPerson > 0) {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0) + "pp";
                thisPerson = line.PerPerson;
                MyPerPersonshow = true;
                MyPlane = true;
            } else {
                thisFullPrice = parseFloat(line.FullPrice/MyPerPerson).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice/MyPerPerson).toFixed(0) + "pp";
                thisPerson = MyPerPerson;
                MyPerPersonshow = true;
            }
        } else {
            if (line.PerPerson > 0) {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0) + "pp";
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0) + "pp";
                thisPerson = line.PerPerson;
                MyPerPersonshow = true;
                MyPlane = true;
            } else {
                thisFullPrice = parseFloat(line.FullPrice).toFixed(0);
                thisOfferPrice = parseFloat(line.OfferPrice).toFixed(0);
                thisPerson = 0;
                MyPerPersonshow = false;
            }
        };
        
            var div9 = new Element("div", {"class":"ResultPrice"}).update(line.currencyChar + '' + thisFullPrice);
            var div10 = new Element("div", {"class":"ResultOffer"}).update(line.currencyChar + '' + thisOfferPrice);
        
        var div21 = new Element("div", {"class":"PerPersonNumber", "title":"Price per person based on " +thisPerson+ " people sharing"}).update("  x "+thisPerson);
        var div23 = new Element("div", {"class":"PerYachtNumber", "title":"Price per yacht"}).update("");
        var div25 = new Element("div", {"class":"Plane", "title":"Price includes flights"}).update("");
        
        if (MyPerPersonshow) {
        div8.insert(div21);
            if (MyPlane) {
            div8.insert(div25);
            }
        } else {
        div8.insert(div23);
        }        
        div1.insert(div2);
        div1.insert(div3);
        div1.insert(div4);
        div1.insert(div5);
        div1.insert(div6);
        div1.insert(div7);
        div1.insert(div8);
        div1.insert(div9);
        div1.insert(div10);
        div1.insert(div11);
        a1.insert(div1);
        $("Charters").insert(a1);
        
        
       if (CellColour == "#C7D1D7" ) {
            CellColour = "#E1E5E8"
            } else {
            CellColour = "#C7D1D7"
            } 

        
    }



function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=549,height=550,left = 740,top = 425');");
}

function openWindow(url)
	{
		popUp = window.open(url, "popUp", 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=yes,resizable=yes,width=440,height=600');
	}

var aryImages = new Array(2);

  aryImages[0] = "../img/bullet2.gif";

  for (i=0; i < aryImages.length; i++) {
    var preload = new Image();
    preload.src = aryImages[i];
  }

function swap(imgMain)
	{
	eval("document.all." + imgMain + ".src = aryImages[0]");
	}



	function SendEmail()
	{
		frm.command.value = "RequestEmail";
		frm.submit();
	}


function ApplyNow(pstrID, pstrEmail)
	{
	frm.action = "Register.asp"
	frm.JobReference.value = pstrID;
	frm.JobEmail.value = pstrEmail;
	frm.submit();
	}
function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789" + comma + period + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 2;
var allNum = "";

for (i = 0;  i < checkStr.value.length;  i++)
{
ch = checkStr.value.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{	
alertsay = "Please enter only these values \""
alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}

// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseInt(allNum);
if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
{
alertsay = "Please enter a value greater than or "
alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}
}

function checkValueValid (){
	var tt = document.getElementById("Sacrifice_Option_" + x)
	y = tt.value;
	if (y == "") {
		checkNumeric (myElement,0,0,',','.','-')
	}
	if (y == "112") {
		checkNumeric (myElement,0,200,',','.','-')
	}
	if (y == "113") {
		checkNumeric (myElement,0,99.99,',','.','-')
	}
	if (y == "115") {
		checkNumeric (myElement,0.01,25,',','.','-')
	}
	if (y == "198") {
		checkNumeric (myElement,0,0,',','.','-')
	}
	if (y == "114") {
		checkNumeric (myElement,0,100000,',','.','-')
	}
}
var myElement
myElement = ''
function SaveID (obj){
	myElement = obj;
}
function loadcontent()
{
$("newcontent").update($("content").innerHTML);
$("content").update("");
}




var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=275,width=400');
	if (window.focus) {newwindow.focus()}
}

function DestDetails(idPrefix, sectionName)
{
    if ($("CountryCharterResults")) {
    var CharterList = document.getElementById(idPrefix + "CountryCharterResults");
    } else {
    var CharterList = document.getElementById(idPrefix + "CharterDetail");
    }
        
	var SailingConditions = document.getElementById(idPrefix + "SailingConditions");
	var Travelnotes = document.getElementById(idPrefix + "Travelnotes");
	var Itinerary = document.getElementById(idPrefix + "Itinerary");
	var Map = document.getElementById(idPrefix + "Map");

    var ChartersTab = document.getElementById(idPrefix + "AChartersTab");
	var SailingTab = document.getElementById(idPrefix + "ASailingTab");
	var NotesTab = document.getElementById(idPrefix + "ANotesTab");
	var ItineraryTab = document.getElementById(idPrefix + "AItineraryTab");
	var MapTab = document.getElementById(idPrefix + "AMapTab");

	switch(sectionName)
	{
		case "Charters":
		    CharterList.style.display = "block";
			SailingConditions.style.display = "none";
			Travelnotes.style.display = "none";
			Itinerary.style.display = "none";
			Map.style.display = "none";

            ChartersTab.className = "destination-tabs-on"
			SailingTab.className = "destination-tabs-off"
			NotesTab.className = "destination-tabs-off"
			ItineraryTab.className = "destination-tabs-off"
			MapTab.className = "destination-tabs-off"
			break;
		case "SailingConditions":
		    CharterList.style.display = "none";
			SailingConditions.style.display = "block";
			Travelnotes.style.display = "none";
			Itinerary.style.display = "none";
			Map.style.display = "none";

            ChartersTab.className = "destination-tabs-off"
			SailingTab.className = "destination-tabs-on"
			NotesTab.className = "destination-tabs-off"
			ItineraryTab.className = "destination-tabs-off"
			MapTab.className = "destination-tabs-off"
			break;
		case "Travelnotes":
		    CharterList.style.display = "none";
			SailingConditions.style.display = "none";
			Travelnotes.style.display = "block";
			Itinerary.style.display = "none";
			Map.style.display = "none";

            ChartersTab.className = "destination-tabs-off"
			SailingTab.className = "destination-tabs-off"
			NotesTab.className = "destination-tabs-on"
			ItineraryTab.className = "destination-tabs-off"
			MapTab.className = "destination-tabs-off"
			break;
		case "Itinerary":
		    CharterList.style.display = "none";
			SailingConditions.style.display = "none";
			Travelnotes.style.display = "none";
			Itinerary.style.display = "block";
			Map.style.display = "none";

            ChartersTab.className = "destination-tabs-off"
			SailingTab.className = "destination-tabs-off"
			NotesTab.className = "destination-tabs-off"
			ItineraryTab.className = "destination-tabs-on"
			MapTab.className = "destination-tabs-off"
			break;
		case "Map":
		    CharterList.style.display = "none";
			SailingConditions.style.display = "none";
			Travelnotes.style.display = "none";
			Itinerary.style.display = "none";
			Map.style.display = "block";

            ChartersTab.className = "destination-tabs-off"
			SailingTab.className = "destination-tabs-off"
			NotesTab.className = "destination-tabs-off"
			ItineraryTab.className = "destination-tabs-off"
			MapTab.className = "destination-tabs-on"
			break;
	}
}


function MoreDetails(sectionName)
{
        
	var CharterDetail = document.getElementById("CharterDetail");
	var YachtDetail = document.getElementById("YachtDetail");
	var DestinationDetail = document.getElementById("DestinationDetail");
	var Map = document.getElementById("Map");

    var ATab = document.getElementById("AMoreTab");
	var BTab = document.getElementById("AYachtTab");
	var CTab = document.getElementById("ADestinationTab");
	var DTab = document.getElementById("AMapTab");

	switch(sectionName)
	{
		case "More":
		    CharterDetail.style.display = "block";
			YachtDetail.style.display = "none";
			DestinationDetail.style.display = "none";
			Map.style.display = "none";

            ATab.className = "destination-tabs-on"
			BTab.className = "destination-tabs-off"
			CTab.className = "destination-tabs-off"
			DTab.className = "destination-tabs-off"
			break;
		case "Spec":
		    CharterDetail.style.display = "none";
			YachtDetail.style.display = "block";
			DestinationDetail.style.display = "none";
			Map.style.display = "none";

            ATab.className = "destination-tabs-off"
			BTab.className = "destination-tabs-on"
			CTab.className = "destination-tabs-off"
			DTab.className = "destination-tabs-off"
			break;
		case "Destination":
		    CharterDetail.style.display = "none";
			YachtDetail.style.display = "none";
			DestinationDetail.style.display = "block";
			Map.style.display = "none";

            ATab.className = "destination-tabs-off"
			BTab.className = "destination-tabs-off"
			CTab.className = "destination-tabs-on"
			DTab.className = "destination-tabs-off"
			break;
		case "Map":
		    CharterDetail.style.display = "none";
			YachtDetail.style.display = "none";
			DestinationDetail.style.display = "none";
			Map.style.display = "block";

            ATab.className = "destination-tabs-off"
			BTab.className = "destination-tabs-off"
			CTab.className = "destination-tabs-off"
			DTab.className = "destination-tabs-on"
			break;
	}
}

function CharterTypeChange(sectionName)
{
        ajaxOptions = {
            method: "post",
            parameters: {"CharterType": sectionName},            
            onSuccess: function(transport){
            }.bind(this),
            onFailure: function(){
                alert("There was a problem.");
            }.bind(this),
            onComplete: function(){
                $("CharterType").value = sectionName;
                GetCountries();
                SaveSearchCriteria()
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/EditCharterType.aspx", ajaxOptions);
        

	switch(sectionName)
	{
		case 1:
		    $("BareboatTab").className = "destination-tabs-on";
			$("CabinTab").className = "destination-tabs-off";
			$("CrewedTab").className = "destination-tabs-off";
			$("FlotillaTab").className = "destination-tabs-off";
			break;
		case 2:
		    $("BareboatTab").className = "destination-tabs-off";
			$("CabinTab").className = "destination-tabs-on";
			$("CrewedTab").className = "destination-tabs-off";
			$("FlotillaTab").className = "destination-tabs-off";
			break;
		case 3:
		    $("BareboatTab").className = "destination-tabs-off";
			$("CabinTab").className = "destination-tabs-off";
			$("CrewedTab").className = "destination-tabs-on";
			$("FlotillaTab").className = "destination-tabs-off";
			break;
		case 4:
		    $("BareboatTab").className = "destination-tabs-off";
			$("CabinTab").className = "destination-tabs-off";
			$("CrewedTab").className = "destination-tabs-off";
			$("FlotillaTab").className = "destination-tabs-on";
			break;
	}
	
}

function HomepageCharterSort()
{
    var sectionName = 1;
    if 	($("SortBareboat").checked == true) {
        sectionName = 1;
    };
    if 	($("SortCabin").checked == true) {
        sectionName = 2;
    };
    if 	($("SortCrewed").checked == true) {
        sectionName = 3;
    };
    if 	($("SortFlotilla").checked == true) {
        sectionName = 4;
    };
    ajaxOptions = {
            method: "post",
            parameters: {"CharterType": sectionName},            
            onSuccess: function(transport){
            }.bind(this),
            onFailure: function(){
                alert("There was a problem.");
            }.bind(this),
            onComplete: function(){
                $("CharterType").value = sectionName;
                GetCountriesNew();
                SaveSearchCriteria()
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/EditCharterType.aspx", ajaxOptions);
}





function SetRating (type, id, BookingID)
{
ajaxOptions = {
            method: "post",
            parameters: {"Type": type, "Rating": id, "BookingID": BookingID},            
            onSuccess: function(transport){
            }.bind(this),
            onFailure: function(){
                alert("There was a problem.");
            }.bind(this),
            onComplete: function(){
                loadstars(type, id, BookingID)
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/EditFeedbackrating.aspx", ajaxOptions);
}

function loadstars (type, id, BookingID)
{

var ImagePath = "";
var i=1;
if (type == 1) // destination
{
$("DestinationStars").update("");
    for (i=1;i<=5;i++)
    {
        if (id >= i) {
        ImagePath = "/images/star1.gif";
        } else {
        ImagePath = "/images/star3.gif";
        }
        var img1 = new Element("img", {"src":ImagePath, "title":"Set rating to "+i+"/5", "style":"cursor:pointer;border:0px;"});
        var a1 = new Element("a", {"href":"javascript:SetRating("+type+", "+i+", "+BookingID+")","title":"Set rating to "+i+"/5"});
        a1.insert(img1);
        $("DestinationStars").insert(a1);
    }
}
if (type == 2) // destination
{
$("YachtStars").update("");
    for (i=1;i<=5;i++)
    {
        if (id >= i) {
        ImagePath = "/images/star1.gif";
        } else {
        ImagePath = "/images/star3.gif";
        }
        var img1 = new Element("img", {"src":ImagePath, "title":"Set rating to "+i+"/5", "style":"cursor:pointer;border:0px;"});
        var a1 = new Element("a", {"href":"javascript:SetRating("+type+", "+i+", "+BookingID+")","title":"Set rating to "+i+"/5"});
        a1.insert(img1);
        $("YachtStars").insert(a1);
    }
}

}

function Feedback(ID){
        $("MyFeedback").update("");
        var p1 = new Element("p").update("Please use the following section to provide feedback on the destination and the boat type chartered for future users, which will be published on our website. We would be grateful if you could keep the reviews specific to the characteristics of the yacht type chartered, and not any particulars of the exact boat supplied, as obviously standards and equipment levels vary from boat to boat dependent on age, and operator etc . . .");
        var p2 = new Element("p").update("Please note that comments relating to the specific boat will be edited. Also please note that we do value your feedback for the charter experience received, and ask you to complete an after charter questionnaire on completion of your charter in which we invite you to share with us as much detail as possible of your experience. The charter questionnaires however are not published.");
        $("MyFeedback").insert(p1);
        $("MyFeedback").insert(p2);
        $("MyFeedback").hide();
        $("MyDetails").hide();
        ajaxOptions = {
            method: "post",
            parameters: {"BookingID": ID},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateFeedback(data)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the special offers.");
            }.bind(this),
            onComplete: function(){
            
            $("MyFeedback").show();
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/GetBookingFeedback.aspx", ajaxOptions);
    }
    function generateFeedback(lineData){
        lineData.each(function(line){
            generateFeedbackLine(line);
        });
    }
    function generateFeedbackLine(line){
        if (line.CountryName.Length > 0 ){
        var h1 = new Element("h2").update("Destination ("+line.CountryName+") Review");
        } else {
        var h1 = new Element("h2").update("Destination Review");
        }
        var tab1 = new Element("table", {"cellspacing":"0", "cellpadding":"0", "style":"border:0px;"});
        
        var bod1 = new Element("tbody");  
        var bod2 = new Element("tbody"); 
        
        if (line.YachtName.Length > 0 ){
        var h2 = new Element("h2").update("Yacht ("+line.YachtName+") Review");
        } else {
        var h2 = new Element("h2").update("Yacht Review");
        }
        var tab2 = new Element("table", {"cellspacing":"0", "cellpadding":"0", "style":"border:0px;"});
        
        var tr1 = new Element("tr");
        var tr2 = new Element("tr");
        var tr3 = new Element("tr");
        var tr4 = new Element("tr");
        
        var a1 = new Element("a", {"href":"javascript:CloseFeedback("+line.BookingID+")","title":"save review"}).update("Save Review");
        
        
        var td1 = new Element("td", {"style":"width:130px;"}).update("Rating:");
        var td2 = new Element("td", {"style":"width:110px;", "id":"YachtStars"});

        
        var td3 = new Element("td", {"style":"width:130px;"}).update("Comments:");
        var td4 = new Element("td", {"style":"width:300px;"});
        var inp1 = new Element("textarea", {"id":"YachtDescript", "style":"", "onchange":"SaveFeedback("+line.BookingID+")"}).update(line.YachtDescript);
        
        td4.insert(inp1);
        
        var td5 = new Element("td", {"style":"width:130px;"}).update("Rating:");
        var td6 = new Element("td", {"style":"width:200px;", "id":"DestinationStars"});
       
        var td7 = new Element("td", {"style":"width:130px;"}).update("Comments:");
        var td8 = new Element("td", {"style":"width:300px;"});
        var inp2 = new Element("textarea", {"id":"DestinationDescript", "style":"", "onchange":"SaveFeedback("+line.BookingID+")"}).update(line.DestinationDescript);
        
        td8.insert(inp2);
        tr1.insert(td1);
        tr1.insert(td2);
        tr2.insert(td3);
        tr2.insert(td4);
        tr3.insert(td5);
        tr3.insert(td6);
        tr4.insert(td7);
        tr4.insert(td8);
        bod1.insert(tr1);
        bod1.insert(tr2);
        bod2.insert(tr3);
        bod2.insert(tr4);
        
        tab1.insert(bod1);
        tab2.insert(bod2);
        
        $("MyFeedback").insert(h2);     
        $("MyFeedback").insert(tab1);
        $("MyFeedback").insert(h1);
        $("MyFeedback").insert(tab2);
        $("MyFeedback").insert(a1);
        
        
        
        
        
        loadstars(1, line.DestinationRating, line.BookingID)
        loadstars(2, line.YachtRating, line.BookingID)
        
       
    }
    
function CloseFeedback(BookingID){
SaveFeedback(BookingID);
$("MyDetails").show();
$("MyFeedback").hide();
}

function SaveFeedback (BookingID)
{
ajaxOptions = {
            method: "post",
            parameters: {"DestinationDescript": $("DestinationDescript").getValue(), "YachtDescript": $("YachtDescript").getValue(), "BookingID": BookingID},            
            onSuccess: function(transport){
            }.bind(this),
            onFailure: function(){
                alert("There was a problem.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/EditFeedback.aspx", ajaxOptions);
}




function CheckCerts(ID, Field){
        ajaxOptions = {
            method: "post",
            parameters: {"ClientID": ID},
            onSuccess: function(transport){
                var data = transport.responseText.evalJSON();
                generateCheckCerts(data, Field,ID)
            }.bind(this),
            onFailure: function(){
                alert("There was a problem fetching the crew pool.");
            }.bind(this),
            onComplete: function(){
            }.bind(this)
        };
        new Ajax.Request("AjaxCalls/CheckCertificate.aspx", ajaxOptions);
    }
    function generateCheckCerts(lineData, Field,ID){
        lineData.each(function(line){
            generateCheckCert(line, Field,ID);
        });
    }
    var BookingCerts = "";
    function generateCheckCert(line, Field,ID){
      
        BookingCerts += ",\\Certificates\\"+line.user+"\\"+line.file;
        var MyFiles = parseFloat($(Field).innerHTML);
        var Count = 0;
        if (MyFiles > 0) {Count = MyFiles}
        Count = Count + 1;
        $(Field).innerHTML = "<a href='viewcerts.asp?CrewID=" + ID +"'target='_blank'>" + Count + "</a>";
    }
    
    
    
   
   

