﻿// JScript File
//Custom Validator Function
//Validate if the Selected Item of the Drop Down is not the first item... if it is then error
function DropDownValidateCountryMandatory(source, arguments){    
    if(arguments.Value == 0)
    { 
        arguments.IsValid = false;        
    }
    else
    {
        arguments.IsValid = true;            
    }
}


function getRootURL() {
    var baseURL = location.href;
    var rootURL = baseURL.substring(0, baseURL.indexOf('/', 7));

    // if the root url is localhost, don't add the directory as cassani doesn't use it
    if (baseURL.indexOf('localhost') == -1) {
        return rootURL + "/";
    } else {
    return rootURL + baseURL.substring(baseURL.indexOf('/', 8), baseURL.indexOf('/', baseURL.indexOf('/', 8)+1)) + "/";        
    }
}

function DropDownValidateTypeMandatory(source, arguments){    
    if(arguments.Value == 0)
    {
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;
    }
}


function DropDownValidateReviewMandatory(source, arguments){    
    if(arguments.Value == '-')
    {
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;            
    }
}

function ValidateInputSize(source, arguments){    
    if(arguments.Value.length >=50)
    {
        arguments.IsValid = true;
    }
    else
    {
        arguments.IsValid = false;
    }
}

function HideElement(objName){
    document.getElementById(objName).style.visibility = "hidden";
    document.getElementById(objName).style.position = "absolute";
}

function ClearTextOnClickField(objName,objDefaultValue){
    if(document.getElementById(objName).value == objDefaultValue)
        document.getElementById(objName).value = "";        
}

function OpenHelpPopup(page,anchor,width,height){
	var screenW = screen.width;
	var screenH = screen.height;	
	var hndWin = window.open(page + "#" + anchor,'helpwindow','height='+height+',width='+width+',toolbar=no,menubar=no,resizable=no,scrollbars=yes');						
	hndWin.moveTo(screenW - width - 10 ,screenH/5);
}

function OpenEditPopup(page,width,height){
	var screenW = screen.width;
	var screenH = screen.height;	
	var hndWin = window.open(page,'helpwindow','height='+height+',width='+width+',toolbar=no,menubar=no,resizable=no,scrollbars=no');						
	hndWin.moveTo(screenW - width - 10 ,screenH/5);
}

function EditHotel(IdAccommodation, IdLanguage){
	var screenW = screen.width;
	var screenH = screen.height;
	var page = IdLanguage + "-EditAccommodation.aspx?a=" + IdAccommodation;
	var hndWin = window.open(page,'helpwindow','height='+560+',width='+620+',toolbar=no,menubar=no,resizable=no,scrollbars=yes');						
	hndWin.moveTo(screenW - 615 - 10 ,screenH/5);
}

function OpenImagePopup(imgName){				
	var currentImage = document.getElementById(imgName).src;										
	var firstAmp = currentImage.indexOf("&");
    currentImage = currentImage.substring(0, firstAmp);
	var imgAlt = document.getElementById(imgName).alt;												
	var newWind = window.open("viewimage.aspx?imgurl=" + currentImage + "&fullsrc=y&alt=" + imgAlt,'ImageViewer','height=275,width=375,toolbar=no,menubar=no,resizable=yes,scrollbars=yes');					
}

function OpenReviewImagePopup(imgName){					
	var currentImage = document.getElementById(imgName).src;										
	var imgAlt = document.getElementById(imgName).alt;												
	var newWind = window.open("viewimage.aspx?imgurl=" + currentImage + "&fullsrc=y&r=y&alt=" + imgAlt,'ImageViewer','height=275,width=375,toolbar=no,menubar=no,resizable=yes,scrollbars=yes');					
}

function showPhotoGallery(IdAccommodationDetail){						
	var newWind = window.open("photogallery.aspx?a=" + IdAccommodationDetail,'PhotoGallery','height=500,width=350,toolbar=no,menubar=no,resizable=no,scrollbars=no');					
}


function ShowHideVistorInfo(str){
	if(str == "y"){			
		document.getElementById('reviewerInfo').style.visibility = 'hidden';
		document.getElementById('reviewerInfo').style.position = 'absolute';		
	}else
	{				
		document.getElementById('reviewerInfo').style.visibility = 'visible';
		document.getElementById('reviewerInfo').style.position = 'static';		
	}	
}

function SwapImage(imgNo){
	var img = new Array("images/world_unselected.gif","images/region_NAmerica.gif","images/region_Asia.gif","images/region_Caribbean.gif","images/region_Africa.gif","images/region_Europe.gif","images/region_MEast.gif","images/region_CAmerica.gif","images/region_Oceania.gif","images/region_SAmerica.gif");					
	document.getElementById('myImage').src = img[imgNo];
}

