// JavaScript Document
var map
function selectPG(pg){
	//alert(pg)
	$('#ihotPG').val(pg);
	var idplc = $('#iplcID').val();
	var tyhot = $('#ihotTY').val();
	var pghot = pg
	showFilter(idplc,tyhot,pghot)
}
function chgBG(rdNo){
	var countRd = document.all('hotFilt').length
	var rdObj = document.all('hotFilt')
	//alert(countRd +' | '+ rdNo)
	if (rdNo == undefined){
		//alert('undefined')
		for (c=0;c<=countRd - 1;c++){
			//alert(rdObj[c].checked)
			if (rdObj[c].checked == true){
					rdNo = c + 1
			}
		}
	}
	for (i=0;i<=countRd;i++){
		if (i == rdNo){
			$('#hotFilt'+rdNo+'').attr('class','BG_Filter_L');
			$('#hotFilt'+rdNo+rdNo+'').attr('class','BG_Filter_R');
		}
		else{
			$('#hotFilt'+i+'').attr('class','');
			$('#hotFilt'+i+i+'').attr('class','');
		}
	}
}
function starPG(plcID,plcNA){
 showFilter(plcID,'Recomended',1,2,plcNA)
}
function showFilter(plcid,filt,pg,rdbut,plcna){
	chgBG(rdbut)
	var htmlCont
	htmlCont = ' <div style="padding:50px 50px;">'
	htmlCont =  htmlCont + '<div align="center"><img src="images/world-globe-animated-ajax-loaders.gif" alt="Loading"></div><div class="Text_Arial16_OrangeBold" align="center" style="padding:10px 10px;"> Loading '+ filt +' hotels</div></div>'
	$('#pgContent').html(htmlCont);

		$.ajax({
		url: "/GET_HotsOnPlace.aspx", 
		data:  {plcID: ''+plcid+'',plcNA:''+plcna+'', hotPG:''+pg+'', hotFIL: ''+filt+'', radBUT: ''+rdbut+''},
		type: "GET",
		success: function(html){
			$('#pgContent').html(html)	
  		},
		error: function (xhr, desc, exceptionobj) {
			$('#pgContent').html(xhr.responseText);
    		alert(xhr.responseText +' = error');
  		}
	});
}
function showRooms(hotC){
	$('#shwh'+hotC+'').show();
}
function ObjectPositionH(obj) {
      var curleft = 0;
      var curtop = 0;
      if (obj.offsetParent) {
            do {
                  curleft += obj.offsetLeft;
                  curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
      }
	   return [curleft,curtop];
}
function jShow(obj) { 
       var aryPosition = ObjectPositionH(document.getElementById(obj));
	   document.getElementById("divPics").style.left = aryPosition[0] + 140 + "px";
	   document.getElementById("divPics").style.top = aryPosition[1] - 205 + "px";
	   document.getElementById("divPics").style.display="block";
	    $('#divPics').show() ;
}  
function jHide() {  

        $('#divPics').hide() ; //style.display="none";
		$('#dclosex').hide()
		$('#content').html('');
		$('#contentmap').html('');
		$('#contentmap').hide()
		map = ""
		
}
function showPics(obj,shipNa,imag){
	//alert(obj)
	$('#contentmap').hide()
	$('#dclosex').hide()
	$('#content').show()
	map = ""
	jShow(obj)
	
	$.ajax({
		url: "/GET_ImagForProducts.aspx", 
		data: "name="+obj+"&ship="+shipNa+"&imag0="+imag+"",
		type: "GET",
		success: function(html){
			//alert(html)
    	    processResponse (html)
  		},
		error: function (xhr, desc, exceptionobj) {
			$('#content').html(xhr.responseText);
    		alert(xhr.responseText +' = error');
  		}
	});
	//alert("que pasa")
}
function showMap(propID,pTitl,pLat,pLong,pAddr){
	//alert(obj)
	$('#content').hide()
	$('#contentmap').show()
	$('#dclosex').show()
	var mobj = 'amap'+propID
	jShow(mobj)
	var lat = pLat;
	var long = pLong;
	var addr = pAddr;
	var titl = pTitl;
	if (GBrowserIsCompatible()) {
		//var map = new GMap2(document.getElementById("map_canvas"));//
		map = new GMap2(document.getElementById("contentmap"));
		map.setCenter(new GLatLng(lat, long), 14);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
	
		var marker = new GMarker(new GLatLng(lat, long));
		GEvent.addListener(marker, "click", function() {
		var html ='<div class="Text_Arial12_BlueBold" align="left" >' + titl + '<br></div>'
		html = html + '<div class="Text_Arial12_Blue" align="left">'+ addr +'</div>'
		marker.openInfoWindowHtml(html);
		});
		map.addOverlay(marker);
		GEvent.trigger(marker, "click");
	}

}
function processResponse(result){
	if (window.ActiveXObject){
		$('#content').html(result);
	}
	else if (document.implementation && document.implementation.createDocument)	{
		$('#content').html(result);
	}
	else{
		alert('Your browser cannot handle this script');
	}
}
/* ************ PICTURES FUNCTIONS ************* */
function fixward(idNum,totP,imgPath){
	//alert(idNum +' | '+ totP)
	i = 0
	do{
		picM = 'IDpic' + i
		if (picM != idNum){
			eval("document.all[picM].className=''");
		}
		else{
			eval("document.all[idNum].className = 'BG_red'");
			document.images.pictureshow.src="http://pictures.solardestinations.com"+imgPath;
		}
	i++
	}
	while (i<totP+1)
}
/* VALIDATE FORMS */
$(document).ready(function() {
			$("#SiteEmialList").validationEngine({
				success: function() { successVal()} 
			})
		});
/* VALIDATE SUSCRIBE MAIL */
function successVal(){
	var jsmail = $('#email').val();
	var jsuser = $('#userID').val();
	$.get("/EmailForms/SuscribeMailList.aspx", { email: ""+jsmail+"", userID: ""+ jsuser +"" },
					function(data){
						if (data == "false"){
							$('#contact_form').html("<div id='message'></div>");
							$('#message').html("<span class='Text_Arial12_OrangeBold'>Contact Form NOT Submitted!</span>");
							return false;
						}
						else{
							$('#contact_form').html("<div id='message'></div>");
							$('#message').html("<span class='Text_Arial12_Bold'>Contact Form Submitted!</span>")
							.append("<br><span class='text_Arial12_Light'>We will be in touch soon.</span>");
							/*.hide()
							.fadeIn(1500, function() {
							$('#message').append("<img id='checkmark' src='images/check.png' />");*/
						}
					});
}
/* CHECK BOX STYLE */
function init(){
	$(document).ready(function(){
		// check for what is/isn't already checked and match it on the fake ones
		$("input:checkbox").each( function() {
			(this.checked) ? $("#false"+this.id).addClass('falsecheckeddop') : $("#false"+this.id).removeClass('falsecheckeddop');
		});
		// function to 'check' the fake ones and their matching checkboxes
		$(".falsecheckdop").click(function(){
			($(this).hasClass('falsecheckeddop')) ? $(this).removeClass('falsecheckeddop') : $(this).addClass('falsecheckeddop');
			$(this.hash).trigger("click");
			return false;
		});
	});
}
$(document).ready(function(){
		// check for what is/isn't already checked and match it on the fake ones
		$("input:checkbox").each( function() {
			(this.checked) ? $("#false"+this.id).addClass('falsechecked') : $("#false"+this.id).removeClass('falsechecked');
		});
		// function to 'check' the fake ones and their matching checkboxes
		$(".falsecheck").click(function(){
			($(this).hasClass('falsechecked')) ? $(this).removeClass('falsechecked') : $(this).addClass('falsechecked');
			$(this.hash).trigger("click");
			return false;
		});
	});

function changeClass(chkid){
	alert(chkid)
	var check = chkid.replace('false','');
	alert(check)
	//var reID = divShw.replace('pic','');
	/*$(document).ready(function(){
		// check for what is/isn't already checked and match it on the fake ones
		$("input:checkbox").each( function() {
			(this.checked) ? $("#false"+this.id).addClass('falsechecked') : $("#false"+this.id).removeClass('falsechecked');
		});
		// function to 'check' the fake ones and their matching checkboxes
		$(".falsecheck").click(function(){
			($(this).hasClass('falsechecked')) ? $(this).removeClass('falsechecked') : $(this).addClass('falsechecked');
			$(this.hash).trigger("click");
			return false;
		});
	});*/
}
/* TO TAKE ID FROM FORM TO FIND PACKAGES */
function findPacks(formID){
	//alert(formID)
	var idForm = formID
	var idString = $('#'+ idForm +'').formSerialize();
	idString = idString.replace(/%7C/g,'|')
	var idStrParts
	var idxOf
	var idValP
	var idVal
	var naPrts
	var naVal
	var naToFind = ''
	var idToFind = ''
	//alert(idString)
	idStrParts = idString.split('&');
	for (i = 0;i<idStrParts.length;i++){
		if (idForm == 'frmFindPack'){
			idxOf = idStrParts[i].indexOf('dot')
		}
		else{
			idxOf = idStrParts[i].indexOf('dop')
		}
		//alert(idxOf)
		//alert(idStrParts[i])
		if (idxOf != -1){
			idValP = idStrParts[i].split('=')
			naPrts = idValP[1].split('|')
			idVal = naPrts[0]
			naVal = naPrts[1]
			idToFind = idToFind + idVal +','
			naToFind = naToFind + naVal +'_'
		}
	}
	idToFind = idToFind.substring(0,idToFind.length - 1); 
	naToFind = naToFind.substring(0,naToFind.length - 1);
	//alert(idToFind)
	if (idForm == 'frmFindPack'){
		$('#allID').val(idToFind);
	}
	else{
		$('#allIDsdp').val(idToFind);
	}
	//alert($('#allIDsdp').val(idToFind))
	$('#'+ idForm +'').attr('action','/Find_Package_to_'+ naToFind +'.aspx'); /// Find_Packages.aspx
	$('#'+ idForm +'').submit();
}
/* TO GO TO HOTEL PAGE */
function gotoHotelPage(rat,plcna){
	//alert(rat +' | '+ plcna)
	$('#RG1').val(rat);
	//document.form1.RG1.value = rat
	//alert($('#RG1').val())
	$('#form1').attr('action',rat+'/'+plcna+'_Hotels.aspx');
	//document.form1.action = '/<%=plcNA%>_Hotels.aspx'
	$('#form1').submit();
	//document.form1.submit()
}
function openPG(pg,qpg){
	//alert(pg)
	//alert(qpg)
	var chpg
	var oppg = 'pg'+pg
	for (i=0;i<=qpg;i++){
		chpg = 'pg'+i
		if (chpg == oppg){
			$('#'+ oppg +'').show();
		}
		else{
			$('#'+ chpg +'').hide();
		}
		
	}
	
}

