// JavaScript Document
function initcountry(){
	//alert('Heloooo')
	makeRounded();
	replaceChecks();
}

function findObj(elemID){
	var obj=false;
	if(document.all){
		obj=document.all(elemID);
	}
	else{
		if(document.getElementById){
			obj=document.getElementById(elemID);
		}
		else{
			if(document.laers){
				obj=document.laers[elemID];
			}
		}
	}
	return obj;	
}

function displayDiv(divID,display){
	oDiv=findObj(divID);
	if (display){
		oDiv.style['display'] = "";
	}
	else{
		oDiv.style['display'] = "none";
	}
}


function makeRounded() {
  var divs=document.getElementsByTagName('div');
  var numDivs=divs.length;
  var roundedDivs= new Array();
  for(i=0;i<numDivs;i++) {
    if(/\brounded\b/.test(divs[i].className)) {
      roundedDivs[roundedDivs.length]=divs[i];
	 }
  }
  var numRoundedDivs=roundedDivs.length;
  for(i=0;i<numRoundedDivs;i++) {
    var brdivCo=roundedDivs[i];
    var tldiv=document.createElement('div');
    brdivCo.className=brdivCo.className.replace('rounded','');
    tldiv.className='rounded';
    brdivCo.parentNode.replaceChild(tldiv,brdivCo);
	brdivCo.className='brdivCo';
    trdiv=document.createElement('div');
	bldiv=document.createElement('div');
    tldiv.appendChild(trdiv);
	trdiv.appendChild(bldiv);
	trdiv.className='trdiv';
	bldiv.appendChild(brdivCo);
	bldiv.className='bldiv';
	
  }
}
var inputs;
var imgFalse = '/images/false.png';
var imgTrue = '/images/true.png';

//this function runs when the page is loaded, put all your other onload stuff in here too.