function enlargeMap()
{   
    document.getElementById("mapholder").style.position = 'absolute';
    document.getElementById("mapholder").style.width = '500px';
    document.getElementById("mapholder").style.height = '320px';
//    document.getElementById("mapholder").style.clip = 'rect(50px, 50px, 50px, 50px)';     
      
    document.getElementById("map").style.width = '500px';
    document.getElementById("map").style.height = '300px';          
    mapChangeSize();
                       
    document.getElementById("ctl00_m_lnkSeeMore").style.visibility = "hidden";                             
    document.getElementById("ctl00_m_lnkSeeLess").style.visibility = "visible";      
    document.getElementById("ctl00_m_lnkSeeLess").style.position = "relative";      
}

function resizeMap()
{
    document.getElementById("mapholder").style.position = 'relative';
    document.getElementById("mapholder").style.width = '172px';
    document.getElementById("mapholder").style.height = '132px';    
    document.getElementById("map").style.position = 'relative';    
    document.getElementById("map").style.width = '172px';
    document.getElementById("map").style.height = '132px';  
    document.getElementById("map").style.padding = '0px';        
    mapChangeSize();
    
    document.getElementById("ctl00_m_lnkSeeLess").style.visibility = "hidden";      
    document.getElementById("ctl00_m_lnkSeeLess").style.position = "absolute";
    document.getElementById("ctl00_m_lnkSeeMore").style.visibility = "visible";          
}

function redirect_to_page()
{
    window.location = "../" + url;    
}


function toggle_filter_box_visibility()
{
    var imgArrowDown = "images/gen_arrow_down.gif";
    var imgArrowNormal = "images/gen_arrow_normal.gif";
    
    var objFilterBoxTable = document.getElementById("filter_box_table");
    var imgArrowObject = document.getElementById("filter_box_arrow");       
    
    if(objFilterBoxTable.style.visibility == 'hidden')
    {
        //Make Visible
        objFilterBoxTable.style.visibility = 'visible';
        objFilterBoxTable.style.position = 'relative';
        imgArrowObject.src = imgArrowDown;
    }
    else
    {
        //Make Invisible
        objFilterBoxTable.style.visibility = 'hidden';
        objFilterBoxTable.style.position = 'absolute';        
        imgArrowObject.src = imgArrowNormal;
    }
}


function redirectDefault(IdLanguage)
{
    window.location = IdLanguage + "-default.aspx";
}


function ShowAddPhoto()
{
    window.open('ImageUploader.aspx?Review=y','Add Photo','height=500,width=500,status=yes,toolbar=no,menubar=no,location=no');       
}

function ShowMessageBox(objSubject)
{    
    window.open("SendMessage.aspx?s=" + objSubject + "","SendMessage","height=300,width=550,status=yes,toolbar=no,menubar=no,location=no");       
}

function OpenRates(IdAcc)
{
    var newWind = window.open("Affiliate.aspx?a=" + IdAcc, 'Affiliate','height=275,width=450,toolbar=no,menubar=no,resizable=yes,scrollbars=yes');					
}

function OpenUploadVideo(objReferer)
{
    var newWind = window.open("UploadMedia.aspx?ref=" + objReferer, 'UploadVideo','height=275,width=400,toolbar=no,menubar=no,resizable=no,scrollbars=no');					
}

function RecommendationChecked(obj, objValidator, status)
{
    document.getElementById(obj).value = status;
    document.getElementById(objValidator).style.visibility = "hidden";
    document.getElementById(objValidator).style.display = "none";                    
}


function HiglightPad(ePadName, objPad)
{    
    //objPad.style.cursor = "hand";
    objPad.style.cursor = "pointer";    
    objPad.setAttribute("id",ePadName + "_h");
}

function UnHiglightPad(ePadName, objPad)
{
    objPad.setAttribute("id",ePadName);
}

function NavigatePad(ePadName)
{
    var lnk = document.getElementById(ePadName + "_link");
    window.location = lnk.href;
}

var timeoutperiod = 2000;
var timeObj;

function showGreenLabelInfo()
{    
    clearTimeout(timeObj);
    document.getElementById("ecoLabelInfo").style.visibility = "visible";            
}

function hideGreenLabelInfo()
{    
    document.getElementById("ecoLabelInfo").style.visibility = "hidden";    
}

function resetTimeOut()
{
    clearTimeout(timeObj);
    timeObj = setTimeout("hideGreenLabelInfo()",timeoutperiod);
}

function startTimeOut()
{
    timeObj = setTimeout("hideGreenLabelInfo()",timeoutperiod);
}


function statwords(message){
window.status = message;
}


var affiliateList = new Array();

function addToArray(aIndex, strArrayElement)
{
    affiliateList[aIndex] = strArrayElement;
}

