var ContentHeight = 140;
var TimeToSlide = 200.0;
var openAccordion = '';
var openImg = '';
var numPerPage=10;
var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September",  "October", "November", "December");

//===================================================
//              Home theme promo change AJAX code
//===================================================
	$(document).ready(function(){
		$("#generate").change(onSelectChange);
	});
	function onSelectChange(){
		showLightBox();
		var selected = $("#generate option:selected");		
		var output = "";
		if(selected.val() != 0){
			$("#response").load("components/honeymoonpackages.html?req="+selected.val());
			document.getElementById('theme_name').innerHTML=selected.text();
		}
		setTimeout("hideLightBox()",1500);
	}
	function selectOption(num,name)
	{
		var selObj = document.getElementById(name);
		selObj.selectedIndex = num;
	}
	
	function onSubmit(){
		if(document.quickSearch.destination.value == "" && document.quickSearch.cities.value == "I know my destination"){
			alert("Select your destination or enter your choice in the ‘I know my destination’ field");
			return false;
		}
	}
	function blankTextBox(name)
	{
		document.getElementById(name).value='I know my destination';
	}
	function fieldBlank(id)
	{
		if(document.getElementById(id).value == "I know my destination"){
			document.getElementById(id).value='';
		}else if(document.getElementById(id).value == ""){
			document.getElementById(id).value='I know my destination';
		}
		if(document.getElementById("theme"))document.getElementById("theme").style.visibility='visible';
		if(document.getElementById("month"))document.getElementById("month").style.visibility='visible';


	}
	
	function onClickfieldBlank(id)
	{
		if(document.getElementById(id).value != "" ){
			document.getElementById(id).value='';
		}
	}
	function frmchng(val,id)
	{
		for(i=0;i<document.getElementById(id).length;i++)
		{
			if(document.getElementById(id).options[i].value==val){
				document.getElementById(id).selectedIndex=i
			}
		}
	}
//===================================================
//              LightBox 
//===================================================
	function showLightBox(){
		document.getElementById('light').style.display='block';
		document.getElementById('fade').style.display='block';
		if(document.getElementById("destination"))document.getElementById("destination").style.visibility='hidden';
		if(document.getElementById("theme"))document.getElementById("theme").style.visibility='hidden';
		if(document.getElementById("duration"))document.getElementById("duration").style.visibility='hidden';
		if(document.getElementById("month"))document.getElementById("month").style.visibility='hidden';
	}
	function hideLightBox(){
		document.getElementById('light').style.display='none';
		document.getElementById('fade').style.display='none';
		if(document.getElementById("destination"))document.getElementById("destination").style.visibility='visible';
		if(document.getElementById("theme"))document.getElementById("theme").style.visibility='visible';
		if(document.getElementById("duration"))document.getElementById("duration").style.visibility='visible';
		if(document.getElementById("month"))document.getElementById("month").style.visibility='visible';
	}
	function setResultTimer(){
		showObjectArray('sort', 1);
	}

//===================================================
//              Show/Hide 
//===================================================

$("#filtershowhide").ready(function() {
	$('a.filterLink').click(function() {
	$(this).parent().prev('.filter').toggle('slow');
	filterShowHide()
	return false;

});
});

$("#quickshowhide").ready(function() {
	$('a.showhideLink').click(function() {
	$('.commonshowhide').hide();
	$('.showhide').hide();
	$(this).parent().next('.showhide').toggle('slow');
	return false;
});
});

$("#commonshowhide").ready(function() {
	$('a.commonshowhideLink').click(function() { 
	$('.commonshowhide').hide();
	$('.showhide').hide();
	$(this).parent().next('.commonshowhide').toggle('slow');
	return false;
});
});

