// $Id: General.js,v 1.4 2006/10/11 12:53:10 clinton Exp $

//Function used to show print dialog.
function PrintWindow(){
	window.print()
}

//generic pop up message function
function popUp(title, main, footer){
	var p = "Carefree International Travel\n\n" + title + "\n\n" + main;
	if( footer ) p += "\n" + footer;
	alert(p);
	}

//Function used to open window.
function OpenWindow(strUrl, intHeight, intWidth){
	var myNewWindow;
	myNewWindow = window.open(strUrl,null,'height=' + intHeight + ',width=' + intWidth + ',status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
	myNewWindow.focus()
}

//code for change colour on mouse click
//http://www.htmldog.com/articles/suckerfish/focus/

		sfFocus = function() { 
			var sfEls = document.getElementsByTagName("INPUT"); 
			for (var i=0; i<sfEls.length; i++) { 
				sfEls[i].onfocus=function() { 
					this.className+=" sffocus"; } 
				sfEls[i].onblur=function() {
					this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
				} 
			} 
		} 
		if (window.attachEvent) window.attachEvent("onload", sfFocus);
		
		sfFocus2 = function() { 
			var sfEls = document.getElementsByTagName("SELECT"); 
			for (var i=0; i<sfEls.length; i++) { 
				sfEls[i].onfocus=function() { 
					this.className+=" sffocus2"; } 
				sfEls[i].onblur=function() {
					this.className=this.className.replace(new RegExp(" sffocus2\\b"), "");
				} 
			} 
		} 
		if (window.attachEvent) window.attachEvent("onload", sfFocus2);
		

//Help pop up functions

cfHOver = '/carefree/images/icons/help_over.gif';
cfHOut = '/carefree/images/icons/help.gif';

function cfHelp(whichOne) {
	cfHelpWindow = window.open("help.jsp?helpSection=" + pageId + "#" + whichOne, "cfHelp", "width=450,height=400,scrollbars=yes,");
	cfHelpWindow.focus();
}

function clearOver(){
	var theItem = document.getElementById('lblMap');
	theItem.className='cfInvisible'
}

function over(whichOne){
	var theItem = document.getElementById('lblMap');
	var message='';
	switch(whichOne){
			case ('Netherlands'):message+='The Netherlands';break;
			case ('Czech'):message+='Czech Republic';break;
			case ('NorthernIreland'):message+='Northern Ireland';break;
			case ('Europe'):message='Back to map of Europe';break;
			default:message+=whichOne;break;
			}
			theItem.className='lblMap'
			theItem.innerHTML=message;
}

//change drop downs on search page (depending on map click)
function cd(which, code, region){
	var theCountry = document.cccForm.country; 
  var theRegion = document.cccForm.area; 
  var theMap; var theFranceMap;
  
	var objForm = eval('document.cccForm');
    
	if (which=="France") { //if France, change the Map to the French one.
		cfShowHide("hide","divMainMap"); cfShowHide("show","divFranceMap");} 
	
	if (which=="Europe") { //if Europe, change the Map to the Europe one, reset 
    setDropDown(theCountry, '');
		cfShowHide("show","divMainMap"); cfShowHide("hide","divFranceMap");
    setUpPage();
  }	else {	
		if (region==true){
      setDropDown(theRegion, code)
			changeDrops('region');
		} else {
      setDropDown(theCountry, code);
			changeDrops('country');
		}
	}
}

//send in either show or something else to show/hide a div with an id.
function cfShowHide(showOrHide, divName) {
	var theDiv
	if (showOrHide == 'show'){
		theDiv = document.getElementById(divName);
    if (theDiv != null)	theDiv.className='cfVisible'
  }	else {
		theDiv = document.getElementById(divName);
    if (theDiv != null) theDiv.className='cfInvisible'}
}

//stop navigation away from the page
function areYouSure(url) {
if (confirm("Are you sure you want to move away from the\nInternational Travel section of our website?\n\nYou will lose all details of the Holiday you are currently booking.")){
		window.location= url;
	}
}

//if multiple is requested then loop through items with same name
function enableDisable(enableOrDisable, nameOfItem, extraCSS, noStyle, wipeCheckBox, wipeTextBox){
	var theItem;
  for (var f = 0; f < document.forms.length;f++){ 
    var objForm = document.forms[f];  
    
    var theItemAry = eval("objForm."+nameOfItem);
    if (theItemAry == null) continue;
    if (typeof theItemAry.type == 'string') theItemAry = new Array(theItemAry); 
    
    for (var i = 0; i < theItemAry.length; i++) {
			//if (objForm.elements[i].name == nameOfItem){
				theItem = theItemAry[i];
        if (enableOrDisable == 'enable') { 
          if (noStyle!='true') theItem.className='inputStyle' + extraCSS;
						theItem.disabled=false;
        }	else {
          if (noStyle!='true') theItem.className='inputStyleDis' + extraCSS;
          if (wipeCheckBox == 'true') {theItem.checked=false;}
          if (wipeTextBox == true && theItem.type == 'text') {theItem.value='';}
          theItem.disabled=true;
        }
      //}
    } 
  }
}

//enables/disables the carefree insurance options depending on whether the tick box is selected. 
//also resets the values of the supercover/standard and personal insurance options when they are deselected.
function changeCarefreeCover(){
  objItem = document.pageForm.rdoOption;
  if (objItem.checked){
    enableDisable('enable','insDate_day',' cfThirdSize');
    enableDisable('enable','insDate_mon',' cfThirdSize');
    enableDisable('enable','insDate_year',' cfThirdSize'); 
    enableDisable('enable','insEndDate_day',' cfThirdSize');
    enableDisable('enable','insEndDate_mon',' cfThirdSize');
    enableDisable('enable','insEndDate_year',' cfThirdSize');
    enableDisable('enable','b7','','true', 'true');
    enableDisable('enable','b10','','true');
    enableDisable('enable','b13','','true');
    enableDisable('enable','skiCover','','true');
    enableDisable('enable','over80s','');
    enableDisable('enable','chanIslands','','true');
    enableDisable('enable','spain','','true');
    enableDisable('enable','over65s','','true');
  }	else {
    enableDisable('disable','insDate_day',' cfThirdSize');
    enableDisable('disable','insDate_mon',' cfThirdSize');
    enableDisable('disable','insDate_year',' cfThirdSize'); 
    enableDisable('disable','insEndDate_day',' cfThirdSize');
    enableDisable('disable','insEndDate_mon',' cfThirdSize');
    enableDisable('disable','insEndDate_year',' cfThirdSize');
    enableDisable('disable','b7','','true','true');
    setRadioSet(document.pageForm.b7, "");
    enableDisable('disable','b10','','true','true');
    setRadioSet(document.pageForm.b10, "");
    enableDisable('disable','b13','','true','true');
    setRadioSet(document.pageForm.b13, "");
    enableDisable('disable','skiCover','','true');
    enableDisable('disable','over80s','');
    enableDisable('disable','chanIslands','','true');
    enableDisable('disable','spain','','true');
    enableDisable('disable','over65s','','true');
  }
}

//enable/disable the 'choose personal insurance' options depending on whether or not the tick box is selected.
function changePersonal(deselect, clearCFPersonal){
	var objForm = eval('document.cccForm');
	var objItem;
	for (i = 0; i < objForm.length; i++) {
					if (objForm.elements[i].name == 'chkOption2'){
						objItem = objForm.elements[i];}
					}
	if (objItem != null){
		if (deselect==true){
			if (objItem.checked==true){popUp('Personal Insurance', 'As you have selected Personal Insurance from Carefree\n we will now deselect the personal insurance option.') }
			objItem.checked=false //if deselect is true then set the Arrange own perosnal insurance tick box to deselected
		}	
		if (clearCFPersonal==true){
			if (objItem.checked==true){
				for (i = 0; i < objForm.length; i++) {
						var objItem2
						if ((objForm.elements[i].name == 'b10') & (objForm.elements[i].checked)){
							objItem2 = objForm.elements[i];
							popUp('Personal Insurance', 'As you have selected to arrange your own Personal Insurance\nwe will now deselect the Carefree personal insurance option.'); 
							objItem2.checked=false;
							}
						}
			}
		}
		if (objItem.checked){enableDisable('enable','b1',''); enableDisable('enable','b2',''); enableDisable('enable','b3','', 'true');}
		else{enableDisable('disable','b1','','','',true); enableDisable('disable','b2','','','',true); enableDisable('disable','b3','', 'true','true');}
	}
}

// 
function changeOption(){
	var theOptionA = document.cccForm.rdoOption[0]; var theOptionB = document.cccForm.rdoOption[1];
	if (theOptionA.checked==true){
		enableDisable('disable','b1',''); enableDisable('disable','b2','');
		enableDisable('enable','a1',' cfThirdSize'); enableDisable('enable','a2',' cfThirdSize');enableDisable('enable','a3',' cfThirdSize'); enableDisable('enable','a4',' cfThirdSize');enableDisable('enable','a5',' cfThirdSize'); enableDisable('enable','a6',' cfThirdSize');
		enableDisable('enable','b7','','true');enableDisable('enable','b10','','true');enableDisable('enable','b13','','true');enableDisable('enable','b16','','true');enableDisable('enable','b18','');enableDisable('enable','b20','','true');enableDisable('enable','b21','','true');enableDisable('enable','b22','','true');
		}
	else{
		enableDisable('enable','b1', ''); enableDisable('enable','b2', '');
		enableDisable('disable','a1',' cfThirdSize'); enableDisable('disable','a2',' cfThirdSize');enableDisable('disable','a3',' cfThirdSize'); enableDisable('disable','a4',' cfThirdSize');enableDisable('disable','a5',' cfThirdSize'); enableDisable('disable','a6',' cfThirdSize');
		enableDisable('disable','b7','','true');enableDisable('disable','b10','','true');enableDisable('disable','b13','','true');enableDisable('disable','b16','','true');enableDisable('disable','b18','');enableDisable('disable','b20','','true');enableDisable('disable','b21','','true');enableDisable('disable','b22','','true');
		}
}

// for ferry search page (stage5)
function changeOptionIns(){
  if (document.cccForm.mode.value == "inclusive") {
    if (getRadioSetValue(document.pageForm.rdoReturn) == "S") {
      alert("Return crossings only on inclusive holidays");  
    }
    setRadioSet(document.pageForm.rdoReturn, "R");
  }
  
	var theOptionA = document.pageForm.rdoReturn[0];
	if (theOptionA.checked==true){
		enableDisable('enable', 'trip2_route', '');
    enableDisable('enable', 'trip2_operator', '');
    enableDisable('enable', 'trip2_date_day', ' cfThirdSize'); 
    enableDisable('enable', 'trip2_date_mon', ' cfThirdSize'); 
    enableDisable('enable', 'trip2_date_year', ' cfThirdSize'); 
    enableDisable('enable', 'trip2_time', ''); 
    
    defaultInbound();
    
    cfShowHide('show', 'star1'); 
    cfShowHide('show', 'star2'); 
    cfShowHide('show', 'star3'); 
    cfShowHide('show', 'star4');
  }	else {
		enableDisable('disable', 'trip2_route', '');
    enableDisable('disable', 'trip2_operator', '');
    enableDisable('disable', 'trip2_date_day', ' cfThirdSize'); 
    enableDisable('disable', 'trip2_date_mon', ' cfThirdSize'); 
    enableDisable('disable', 'trip2_date_year', ' cfThirdSize'); 
    enableDisable('disable', 'trip2_time', '');  
    
    resetDropDown('trip2_route');
    resetDropDown('trip2_operator');
    resetDropDown('trip2_date_day');
    resetDropDown('trip2_date_mon');
    resetDropDown('trip2_date_year');
    resetDropDown('trip2_time');
    
    
    cfShowHide('hide', 'star1');
    cfShowHide('hide', 'star2'); 
    cfShowHide('hide', 'star3'); 
    cfShowHide('hide', 'star4'); 
  }
}



//this function resets the two drop down that aren't the one selected!
function resetDrops(whichOne){
		var objCountry; var objRegion; var objSite;
		var objForm = eval('document.cccForm');
		//get all three drop downs as objects
		for (i = 0; i < objForm.length; i++) {
			if (objForm.elements[i].name == 'drpCountry'){
			objCountry = objForm.elements[i];
			}
			if (objForm.elements[i].name == 'drpRegion'){
			objRegion = objForm.elements[i];
			}
			if (objForm.elements[i].name == 'drpSite'){
			objSite = objForm.elements[i];
			}		
		}
		switch(whichOne){
			case ('country'):
				objRegion.selectedIndex = 0; objSite.selectedIndex = 0;	
			break;
			case ('region'):
				objCountry.selectedIndex = 0; objSite.selectedIndex = 0;	
			break;
			case ('site'):
				objCountry.selectedIndex = 0; objRegion.selectedIndex = 0;
			break;
			}
}

//check insurance - either 'standard' or 'super' not both
function checkMotoring(which){
	var objItem; var objForm = eval('document.cccForm'); var nameOfItem;
	if (which=='standard') {nameOfItem='b7'}
	else {nameOfItem='b13'};
				for (i = 0; i < objForm.length; i++) {
					if (objForm.elements[i].name == nameOfItem){
						objItem = objForm.elements[i];
						objItem.checked=false;}
					}
	// also sforces user to select same personal (ie trip or multitrip) as they have selected for supercover or standard.
	// but this should be done server side
}

//shows the pets warning text
function showPets(){
	var objTick; var objForm = eval('document.pageForm');var divName = 'petNote';
		for (i = 0; i < objForm.length; i++) {
			if (objForm.elements[i].name == 'chkPets'){objTick = objForm.elements[i];}
		}	
		if(objTick.checked==true){cfShowHide('show', divName)}else{cfShowHide('hide', divName)}
}

//shows the number of children requested
function showChildren(){
	var objChildren;
	var objForm = eval('document.cccForm');
	for (i = 0; i < objForm.length; i++) {
			if (objForm.elements[i].name == 'drpChildren'){objChildren = objForm.elements[i];}
		}
		
	switch(objChildren.value){
			case ('0'):
				cfShowHide('hide', 'child1');cfShowHide('hide', 'child2');cfShowHide('hide', 'child3');cfShowHide('hide', 'child4');cfShowHide('hide', 'child5');cfShowHide('hide', 'child6');cfShowHide('hide', 'child7');cfShowHide('hide', 'child8');
			break;
			case ('1'):
				cfShowHide('show', 'child1');cfShowHide('hide', 'child2');cfShowHide('hide', 'child3');cfShowHide('hide', 'child4');cfShowHide('hide', 'child5');cfShowHide('hide', 'child6');cfShowHide('hide', 'child7');cfShowHide('hide', 'child8');
			break;
			case ('2'):
				cfShowHide('show', 'child1');cfShowHide('show', 'child2');cfShowHide('hide', 'child3');cfShowHide('hide', 'child4');cfShowHide('hide', 'child5');cfShowHide('hide', 'child6');cfShowHide('hide', 'child7');cfShowHide('hide', 'child8');
			break;
			case ('3'):
				cfShowHide('show', 'child1');cfShowHide('show', 'child2');cfShowHide('show', 'child3');cfShowHide('hide', 'child4');cfShowHide('hide', 'child5');cfShowHide('hide', 'child6');cfShowHide('hide', 'child7');cfShowHide('hide', 'child8');
			break;
			case ('4'):
				cfShowHide('show', 'child1');cfShowHide('show', 'child2');cfShowHide('show', 'child3');cfShowHide('show', 'child4');cfShowHide('hide', 'child5');cfShowHide('hide', 'child6');cfShowHide('hide', 'child7');cfShowHide('hide', 'child8');
			break;
			case ('5'):
				cfShowHide('show', 'child1');cfShowHide('show', 'child2');cfShowHide('show', 'child3');cfShowHide('show', 'child4');cfShowHide('show', 'child5');cfShowHide('hide', 'child6');cfShowHide('hide', 'child7');cfShowHide('hide', 'child8');
			break;
			case ('6'):
				cfShowHide('show', 'child1');cfShowHide('show', 'child2');cfShowHide('show', 'child3');cfShowHide('show', 'child4');cfShowHide('show', 'child5');cfShowHide('show', 'child6');cfShowHide('hide', 'child7');cfShowHide('hide', 'child8');
			break;
			case ('7'):
				cfShowHide('show', 'child1');cfShowHide('show', 'child2');cfShowHide('show', 'child3');cfShowHide('show', 'child4');cfShowHide('show', 'child5');cfShowHide('show', 'child6');cfShowHide('show', 'child7');cfShowHide('hide', 'child8');
			break;
			case ('8'):
				cfShowHide('show', 'child1');cfShowHide('show', 'child2');cfShowHide('show', 'child3');cfShowHide('show', 'child4');cfShowHide('show', 'child5');cfShowHide('show', 'child6');cfShowHide('show', 'child7');cfShowHide('show', 'child8');
			break;
			}	
}

function moveOn(){
		var objTick; var objForm = eval('document.cccForm');
		for (i = 0; i < objForm.length; i++) {
			if (objForm.elements[i].name == 'tc'){objTick = objForm.elements[i];}
		}		
		if(objTick.checked==true){
			window.location='index.aspx?stage=stage13'
		}
		else{
			alert('Sorry, you have not completed all the required fields.\n\nPlease complete the following items\n\n\- Agree to terms and conditions');
		}
}