// JavaScript Document
var objPos
var objL
var objT
var IDarray = new Array()
$(document).ready(function(){
	var showAll = $('#showAll').val()
	if (showAll == 1) {
		IDarray = $('#IDarray').val().split('|');
		openPg(1);
	}
});
function openPgURL(url){
	window.location=url;	
}
var totpg
var strMsg
var strDiv
var placeNA
var placeID
var FrToTxt = new Array
var domDiv
function openPg(pg,pkID){
	$('#dvFea').hide();
	$('#allItin').show();
	$('#allLink').hide();
	window.scrollTo(150,0);
	var sqlPg = pg - 1
	//$('#dvResp').hide();
	$('#dvFrTo').hide();
	$('#dvFrToB').hide();
	$('#pgNosB').hide();
	$('#dvResp').html('');
	$('#dvFrTo').html('');
	$('#dvFrToB').html('');
		
	totpg = $('#totPgs').val();
	placeID = $('#IDplace').val();
	placeNA = $('#NAplace').val();
	$('#dvWait').html('<img src="/images/ajax-loader.gif" width="50" height="50" />');
	$('#dvWait').show();
	
	for (i=1;i<=totpg;i++){
		if (i!=pg){
			$('[id^="pg'+i+'"]').attr('class','pgNosNoSel');
		}
		else{
			$('[id^="pg'+i+'"]').attr('class','pgNosSel');
		}
		if (i == totpg){
			FrToTxt[i] = 'from '+ Number((i*10)-9) +' to '+ $('#totPks').val();
		}
		else{
			FrToTxt[i] = 'from '+ Number((i*10)-9) +' to '+ Number(i*10)
		}
	}
	//alert(placeID);
	//alert(IDarray[sqlPg]);
	$.ajax({
		type: "POST",
		url: "/Get_ajaxPages.aspx?placeID="+ placeID +"&allPacksID="+ IDarray[sqlPg], 
		//contentType: "application/json; charset=utf-8",
		//dataType: "json",
		//data: '{placeID:"' + placeID + '", allPacksID:"'+ IDarray[sqlPg] +'"}',  
		success: function(data) {
			//alert(data)
			msg = data //eval("(" + data.d + ")");
			//alert(msg)
			if (msg != '') {
				//msg = msg.replace('<div>','');
				//msg = msg.replace('</div>','');
				strMsg = msg.split('@')
				// NOTE: 0 = ID | 1 = Title | 2 = Description | 3 = No. Nights | 4 = Price | 5 = Included | 6 = No. of Feed backs | 7 = Related //
				strDiv = '';
				var margTo = '10px'
				for (i in strMsg){
					if(i < strMsg.length){
						
						var strMsgLn 
						strMsgLn = strMsg[i].split('|');
						if (i > 0){margTo = '5px'};
							strDiv = strDiv +'<div style="margin-top:'+ margTo+'; padding:5px 0px 5px 10px;">'
							strDiv = strDiv +'<div class="Text_Arial12_BlueBold" style="width:260px; padding:2px 0px 2px 0px; float:left; word-wrap:break-word;"><a href="/'+ placeNA.replace(/\s/g,'_') +'/Itinerary_pk'+ strMsgLn[0] +'_'+ strMsgLn[1].replace(/\s/g,"_") +'.aspx"><u>'+ strMsgLn[1] +'</u></a></div>'
																			
							if(strMsgLn[4] != 9999){
								strDiv = strDiv +'<div class="Text_12_GrayBold" style="padding:2px 0px 2px 0px; float:right; width:140px;" align="right">'+ strMsgLn[3] +' nights from <b class="Text_Arial12_OrangeBold">'+ formatCurrency(strMsgLn[4]) +'*</b></div>'	
							}
							else{
								strDiv = strDiv +'<div class="Text_12_GrayBold" style="padding:2px 0px 2px 0px; float:right; width:1px;" align="right"></div>'
							}
							strDiv = strDiv +'<div style="clear:both"></div>'
							strDiv = strDiv +'</div>'
							
							
							
							if (strMsgLn[6] != 'none'){
								strDiv = strDiv +'<div id="'+strMsgLn[6]+'|'+ strMsgLn[0] +'" class="Text_12_Gray" style="margin-left:10px; cursor:pointer; width:100px;" onMouseOver="showPopUp(this.id)" onMouseOut="hidePopUp(this.id)"><b>'+strMsgLn[6]+'</b></div>'
							}
							strDiv = strDiv +'<div class="Text_Arial12" style="padding:3px 10px 3px 15px;">'+ strMsgLn[2] +'</div>'
							strDiv = strDiv +'<div style="padding:3px 3px 3px 15px;" class="Text_Arial12">'
							strDiv = strDiv +'<div><b>Included:</b></div>'
							strDiv = strDiv +'<div style="margin-right:20px">'
							if(strMsgLn[5] !=''){
								strMsgLn[5] = strMsgLn[5].replace('<div>','');
								strMsgLn[5] = strMsgLn[5].replace('</div>','');
								var MsgLn5Ps = strMsgLn[5].split('<br/>');
								strDiv = strDiv +'<ul>'
								for (h in MsgLn5Ps){
								  strDiv = strDiv + '<li>'+ MsgLn5Ps[h].replace('<br/>','<li>');
								}
								strDiv = strDiv +'</ul>'
							}
							strDiv = strDiv +'</div>'
							strDiv = strDiv +'<div style="clear:both"></div>'
							strDiv = strDiv +'</div>'
							if (strMsgLn[7] > 0){
								 strDiv = strDiv +'<div class="Text_Arial11" style="padding:10px 2px 5px 20px;"><a href="/'+ placeNA.replace(/\s/g,'_') +'_CFB'+ strMsgLn[0] +'_'+ strMsgLn[1].replace(/\s/g,'_') +'.aspx">Customer feedback ('+ strMsgLn[7] +') <img src="/images/IMG-Feed.jpg" width="21" height="16" border="0" /></a></div>'
							}
							
							
														
							if (strMsgLn[6] != ''){
								/*strDiv = strDiv +'<div class="Text_Arial11" style="padding:10px 2px 5px 20px;">'
								strDiv = strDiv +'<span class="Text_Arial11_LightBold">Related Interest<br></span>'
								strDiv = strDiv +'<a href="/'+strMsgLn[6].replace(/\s/g,'_') +'_Vacations.aspx" style="margin-right:10px"><span class="Text_Arial11_Light"><u>'+strMsgLn[6]+'</u></span></a>'
								strDiv = strDiv +'</div>'*/
								
							}
							strDiv = strDiv +'<div class="Text_Arial11" style="padding:10px 2px 5px 20px;">'
							strDiv = strDiv +'<span class="Text_Arial11_LightBold">Related Package<br></span>'
							
							var MsgLn8Ps = strMsgLn[8].split('^^');
							for(ds in MsgLn8Ps){
								if (ds < MsgLn8Ps.length -1){
								var aLink = MsgLn8Ps[ds].split('#');
								//NOTE: 0 = Place Name | 1 = No. of packs related //
								strDiv = strDiv +'<a href="/'+aLink[0].replace(/\s/g,'_') +'_Vacations.aspx" style="margin-right:10px"><span class="Text_Arial11_Light"><u>'+aLink[0]+' ('+aLink[1]+')</u></span></a>'
								}
							}
							strDiv = strDiv +'</div>'
							strDiv = strDiv +'<div style="padding:15px 35px 20px 35px; border-bottom:1px solid navy; margin-bottom:20px" align="right">&nbsp;&nbsp;&nbsp;&nbsp;<a href="/'+ placeNA.replace(/\s/g,'_') +'/Itinerary_pk'+ strMsgLn[0] +'_'+ strMsgLn[1].replace(/\s/g,"_") +'.aspx"><img src="/images/BUT_CustomizeIt.gif" width="141" height="25" border="0" /></a></div>'
							//strDiv = strDiv +'<hr style="height: auto; color: #00DD6F; width: 100%;"/>'
							
					}
			  }
				
				
			$('#dvResp').html(strDiv);
				
				
			
			}
			$('#dvWait').html('');
			$('#dvWait').hide();
			$('#dvResp').show();
			$('#dvFrTo').html(FrToTxt[pg]);
			$('#dvFrTo').show();
			$('#dvFrToB').html(FrToTxt[pg]);
			$('#dvFrToB').show();
			$('#pgNosB').show();
			
		},
		error: function (xhr, desc, exceptionobj) {
			//alert(xhr.responseText +' = error');
			$('#dvWait').html('');
			$('#dvWait').hide();
			$('#dvResp').html(' <span class="Orange-Arial14">A error happened:<br></span>'+  xhr.responseText);
			$('#dvResp').show();
		}
	});
	
	
}
///// *****************************************
function ObjectPosition(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 PopInfoCty(obj,id){
	//alert(obj +' | '+ id)
	var shwdiv = 'info'+id
	objPos = ObjectPosition(document.getElementById(obj))
	objL = objPos[0] + 10 +'px'
	objT = objPos[1] + 1 +'px'
	document.getElementById(shwdiv).style.left = objL;
	document.getElementById(shwdiv).style.top = objT;
	$('#info'+id+'').show();
}
function closeInfo(id){
	$('#info'+id+'').hide();
	
}
var imgSrc;
var imgVal;
function openInfo(id){
	var reID = id.replace('pic','');
	divInf = 'desc'+reID;
	divShw = 'pkInf'+reID;
	divtxt = 'txt'+reID;
	divBut = 'butt'+reID
	divReHtml = '<div style="padding: 15px 5px" align="center"><img src="/images/ajax-loader.gif" align="absmiddle"><br><br><span class="Text_Arial11_Blue">Loading...</span></div>'
	
	imgSrc = $('#'+id+'').attr("src");
	imgVal = imgSrc.indexOf("Plus");
	if (imgVal != -1){
		$('#'+id+'').attr("src","/images/Minus.jpg");
		$('#'+divInf+'').attr("class","Text_Arial12");
		$('#rel'+reID+'').html(divReHtml);
		$('#rel'+reID+'').show();
				if(document.getElementById(divtxt) != null){
			$('#'+divtxt+'').html('Hide details');
		}
		//if (reID.indexOf('A')>-1){reID = reID.replace('A','')};
		infoAjax(reID);
		scrollToMore(id);
		return false
	}
	else{
		$('#'+id+'').attr("src","/images/Plus.jpg");
		$('#'+divInf+'').attr("class","Text_12_Gray");
		$('#'+divShw+'').hide();
		if(document.getElementById(divtxt) != null){
			$('#'+divtxt+'').html('More details');
		}
		$('#rel'+reID+'').html(divReHtml);
		$('#rel'+reID+'').hide();
		$('#'+divBut+'').hide();
	}
}
function infoAjax(reID){
	var divHtml
	var ajxID = reID
	if (ajxID.indexOf('A')>-1){ajxID = ajxID.replace('A','')};
	$.ajax({
		url: "/GET_PackRelatedInfo.aspx", 
		//data: {PackID: ""+reID+""}, //stringQuery, if is GET
		data: {'PackID': ''+ ajxID +''},
		type: "POST",
		success: function(html){
			    divHtml = html
			    divHtml = divHtml + '<div class="LN_PckSeparator" style=" padding-bottom:10px; ">&nbsp;</div>'
				pasteResult(reID,divHtml)
		},
		error: function (xhr, desc, exceptionobj) {
			$('#rel'+reID+'').html(xhr.responseText);
    		alert(xhr.responseText +' = error');
  		}
	});
}
function pasteResult(rID,tml){
	$('#pkInf'+rID+'').show();
	$('#rel'+rID+'').html(tml);
	$('#butt'+rID+'').show();
	init()
}
function openInfo111(id){
	var imgSrc;
	var imgVal;
	var divShw = id;
	var divInfo
	var divInfoH
	var reID = divShw.replace('pic','');
	divShw = divShw.replace('pic','');
	divInfo = 'desc'+divShw;
	divInfoH = 'desch'+divShw;
	divtxt = 'txt'+divShw;
	divShw = 'pkInf'+divShw;
	imgSrc = $('#'+id+'').attr("src");
	imgVal = imgSrc.indexOf("Plus");
	if (imgVal != -1){
		$('#'+id+'').attr("src","/images/Minus.jpg");
		$('#'+divInfo+'').hide();
		$('#'+divInfoH+'').show();
		$('#'+divShw+'').show();
		if(document.getElementById(divtxt) != null){
			$('#'+divtxt+'').html('Hide details');
		}
		
		$.ajax({
		url: "/GET_PackRelatedInfo.aspx", 
		//data: {PackID: ""+reID+""}, //stringQuery, if is GET
		data: {'PackID': ''+ reID +''},
		type: "POST",
		success: function(html){
				$('#rel'+reID+'').html(html);
				$('#butt'+reID+'').show();
  		},
		error: function (xhr, desc, exceptionobj) {
			$('#rel'+reID+'').html(xhr.responseText);
    		alert(xhr.responseText +' = error');
  		}
	});
		
		
		/*$.get("/GET_PackRelatedInfo.aspx", { PackID: ""+reID+""},
			function(data){
			if (data == "false"){
				$('#rel'+reID+'').html("<div id='message'></div>");
				return false;
			}
			else{
				$('#rel'+reID+'').html(data);
				init()
				$('#butt'+reID+'').show();
			}
		});
		*/
	}
	else{
		$('#'+id+'').attr("src","/images/Plus.jpg");
		$('#'+divInfo+'').show()
		$('#'+divInfoH+'').hide();
		$('#'+divShw+'').hide();
		if(document.getElementById(divtxt) != null){
			$('#'+divtxt+'').html('More details');
		}
		$('#rel'+reID+'').html('');
		$('#butt'+reID+'').hide();
	}
}
/* 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;
		});
	});*/
}
/* 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' />");*/
						}
					});
}
/* TO TAKE ID FROM FORM TO FIND PACKAGES */
function findPacks(frmID){
	var inplen = $("form#"+frmID+" input:checkbox")
	var frmSub = $('#'+frmID+'').formSerialize();
	var frmSubP = frmSub.split('&');
	var idsSubmit = ''
	var idVal
	var idValP
	var naVal
	var namSubmit = ''
	for(c=0;c<=frmSubP.length-1;c++){
		if (frmSubP[c].indexOf('all') == -1){
			idValP = frmSubP[c].split('=');
			idValP = idValP[1].split('%7C');
			idVal = idValP[0];
			naVal = idValP[1];
			idsSubmit = idsSubmit + idVal +','
			namSubmit =  namSubmit + naVal +'-'
		}
	}
	idsSubmit = idsSubmit.substring(0,idsSubmit.length -1);
	namSubmit = namSubmit.substring(0,namSubmit.length -1);
	$("form#"+frmID+" input[id=allID]").val(idsSubmit); 
	$("form#"+frmID+" input[id=allNA]").val(namSubmit);
	$("form#"+frmID+"").attr('action','/Find_Packages.aspx');
	$("form#"+frmID+"").submit();
}
/* TO TAKE PACKAGES RELATED INFO */
var win = true;	
function NewWindow(mypage,myname,w,h,scroll){
	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)
}
function openAllPg(pg,pgT){
	for (p=1;p<=pgT;p++){
		if (p == pg){
			$('#pgA'+p+'').show();
			$('#pg'+p+'').attr('class','Text_Arial12_Orange');
		}
		else{
			$('#pgA'+p+'').hide();
			$('#pg'+p+'').attr('class','Text_Arial12_Blue')
		}
	}
}
function funcAllLink(a){
	if (a == 1){
		$('#allLink').hide();
		$('#allLinkC').show();
		$('#morFeaAll').hide();
		$('#allPages').show();
	}
	else{
		$('#allLink').show();
		$('#allLinkC').hide();
		$('#morFeaAll').show();
		$('#allPages').hide();
	}
		
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function scrollToMore(jbo){
	var objTOGO = $('#'+jbo+'').offset();
	$('html,body').animate({scrollTop:objTOGO.top-15},2000);
}