function filterShowHide(){
	if(document.getElementById("filtershow").style.display == 'none'){
		document.getElementById("filterhide").style.display = 'none';
		document.getElementById("filtershow").style.display = 'block';
	}else{
		document.getElementById("filterhide").style.display = 'block';
		document.getElementById("filtershow").style.display = 'none';
	}
	
}
function showHideGT(val){
	$('#grouptour'+val).toggle('slow');
}
function showHideGT(val){
	$('#grouptour'+val).toggle('slow',changeSign(val));
}
function changeSign(val){
	if(document.getElementById("gtsapnP"+val).style.display == 'none'){
		document.getElementById("gtsapnP"+val).style.display = 'block';
	}else{
		document.getElementById("gtsapnP"+val).style.display = 'none';
	}
	if(document.getElementById("gtsapnN"+val).style.display == 'block'){
		document.getElementById("gtsapnN"+val).style.display = 'none';
	}else{
		document.getElementById("gtsapnN"+val).style.display = 'block';
	}
}
function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function removeAll(selectbox, start)
{
	var i;
	for(i=selectbox.options.length;i>=start;i--)
	{
	 selectbox.remove(i);
	}
}
function populateAroundDest(){
	var ctr=0;
	removeAll(document.getElementById('destination'), 2);
	removeAll(document.getElementById('theme'), 1);
	for (var counter = 0; counter < document.quickSearch.group_tour.length; counter++){
		if ((document.quickSearch.group_tour[counter].checked) && (document.quickSearch.group_tour[counter].value=="IND")){
			for(var i=0; i<aroundInd.length; i++){
				addOption(document.getElementById('destination'),aroundInd[i],aroundInd[i]);
			}
			for(var i=0; i<categoryInd.length; i++){
				var catArray = categoryInd[i].split('\-');
				addOption(document.getElementById('theme'),catArray[1],catArray[0]);
			}
			ctr++;
		}else if(document.quickSearch.group_tour[counter].checked && (document.quickSearch.group_tour[counter].value=="GT")){
			for(var i=0; i<aroundGT.length; i++){
				addOption(document.getElementById('destination'),aroundGT[i],aroundGT[i]);
			}
			for(var i=0; i<categoryGT.length; i++){
				var catArray = categoryGT[i].split('\-');
				addOption(document.getElementById('theme'),catArray[1],catArray[0]);
			}
			ctr++;
		}
	}
	if(ctr == 0){
		for(var i=0; i<aroundAll.length; i++){
			addOption(document.getElementById('destination'),aroundAll[i],aroundAll[i]);
		}
		for(var i=0; i<category.length; i++){
			var catArray = category[i].split('\-');
			addOption(document.getElementById('theme'),catArray[1],catArray[0]);
		}
	}
}
	
		
//===================================================
//              Step2 Sorting
//===================================================
function ownObject(package_id, country_code, package_name, currency, yatra_rating, s_s_date, e_s_date, s_v_date, e_v_date, domint, on_request, ups, duration, package_image, inclusion,roomRate,duration,themes,grouptourstr, discount, yatra_rating, traveler_rating, dayWiseDurationString, airfare, package_type, discount_message, discount_type, currency, themeicon, cashback_discount, package_sub_name, supplier_code) {

	this.country_code = country_code;
	this.package_name = package_name;
	this.currency = currency;
	this.yatra_rating = yatra_rating;
	this.inclusion = inclusion;
	this.ups = ups;
	this.roomRate = roomRate;
	this.duration = duration;
	this.themes = themes;
	this.package_image = package_image;
	this.grouptourstr = grouptourstr;
	this.discount = discount;
	this.yatra_rating = yatra_rating;
	this.traveler_rating = traveler_rating;
	this.dayWiseDurationString = dayWiseDurationString;
	this.s_v_date = s_v_date;
	this.e_v_date = e_v_date;
	this.package_id = package_id;
	this.package_type = package_type;
	this.airfare = airfare;
	this.discount_message = discount_message;
	this.discount_type = discount_type;
	this.currency = currency;
	this.on_request = on_request;
	this.themeicon = themeicon;
	this.cashback_discount = cashback_discount;
	this.package_sub_name = package_sub_name;
	this.supplier_code = supplier_code;
	
}
function setObject(package_id, country_code, package_name, currency, yatra_rating, s_s_date, e_s_date, s_v_date, e_v_date, domint, on_request, ups, duration, package_image, inclusion,roomRate,duration,themes,grouptourstr, discount, yatra_rating, traveler_rating, dayWiseDurationString, airfare, package_type, discount_message, discount_type, currency, themeicon, cashback_discount, package_sub_name, supplier_code, sortedArray){
	if(sortedArray == 1){
		myObjectArray[objectArrayIndex++] = new ownObject(package_id, country_code, package_name, currency, yatra_rating, s_s_date, e_s_date, s_v_date, e_v_date, domint, on_request, ups, duration, package_image, inclusion, roomRate, duration, themes, grouptourstr, discount, yatra_rating, traveler_rating, dayWiseDurationString, airfare, package_type, discount_message, discount_type,currency, themeicon, cashback_discount, package_sub_name, supplier_code);

		myObjectArrayDuration[objectArrayIndex2++] = new ownObject(package_id, country_code, package_name, currency, yatra_rating, s_s_date, e_s_date, s_v_date, e_v_date, domint, on_request, ups, duration, package_image, inclusion, roomRate, duration, themes, grouptourstr, discount, yatra_rating, traveler_rating, dayWiseDurationString, airfare, package_type, discount_message, discount_type, currency, themeicon, cashback_discount, package_sub_name, supplier_code);
	}else{
		mySortedObjectArray[objectArrayIndex1++] = new ownObject(package_id, country_code, package_name, currency, yatra_rating, s_s_date, e_s_date, s_v_date, e_v_date, domint, on_request, ups, duration, package_image, inclusion, roomRate, duration, themes, grouptourstr, discount, yatra_rating, traveler_rating, dayWiseDurationString, airfare, package_type, discount_message, discount_type, currency, themeicon, cashback_discount, package_sub_name, supplier_code);
	}
}
function myObjectBubbleSort(arrayName,length) {
    for (var i=0; i<(length-1); i++)
        for (var j=i+1; j<length; j++)
            if (arrayName[j].roomRate < arrayName[i].roomRate) {
                var dummy = arrayName[i];
                arrayName[i] = arrayName[j];
                arrayName[j] = dummy;
            }
}
function myObjectBubbleSortByDuration(arrayName,length) {
    for (var i=0; i<(length-1); i++)
        for (var j=i+1; j<length; j++)
            if (arrayName[j].duration < arrayName[i].duration) {
                var dummy = arrayName[i];
                arrayName[i] = arrayName[j];
                arrayName[j] = dummy;
            }
}