function replaceChecks() {
	//alert(imgTrue)
	//get all the input fields on the page
	inputs = document.getElementsByTagName('input');

	//cycle trough the input fields
	for(var i=0; i < inputs.length; i++) {

		//check if the input is a checkbox
		if(inputs[i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(inputs[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImage'+i;
			//set image 
			img.onclick = new Function('checkChange('+i+')');
			//place image in front of the checkbox
			inputs[i].parentNode.insertBefore(img, inputs[i]);
			
			//hide the checkbox
			inputs[i].style.display='none';
		}
	}
}

//change the checkbox status and the replacement image
function checkChange(i) {

	if(inputs[i].checked) {
		inputs[i].checked = '';
		document.getElementById('checkImage'+i).src=imgFalse;
	} else {
		inputs[i].checked = 'checked';
		document.getElementById('checkImage'+i).src=imgTrue;
	}
}
function COshowregion(){
	//var h = 90
	var w = 1024
	document.getElementById('byRegions').style.display='block';
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	//TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	document.getElementById('byRegions').style.left = LeftPosition +'px';
	document.getElementById('divFindButt').style.display='none';
		
}
function COhideregion(){
	document.getElementById('byRegions').style.display='none';
	document.getElementById('divFindButt').style.display='block';
	
}
function findPackNew(){
 	var checkbox_choices = 0;
	var checkbox_values = '';
	var strToURL
	var strcitysIDNA
	var citysID
	var citysNA
	var strIDNA
	var boxlength = document.frmFindPack.findPacks.length
	//alert(boxlength)
	if (boxlength == undefined){
		boxlength = 1
			//alert(boxlength)
			checkbox_values =  document.frmFindPack.findPacks.value;
			//alert(checkbox_values)
			strcitysIDNA = checkbox_values.split('|')
			//if (checkbox_choices == 1){
				citysID = strcitysIDNA[0]
				citysNA = strcitysIDNA[1]
			//checkbox_values =  frmFindPack.findPacks[counter].value;
			//}
	}
	else{
		for (counter = 0; counter < boxlength; counter++){
			if (document.frmFindPack.findPacks[counter].checked){ 
				checkbox_choices = checkbox_choices + 1;
				checkbox_values =  document.frmFindPack.findPacks[counter].value;
				//alert(checkbox_values)
				strcitysIDNA = checkbox_values.split('|')
				if (checkbox_choices == 1){
					citysID = strcitysIDNA[0]
					citysNA = strcitysIDNA[1]
					//checkbox_values =  frmFindPack.findPacks[counter].value;
				}
				if (checkbox_choices > 1){ 
					citysID = citysID +','+ strcitysIDNA[0]
					citysNA = citysNA +'_'+ strcitysIDNA[1]
					//checkbox_values = checkbox_values +'@'+ frmFindPack.findPacks[counter].value;
				}
			}
		}
	}
	//alert(checkbox_values +' = check')
	//alert(citysID +' ID')
	//alert(citysNA +' NA')
	if (citysID == undefined){
		alert('Please check at least one box. Thanks!');
		return;
	}
	else{
		document.frmFindPack.allID.value = citysID
		document.frmFindPack.allNA.value = citysNA
		document.frmFindPack.action = "/Find_Package_to_"+ citysNA +".aspx"
		//document.frmFindPack.action = "/AAA_Find_Packs_CO.asp" //"/Build_Package_to_"+ strToURL +".aspx"
		//document.frmBuildVac.action = "/Build_Itinerary.aspx"
		//alert(document.frmBuildVac.action)
		document.frmFindPack.submit()
	}
}
function CombineCO(jthisCO,jplusCO,jURL){
	document.frmCombine.thisCO.value = jthisCO
	document.frmCombine.plusCO.value = jplusCO
	document.frmCombine.action = ''+ jURL +''
	document.frmCombine.submit()
}



////************ AJAX *********************
var SameInterest
var divIntID
var divSameInterest
var divIntAjax
var divCtyIds
function PacksByInterest(dvNA,inID){ 
divSameInterest = ""

	//alert(dvNA +' | '+ inID)
	divIntAjax = dvNA+'Ajax'
	divCtyIds = document.getElementById('allCtysIDs').value
	document.getElementById('divName').value = dvNA 
	document.getElementById('intID').value = inID 
	document.getElementById(divIntAjax).innerHTML = '<img src="/images/wait.gif">';
   url = '/A_Get_Packs_ByPlace_ByInt.aspx?intID='+ inID +'&ctyIDs='+ divCtyIds
   http_request=GetXmlHttpObject(SameInterest)
   http_request.open('GET', url, true); 
   http_request.send(null); 
} 
function SameInterest() { 
	if (http_request.readyState == 4 || http_request.readyState=="complete") { 
	   if (http_request.status != '') { 
	  		divSameInterest =  http_request.responseText;
			//alert(divSameInterest)
			setTimeout ("document.getElementById(divIntAjax).innerHTML  =  divSameInterest", 500);
			//document.getElementById(divSimilar).style.display = 'block';
			
	  } 
	   else { 
		    alert('There was a problem with the request.'); 
		   // document.getElementById(divSimilar).innerHTML =  '';
			
		} 
	} 
}

function GetXmlHttpObject(handler){
	if (navigator.userAgent.indexOf("Opera")>=0){
		alert("This City selector doesn't work in Opera")
		return
	}
	if (navigator.userAgent.indexOf("MSIE")>=0){
		var strName="Msxml2.XMLHTTP"
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
				strName="Microsoft.XMLHTTP"
			}
			try{
				objXmlHttp=new ActiveXObject(strName)
				objXmlHttp.onreadystatechange=handler
				return objXmlHttp
			}
			catch(e){
				alert("Error. Scripting for ActiveX might be disabled")
				return
			}
	}
	if ((navigator.userAgent.indexOf("Firefox")>=0) || (navigator.userAgent.indexOf("Safari")>=0)){
	objXmlHttp=new XMLHttpRequest()
	objXmlHttp.onload=handler
	objXmlHttp.onerror=handler
	return objXmlHttp
	}
}
var win = true;	
var winloc = window.location.href
function NewWindow(mypage,myname,w,h,scroll){
	/*if (myname !=1){
		mypage = '/Mail_Forms/SendPageFriend.asp?PageURL=' + winloc
	}*/
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}