function SeeOffers(startIndex)
{    
    var windh;
    var hasBlocker = false;
    var i = startIndex;    
    for(i=startIndex;i<affiliateList.length;i++)
    {        
        var splIndex = affiliateList[i].indexOf("|");
        var name = affiliateList[i].substring(0, splIndex);
        var url = affiliateList[i].substring((splIndex + 1));
        var objCheckBox = document.getElementById("chk_" + name);        
        if(objCheckBox.checked)
        {            
            windh = window.open(url, name);
            if(windh == null)
                hasBlocker = true;
        }
    }        
    
    if(hasBlocker)
    {
        alert(document.getElementById("ctl00_ContentPlaceHolder1_lblPopUpBlocker").innerHTML);
    }
}

function SetLanguagePref(lang)
{    
    createCookie("FlagLang", lang, 1825);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function removeQueryString(url)
{
    var url = new String(url);
    return url.replace(/\?.*$/, "");
}

//Performs a redirection to the specified url
function doRedirection(url)
{
    window.location = url;
}

function gotoURL(root, obj)
{
    if(obj.value != "")
        window.location = root + obj.value;
}


function addToNewsletter(email, idlanguage)
{
    jQuery.facebox(function() {
            $.ajax({
                type: "POST",
                url: "AJAXHandler.asmx/AddToNewsLetter",
                data: "{ 'Email': '" + email + "', 'IdLanguage': '" + idlanguage + "' }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {                
                        jQuery.facebox(msg);
                 },
                error: function(msg) {
                    jQuery.facebox(msg);
                }
            });
    });
}

$(document).ready(function() {
   $("input[type='radio']").css("border", "0 none");
   $("input[type='checkbox']").css("border", "0 none");
   var array = new Array();
   //External Links will be openned in new window
   //If popup blocker open the link
   $(".popup").click(function(){

       if (jQuery.browser.msie)
          {

                
                array[0] = this.href;
                try
                {
                    var oWin = window.open(this.href,array[0], "height=480px, width=640px, resizable=yes, menubar=yes, toolbar=yes, location=yes, scrollbars=yes");
                
 
                    if (oWin==null || typeof(oWin)=="undefined")
                        {
                            return true;
                        }
                    else
                        {
                            return false;
                        }
                 }    
             
                catch(err)
                 {    
                
                 }
               
           }
       else
           {
                  
                var popUpName1 = window.open(this.href, "\"" + this.href + "\"", "height=480px, width=640px, resizable=yes, menubar=yes, toolbar=yes, location=yes, scrollbars=yes");
                if (popUpName1==null || typeof(popUpName1)=="undefined")
                {
                    return true;
                }
                else
                {
                    return false;
                }
           }
        

   });
   $(".popup2").click(function(){
       if (jQuery.browser.msie)
          {     
                array[0] = this.href;
                try
                {
                    var oWin = window.open(this.href,array[0], "height=480px, width=640px, resizable=yes, menubar=yes, toolbar=yes, location=yes, scrollbars=yes");
               
                    if (oWin==null || typeof(oWin)=="undefined")
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch(err)
                {}
           }
       else
           {
                var popUpName2 = window.open(this.href, "\"" + this.href + "\"", "height=480px, width=640px, resizable=yes, menubar=yes, toolbar=yes, location=yes, scrollbars=yes");
                if (popUpName2==null || typeof(popUpName2)=="undefined")
                {
                    return true;
                }
                else
                {
                    return false;
                }
           }
        
   });
   $(".popup3").click(function(){
       if (jQuery.browser.msie)
          { 
                array[0] = this.href;
                try
                {
                    var oWin = window.open(this.href,array[0], "height=480px, width=640px, resizable=yes, menubar=yes, toolbar=yes, location=yes, scrollbars=yes");
               
                    if (oWin==null || typeof(oWin)=="undefined")
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch(err)
                {}
           }
       else
           {
                var popUpName3 = window.open(this.href, "\"" + this.href + "\"", "height=480px, width=640px, resizable=yes, menubar=yes, toolbar=yes, location=yes, scrollbars=yes");
                if (popUpName3==null || typeof(popUpName3)=="undefined")
                {
                    return true;
                }
                else
                {
                    return false;
                }
           }
   });
});

function openPopupURL(anchorLink)
{
       if (jQuery.browser.msie)
          {
                var oWin = window.open(anchorLink,"oWin", "height=480px, width=640px, resizable=yes, menubar=yes, toolbar=yes, location=yes, scrollbars=yes");
           
                if (oWin==null || typeof(oWin)=="undefined")
                {
                    return true;
                }
                else
                {
                    return false;
                }
           }
       else
           {
                var popUpName4 = window.open(anchorLink, "\"" + anchorLink + "\"", "height=480px, width=640px, resizable=yes, menubar=yes, toolbar=yes, location=yes, scrollbars=yes");
                if (popUpName4==null || typeof(popUpName4)=="undefined")
                {
                    return true;
                }
                else
                {
                    return false;
                }
           }
}