var objectArrayIndex = 0;
var objectArrayIndex1 = 0;
var objectArrayIndex2 = 0;
var myObjectArray = new Array();
var myObjectArrayDuration = new Array();
var mySortedObjectArray = new Array();

function showObjectArray(element,pageid) {
	showLightBox();
	var data = '';
	var totalCount=0;
	var ctr=0;
	if(element == "sort"){
		var object1 = myObjectArray;
		var duration1 = document.getElementById("lessdurationcon").value;
		var duration2 = document.getElementById("moredurationcon").value;
		var price1 = document.getElementById("lesspricecon").value;
		var price2 = document.getElementById("morepricecon").value;
		var groupTourEnable = document.getElementById("gtenable").value; 
		objectArrayIndex1 = 0;
		mySortedObjectArray = new Array();
		for(var i=0; i<myObjectArray.length; i++){
			var dateStr = object1[i].e_v_date;
			var stDateArray = dateStr.split('\-');
			dateStr = stDateArray[1]+"/"+stDateArray[2]+"/"+stDateArray[0];
			var packageStartDate = new Date(dateStr);
			var searchStartDate = new Date(document.getElementById('stdate').value);
			var regAH = /^a/i;
			var regH = /^h/i;
			var ptype = object1[i].package_type
        	if((object1[i].duration >= duration1 && object1[i].duration <= duration2) && (object1[i].roomRate >= price1 && object1[i].roomRate <= price2) && (packageStartDate >= searchStartDate) &&	((document.filter.sorthotel[0].checked && ptype.match(regAH)) || (document.filter.sorthotel[1].checked && ptype.match(regH)))){
				var condition=0;
				if((groupTourEnable == "IND" && object1[i].grouptourstr == "") || (groupTourEnable == "GT" && object1[i].grouptourstr != "") || (groupTourEnable == "")){

				for (var counter = 0; counter < document.filter.themesChk.length; counter++){
					var valRegx = new RegExp(document.filter.themesChk[counter].value);
					var str = myObjectArray[i].themes;
					if (document.filter.themesChk[counter].checked && str.match(valRegx)){
							condition =1;
					}
				}}
				if(condition == 1){	
					document.getElementById('notFound').style.display='none';
					setObject(myObjectArray[i].package_id, myObjectArray[i].country_code, myObjectArray[i].package_name, myObjectArray[i].currency, myObjectArray[i].yatra_rating, myObjectArray[i].s_s_date, myObjectArray[i].e_s_date, myObjectArray[i].s_v_date, myObjectArray[i].e_v_date, myObjectArray[i].domint, myObjectArray[i].on_request, myObjectArray[i].ups, myObjectArray[i].duration, myObjectArray[i].package_image, myObjectArray[i].inclusion, myObjectArray[i].roomRate, myObjectArray[i].duration, myObjectArray[i].themes, myObjectArray[i].grouptourstr, myObjectArray[i].discount, myObjectArray[i].yatra_rating, myObjectArray[i].traveler_rating, myObjectArray[i].dayWiseDurationString, myObjectArray[i].airfare, myObjectArray[i].package_type, myObjectArray[i].discount_message, myObjectArray[i].discount_type, myObjectArray[i].currency, myObjectArray[i].themeicon, myObjectArray[i].cashback_discount, myObjectArray[i].package_sub_name, myObjectArray[i].supplier_code); 
					ctr++;
				}
	        }
	    }
		if(ctr == 0){	
			//document.getElementById('notFound').style.display='block';
			for(var i=0; i<myObjectArray.length; i++){
				setObject(myObjectArray[i].package_id, myObjectArray[i].country_code, myObjectArray[i].package_name, myObjectArray[i].currency, myObjectArray[i].yatra_rating, myObjectArray[i].s_s_date, myObjectArray[i].e_s_date, myObjectArray[i].s_v_date, myObjectArray[i].e_v_date, myObjectArray[i].domint, myObjectArray[i].on_request, myObjectArray[i].ups, myObjectArray[i].duration, myObjectArray[i].package_image, myObjectArray[i].inclusion, myObjectArray[i].roomRate, myObjectArray[i].duration, myObjectArray[i].themes, myObjectArray[i].grouptourstr, myObjectArray[i].discount, myObjectArray[i].yatra_rating, myObjectArray[i].traveler_rating, myObjectArray[i].dayWiseDurationString, myObjectArray[i].airfare, myObjectArray[i].package_type, myObjectArray[i].discount_message, myObjectArray[i].discount_type, myObjectArray[i].currency, myObjectArray[i].themeicon, myObjectArray[i].cashback_discount, myObjectArray[i].package_sub_name, myObjectArray[i].supplier_code); 
				ctr++;
				document.getElementById("lessdurationcon").value=myObjectArrayDuration[0].duration;
				document.getElementById("moredurationcon").value=myObjectArrayDuration[maxLen1].duration+1;
				document.getElementById("lessdurationconSpan").innerHTML = $("#lessdurationcon").val();
				document.getElementById("moredurationconSpan").innerHTML = $("#moredurationcon").val();
			}
		}
		pagination(ctr,pageid);
		var object = mySortedObjectArray;
	}
	var start = (pageid - 1) * numPerPage; 
	var limit = pageid * numPerPage; 
	if(limit > ctr){
		limit = ctr;
	}
	var tmpctr=0;
	for(var i=start; i<limit; i++){
		var tempData='';
		var package_name=object[i].package_name;
		tempData = offerString.replace(/_PACKAGE_NAME_/g, package_name.substr(0,28));
		if(object[i].package_sub_name != "")
			tempData = tempData.replace(/_S_PACK_NAME_/, "("+object[i].package_sub_name+")");
		else
			tempData = tempData.replace(/_S_PACK_NAME_/, "");
		tempData = tempData.replace(/_DURATION_/g, object[i].duration);
		tempData = tempData.replace(/_CURRENCY_/g,  object[i].currency);
		tempData = tempData.replace(/_ROOM_RATE_/g, FormatNumber(object[i].roomRate));
		//tempData = offerString.replace(/_PACKAGE_SHORT_NAME_/, package_name);
		if(object[i].package_image)
			imgName=object[i].package_image;
		else
			imgName="/images/holiday/hotelimage.jpg";
		tempData = tempData.replace(/_PACKAGE_IMAGE_/g, imgName);
		if(object[i].yatra_rating != ''){

			tempData = tempData.replace(/_DISPLAY_RATINGH_/g,  'block;');
			tempData = tempData.replace(/_YATRA_RATING_/g,  object[i].yatra_rating);
		}else{
			tempData = tempData.replace(/_DISPLAY_RATINGH_/g,  'none;');
		}
		tempData = tempData.replace(/_YATRA_RATING_/g,  durStr);
		tempData = tempData.replace(/_PACKAGE_ID_/g,  object[i].package_id);
		var durStr = object[i].duration - 1+" Nights/ "+object[i].duration+" Days";
		tempData = tempData.replace(/_NIGHTS_DAYS_/g,  durStr);
		var dateStr = object[i].e_v_date;
		var dateArray = dateStr.split('\-');
		if(dateArray[1]=="08"){dateArray[1] = 8}
		if(dateArray[1]=="09"){dateArray[1] = 9}
		dateStr = dateArray[2]+" "+m_names[parseInt(dateArray[1]-1)]+" "+dateArray[0];
		tempData = tempData.replace(/_PACKAGE_VALID_/g, dateStr);
		tempData = tempData.replace(/_INCLUSION_/g,  object[i].inclusion);
		tempData = tempData.replace(/_DESCRIPTION_/g,  object[i].package_desc);
		tempData = tempData.replace(/_PACKAGE_DISCOUNT_/g, object[i].discount);
		tempData = tempData.replace(/_PACKAGE_TYPE_DISCOUNT_/g, object[i].discount_type);
		tempData = tempData.replace(/_DISCOUNT_MESSAGE_/g, object[i].discount_message);
		tempData = tempData.replace(/_CASHBACK_DISCOUNT_/g, object[i].cashback_discount);
		tempData = tempData.replace(/_PACK_TYPE_/g, object[i].package_type);
		if(object[i].discount != '' || object[i].discount != 0.00){
			var discountStr = object[i].discount;
			if(object[i].discount_type == 'P')
					discountStr += '%';
			else discountStr = object[i].currency+" "+discountStr;
			if(object[i].discount_message != '')
				discountStr += " "+object[i].discount_message;
			tempData = tempData.replace(/_DISPLAY_DISCOUNT_/g,  'block;');
			tempData = tempData.replace(/_DISCOUNT_TAG_/g,  discountStr);
		}else{
			tempData = tempData.replace(/_DISPLAY_DISCOUNT_/g,  'none;');
		}
		if(object[i].grouptourstr == ''){
			tempData = tempData.replace(/_GT_DISPLAY_/g,  'none');
		}else{
			tempData = tempData.replace(/_GT_DISPLAY_/g,  'block');
			tempData = tempData.replace(/_GROUP_TOUR_/g,  object[i].grouptourstr);
		}
		tempData = tempData.replace(/_TOUR_HIGHLIGHT_/g,  object[i].ups);
		tempData = tempData.replace(/_Destination_Matrix_/g,  object[i].dayWiseDurationString);
		tempData = tempData.replace(/_COUNT_/g, tmpctr);
		tempData = tempData.replace(/_SEARCH_ID_/g, search_id);
		tempData = tempData.replace(/_S_V_DATE_/g, object[i].s_v_date);
		tempData = tempData.replace(/_E_V_DATE_/g, object[i].e_v_date);
		tempData = tempData.replace(/_CUR_DATE_/g, object[i].s_v_date);
		if(object[i].package_type == "ahp" || object[i].package_type == "ahi" ){
			tempData = tempData.replace(/_TOOL_TRIP_/g, 'id="priceBreaking_COUNTER_" style="cursor:pointer;" title="_BREAKING_PRICE_"');
			tempData = tempData.replace(/_BREAKING_PRICE_/g, object[i].airfare);
			tempData = tempData.replace(/_COUNTER_/g, tmpctr);
			tempData = tempData.replace(/_RATE_HREF_/g, '<a href="javascript:return false;" class="step2priceheading">');
		}else{
			tempData = tempData.replace(/_RATE_HREF_/g, '');
		}
		tempData = tempData.replace(/_ON_REQUEST_/g, object[i].on_request);
		//if(object[i].on_request == 1){
			tempData = tempData.replace(/_ACTION_PAGE_/g, "requestForm");
			tempData = tempData.replace(/_SUBMIT_BUTTON_/g, "submitbutton");
			tempData = tempData.replace(/_HREF_ID_/g, "request");
		/*}else{
			tempData = tempData.replace(/_ACTION_PAGE_/g, "get_cal");
			tempData = tempData.replace(/_SUBMIT_BUTTON_/g, "check_availbility");
			tempData = tempData.replace(/_HREF_ID_/g, "cal1");			
		}*/
		tempData = tempData.replace(/_THEMES_ICON_/g, object[i].themeicon);
		tempData = tempData.replace(/_SUPPLIER_IMG_/g, object[i].supplier_code);
		tmpctr++;
		data += tempData;
	}

document.getElementById("sorted_results").innerHTML='';
document.getElementById("sorted_results").innerHTML=data;

setTimeout("hideLightBox()",600);	
}

