

//set a cookie value, storing the users text size adjustment preference
function adjustTextSize(adjustment,max,min){
    var textadjustValue ;

    if (adjustment == 0){ //reset 
         textadjustValue = 0;
    }
    else{ //adjustment
       textadjustValue = convertToInteger(readCookie('textadjustment')) + parseInt(adjustment);
       if (textadjustValue > max || textadjustValue  < min) { return; } //return if we have reached the max or min adjustment
    } 
 
    //create or override exsiting cookie
    createCookie('textadjustment', textadjustValue, 365 * 10);
        
    //update css link
    getPreferredStyleSheet();
}


//reads the cookie value and set the correct stylesheet
function getPreferredStyleSheet(){
    
    //get the current adjust value
    var textadjustValue = convertToInteger(readCookie('textadjustment'));

    //repoint css
    document.getElementById('textadjuster').href = '/css/adjustments/textadjust_' + textadjustValue + '.css';
}

//cookie functions are written by ALA author Peter-Paul Koch http://www.quirksmode.org/.
 function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function convertToInteger(value){
    if (value == null){
        return 0;
    }
    else{ 
        return parseInt(value);
    }   
        
}

function clearhelptext(ctrl,originaltext){
    if (ctrl.value==originaltext) ctrl.value="";
}

function showfaq(faqid){
    //loop all LI and hide all faq answer
    if (document.getElementById(faqid).className == "faq-answer show"){
        document.getElementById(faqid).className = "faq-answer hide";    
    }
    else{
        var lis = getElementsByClassName(document,"li","faq-answer");
        for(i=0;i<lis.length;i++){
            lis[i].className = "faq-answer hide";
        }
        //show selected faq answer
        document.getElementById(faqid).className = "faq-answer show";
    }
}

var oDestinationId;
var oDestinationDetailId;

function showdestination(destinationid,destinationdetailid){
    //check if clicked destination is open and if so close
    if (document.getElementById(destinationdetailid).className == "destination-detail show")
    {
        //document.getElementById(destinationdetailid).className = "destination-detail hide";
        //change a link text
       // document.getElementById(destinationid).innerHTML = document.getElementById(destinationid).innerHTML.replace('Hide','Show');        
    }
    else{
        //loop all DIV and hide all destination details
        var details = getElementsByClassName(document,"div","destination-detail");
        for(i=0;i<details.length;i++){
            details[i].className = "destination-detail hide";
        }
        //loop all show/hide links and reset
        var destinationtoggles = getElementsByClassName(document,"a","destination-toggle");
        for(i=0;i<destinationtoggles.length;i++){
            destinationtoggles[i].innerHTML = destinationtoggles[i].innerHTML.replace('Hide','Show');
        }        
        
        //show selected faq answer
        document.getElementById(destinationdetailid).className = "destination-detail show";
        
        //change a link text
        //document.getElementById(destinationid).innerHTML = document.getElementById(destinationid).innerHTML.replace('Show','Hide');        
        
    }
    

}


function getElementsByClassName(oElm, strTagName, strClassName){
        var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	    var arrReturnElements = new Array();
	    strClassName = strClassName.replace(/\-/g, "\\-");
	    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	    var oElement;
	    for(var i=0; i<arrElements.length; i++){
	        oElement = arrElements[i];
	        if(oRegExp.test(oElement.className)){
	            arrReturnElements.push(oElement);
	        }
	    }
	    return (arrReturnElements)
}

//switches between general and cruise specific contact form
function contactFormSwitch(type){
    switch (type){
        case "general":
            document.getElementById('cruise-specific').className = 'contact-form-section hide';
            document.getElementById('marketing-section').className = 'contact-form-section';
            break;
        case "cruise":
            document.getElementById('cruise-specific').className = 'contact-form-section';
            document.getElementById('marketing-section').className = 'contact-form-section hide';
            break;
    }
}

//shows or hides the marketing question depending on if user has ticked the newsletter box
function contactFormNewsletterQuestions(ctrl){
    if (ctrl.checked){
        //show fields
        document.getElementById('marketing-section').className = 'contact-form-section';
    }
    else{
        //hide fields
        document.getElementById('marketing-section').className = 'contact-form-section hide';
    }
}