function pagination(totalCount, currentPage){ 
	var numPages = Math.ceil(totalCount / numPerPage);
	if(numPages > 1){
		var pagination='';
		var ctrPage = 0;
		if(currentPage > 1){
			ctrPage = currentPage-1;
			pagination += '<a href="javascript:showObjectArray(\'sort\','+ctrPage+')">Prev</a>&nbsp;&nbsp;';
		}else{
			pagination += 'Prev&nbsp;&nbsp;';
		}
		for(var i=1; i<=numPages; i++){
			if(i != currentPage){
				pagination += '<a href="javascript:showObjectArray(\'sort\','+i+')">'+i+'</a>&nbsp;&nbsp;';
			}else{
				pagination += i+'&nbsp;&nbsp;';
			}
		}
		if(currentPage < numPages){
			ctrPage = currentPage+1
			pagination += '<a href="javascript:showObjectArray(\'sort\','+ctrPage+')">Next</a>&nbsp;&nbsp;';
		}else{
			pagination += 'Next&nbsp;&nbsp;';
		}
		document.getElementById("paginationTop").innerHTML='';
		document.getElementById("paginationTop").innerHTML=pagination;
		document.getElementById("paginationBot").innerHTML='';
		document.getElementById("paginationBot").innerHTML=pagination;
		document.getElementById('spanerrors').scrollIntoView();
	}else{
		document.getElementById("paginationTop").innerHTML='';
		document.getElementById("paginationBot").innerHTML='';
	}
	document.getElementById("resultfoundheading").innerHTML=totalCount+" Holiday packages found";
	setTimeout("defaultScripts()",100);
}
function defaultScripts(){
	   $(document).ready(function(){
				$("a[id='destinationGuide']").colorbox({width:"800", height:"500"});
				
				$("a[id='cal0'],a[id='cal1'],a[id='cal2'],a[id='cal3'],a[id='cal4'],a[id='cal5'],a[id='cal6'],a[id='cal7'],a[id='cal8'],a[id='cal9'],a[id='cal10'],a[id='cal11'],a[id='cal12']").colorbox({transition:"none", width:"400", height:"535", align:"center", iframe:true});

				$("a[id='request']").colorbox({ width:"555", height:"570", iframe:true});
				
				$("a[id='tellafriend']").colorbox({ width:"450", height:"370", iframe:true});

				$("#priceBreaking0, #priceBreaking1, #priceBreaking2, #priceBreaking3, #priceBreaking4, #priceBreaking5, #priceBreaking6, #priceBreaking7, #priceBreaking8, #priceBreaking9, #priceBreaking10, #priceBreaking11, #priceBreaking12, #priceBreaking13, #priceBreaking14, #priceBreaking15").tooltip({
					track: true,
					delay: 0,
					showURL: false,
					fixPNG: true,
					showBody: " - ",
					extraClass: "pretty priceBreaking",
					top: -15,
					left: 5
				});

				
	   });
	   $(document).ready(function(){  
			$(".rss-popup a").hover(function() {
				$(this).next("em").stop(true, true).animate({opacity: "show", top: "-60"}, "slow");
			}, function() {
				$(this).next("em").animate({opacity: "hide", top: "-70"}, "fast");
			});
		   
		});  
}

//for formating number ;
var N=navigator.appName;
var V=navigator.appVersion.split(';')
V=parseInt(V[1].substring(6,7));
function FormatNumber(amount){
    if(N=="Microsoft Internet Explorer" && V<6){
        var am=amount;
                return am;
        }else{
                var delimiter = ","; // replace comma if desired
                var a=amount;
                var i = amount;
                if(isNaN(i)) { return ''; }
                var minus = '';
                if(i < 0) { minus = '-'; }
                i = Math.abs(i);
                var n = new String(i);
                var a = [];
                while(n.length > 3){
            var nn = n.substr(n.length-3);
                        a.unshift(nn);
                        n = n.substr(0,n.length-3);
                   }
                if(n.length > 0) { a.unshift(n); }  
                n = a.join(delimiter);
                amount = n  
                amount = minus + amount;
                return amount;
    }
}
function calculatePrice(val){
	var packageTotal=0;
	var tmpVal;
	var package_price,airfare,tax,visafee,childairfare;
	var splitArray;
	if(val == 'AF'){
		var selIndex = document.package_detail.city_code.selectedIndex;
		var city_code = document.package_detail.city_code.options[selIndex].value;
		splitArray = city_code.split("|");
		airfare = splitArray[1];
		childairfare = airfare*75/100;
		tax = splitArray[3];
		visafee = splitArray[2];
		for (var i=1; i<document.package_detail.package_code.length; i++)  {
			var package_code= document.package_detail.package_code[i].value;
			var splitArray = package_code.split("|");
			tmpVal = splitArray[1];
			package_price = splitArray[0].replace(/,/, "") ;
			packageTotal = (parseInt(package_price)+parseInt(airfare)+parseInt(visafee)+parseInt(tax));
			if(document.getElementById("adultPrice"+(i-1)))document.getElementById("adultPrice"+(i-1)).innerHTML = FormatNumber(Math.round(packageTotal));
			package_price = splitArray[3].replace(/,/, "") ;
			packageTotal = (parseInt(package_price)+parseInt(childairfare)+parseInt(visafee)+parseInt(tax));
			if(document.getElementById("childPrice"+(i-1)))document.getElementById("childPrice"+(i-1)).innerHTML = FormatNumber(Math.round(packageTotal));
		}
	}
	for (var i=0; i<document.package_detail.package_code.length; i++)  {
		if (document.package_detail.package_code[i].checked)  {
			var package_code= document.package_detail.package_code[i].value;
			var splitArray = package_code.split("|");
			document.getElementById("room_code").value = splitArray[2];
			tmpVal = splitArray[1];
			package_price = splitArray[0].replace(/,/, "") ;
		} 
	}
	if(document.package_detail.city_code){
		var selIndex = document.package_detail.city_code.selectedIndex;
		var city_code = document.package_detail.city_code.options[selIndex].value;
		splitArray = city_code.split("|");
		airfare = splitArray[1];
		childairfare = airfare*75/100;
		tax = splitArray[3];
		visafee = splitArray[2];
		document.getElementById("air_city_code").value = splitArray[4];
		package_price = (parseInt(package_price)+parseInt(airfare)+parseInt(visafee)+parseInt(tax));
	}
	document.getElementById("priceLarge").innerHTML = FormatNumber(Math.round(package_price));
	document.getElementById("rate").value = Math.round(package_price);
}

