function submenuDisplay(menuId){
    var obj=document.getElementById(menuId);
    var curleft=curtop=0;
    if(obj.offsetParent){
        do{
            curleft+=obj.offsetLeft;
            curtop+=obj.offsetTop;
        }while(obj=obj.offsetParent);
    }
    document.getElementById('land1').style.top=curtop+"px";
    document.getElementById('land1').style.left=curleft+"px";
    document.getElementById('land1').style.display="";
}
function disappearText(control,appearText){
    var inputControl=document.getElementById(control);
    if(inputControl.value==appearText){
        inputControl.value='';
    }
}
function btnChangeBackColor(buttonId,colorCode){
    document.getElementById(buttonId).style.backgroundColor=colorCode;
}
function restrictVideoSizeSameOnHomePage(){
    for(var i=0;i<document.getElementsByTagName('embed').length;i++){
        document.getElementsByTagName('embed')[i].width='192px';
        document.getElementsByTagName('embed')[i].height='155px';
    }
}
function restrictVideoSizeSame(){
    for(var i=0;i<document.getElementsByTagName('embed').length;i++){
        document.getElementsByTagName('embed')[i].width='300px';
        document.getElementsByTagName('embed')[i].height='236px';
    }
}
function showHideDiv(showDivId,hideDivId){
    document.getElementById(showDivId).style.display='';
    document.getElementById(hideDivId).style.display='none';
}
var is_chrome=/chrome/.test(navigator.userAgent.toLowerCase());
var is_set='';
var rating_value=0;
function changeImage(imageNumber,blankImage,fullImage,ulId,width,height){
    is_set='';
    rating_value=0;
    document.getElementById(ulId).innerHTML="";
    var imgStr='<li class="label rating">'+ulId+':</li>';
    var i;
    var j=5-imageNumber;
    for(i=1;i<=imageNumber;i++){
        imgStr+='<li><img src='+fullImage+' width='+width+' height='+height+' onmouseout="orgImage(\''+blankImage+'\',\''+fullImage+'\',\''+ulId+'\',\''+width+'\',\''+height+'\')" onclick="setImage('+i+',\''+blankImage+'\',\''+fullImage+'\',\''+ulId+'\',\''+width+'\',\''+height+'\')"></li>';
    }
    for(var m=1;m<=j;m++){
        i=m+imageNumber;
        imgStr+='<li><img src='+blankImage+' width='+width+' height='+height+' onmouseout="orgImage(\''+blankImage+'\',\''+fullImage+'\',\''+ulId+'\',\''+width+'\',\''+height+'\')" onmouseover="changeImage('+i+',\''+blankImage+'\',\''+fullImage+'\',\''+ulId+'\',\''+width+'\',\''+height+'\')"></li>';
    }
    document.getElementById(ulId).innerHTML=imgStr;
}
function orgImage(blankImage,fullImage,ulId,width,height){
    var imgStr='<li class="label rating">'+ulId+':</li>';
    var i;
    for(i=1;i<=5;i++){
        imgStr+='<li><img src='+blankImage+' width='+width+' height='+height+' onmouseover="changeImage('+i+',\''+blankImage+'\',\''+fullImage+'\',\''+ulId+'\',\''+width+'\',\''+height+'\')"></li>';
    }
    if(is_set!=''){
        document.getElementById(ulId).innerHTML=is_set;
        document.getElementById(ulId+'RatingValue').value=rating_value;
    }
    else{
        document.getElementById(ulId).innerHTML=imgStr;
        document.getElementById(ulId+'RatingValue').value=0;
    }
}
/*function setImage(imageNumber,blankImage,fullImage,ulId,width,height){
    is_set='';
    var imgStr='<li class="label rating">'+ulId+':</li>';
    var i;
    var j=5-imageNumber;
    for(i=1;i<=imageNumber;i++){
        if(i==imageNumber){
            imgStr+='<li><img src='+fullImage+' width='+width+' height='+height+'></li>';
        }
        else{
            imgStr+='<li><img src='+fullImage+' width='+width+' height='+height+' onmouseover="changeImage('+i+',\''+blankImage+'\',\''+fullImage+'\',\''+ulId+'\',\''+width+'\',\''+height+'\')"></li>';
        }
    }
    for(var m=1;m<=j;m++){
        i=m+imageNumber;
        imgStr+='<li><img src='+blankImage+'  width='+width+' height='+height+' onmouseover="changeImage('+i+',\''+blankImage+'\',\''+fullImage+'\',\''+ulId+'\',\''+width+'\',\''+height+'\')"></li>';
    }
    document.getElementById(ulId).innerHTML=imgStr;
    is_set=imgStr;
    document.getElementById(ulId+'RatingValue').value=imageNumber;
    rating_value=imageNumber;
}*/
function setImage(imageNumber,blankImage,fullImage,ulId,width,height){
    is_set='';
    var imgStr='<li class="label rating">'+ulId+':</li>';
    var i;
    var j=5-imageNumber;
    for(i=1;i<=imageNumber;i++){
        if(i==imageNumber){
            imgStr+='<li><img src='+fullImage+' width='+width+' height='+height+'></li>';
        }
        else{
            imgStr+='<li><img src='+fullImage+' width='+width+' height='+height+' ></li>';
        }
    }
    for(var m=1;m<=j;m++){
        i=m+imageNumber;
        imgStr+='<li><img src='+blankImage+'  width='+width+' height='+height+' ></li>';
    }
    document.getElementById(ulId).innerHTML=imgStr;
    is_set=imgStr;
    document.getElementById(ulId+'RatingValue').value=imageNumber;
    rating_value=imageNumber;
}

function validateRating(msg){
    alert(msg);
}
function checkedAll(frm,action){
    var aa=document.getElementById(frm);
    if(action==1){
        for(var i=0;i<aa.elements.length;i++)

        {
                aa.elements[i].checked=true;
            }
    }
    if(action==2){
        for(var i=0;i<aa.elements.length;i++)

        {
                aa.elements[i].checked=false;
            }
    }
}

function adventuresListDisclamerBox(openUrl) {
    var overlayHeight = $(document).height();
    var overlayWidth = $(window).width();
          	
    var dialogTop =  ($(window).height()/3) - ($('#advent-dialog-box').height())+(100+$(window).scrollTop());
    var dialogLeft = (overlayWidth/2) - ($('#advent-dialog-box').width()/2);
        
    $('#advent-dialog-box a.button.okbtn').attr('href',openUrl);
    $('#advent-dialog-box a.button.okbtn').click(function(){
        //console.log('click event triggered!');
        $('#advent-dialog-box .close').click();
        return true; 
    });
    
      
    $('#advent-dialog-overlay').css({
        height:overlayHeight, 
        width:overlayWidth
    }).show();
    $('#advent-dialog-box').css({
        top:dialogTop, 
        left:dialogLeft
    }).show();
			
			
    //Add timeout to close dialog box and go to the link URL
    setTimeout(function(){
        if(!$('#advent-dialog-box').is(':hidden')) {
            $('#advent-dialog-box .close').click();
            window.open(openUrl);
        }
    },3000);
			
    return false;
}


function extremeListDisclamerBox(openUrl) {
    var overlayHeight = $(document).height();
    var overlayWidth = $(window).width();
          	
    var dialogTop =  ($(window).height()/3) - ($('#extr-dialog-box').height())+(100+$(window).scrollTop());
    var dialogLeft = (overlayWidth/2) - ($('#extr-dialog-box').width()/2);
        
    //$('#extr-dialog-box a.accept_link').attr('href','javascript: $(\'#extr-dialog-box .close\').click(); window.open(\''+openUrl+'\'); return true; ' );
    $('#extr-dialog-box a.accept_link').attr('href',openUrl);
    $('#extr-dialog-box a.accept_link').click(function(){
        //console.log('click event triggered!');
        $('#extr-dialog-box .close').click();
        return true; 
    });
      
    $('#extr-dialog-overlay').css({
        height:overlayHeight, 
        width:overlayWidth
    }).show();
    $('#extr-dialog-box').css({
        top:dialogTop, 
        left:dialogLeft
    }).show();
			
			
    //Add timeout to close dialog box and go to the link URL
    setTimeout(function(){
        if(!$('#extr-dialog-box').is(':hidden')) {
            //$('#extr-dialog-box a.accept_link').click();
            $('#extr-dialog-box .close').click();            
            window.open(openUrl);
        }
    },5000);
			
    return false;
}


function sightsListDisclamerBox(openUrl) {
    var overlayHeight = $(document).height();
    var overlayWidth = $(window).width();
          	
    var dialogTop =  ($(window).height()/3) - ($('#sights-dialog-box').height())+(100+$(window).scrollTop());
    var dialogLeft = (overlayWidth/2) - ($('#sights-dialog-box').width()/2);
        

    $('#sights-dialog-box a.button.okbtn').attr('href',openUrl);
    $('#sights-dialog-box a.button.okbtn').click(function(){
        //console.log('click event triggered!');
        $('#sights-dialog-box .close').click();
        return true; 
    });
    
    $('#sights-dialog-overlay').css({
        height:overlayHeight, 
        width:overlayWidth
    }).show();
    $('#sights-dialog-box').css({
        top:dialogTop, 
        left:dialogLeft
    }).show();
			
			
    //Add timeout to close dialog box and go to the link URL
    setTimeout(function(){
        if(!$('#sights-dialog-box').is(':hidden')) {
            $('#sights-dialog-box .close').click();
            window.open(openUrl);
        }
    },5000);
			
    return false;
}

function voluteeringPanelDisclamerBox(openUrl) {
    var overlayHeight = $(document).height();
    var overlayWidth = $(window).width();
          	
    var dialogTop =  ($(window).height()/3) - ($('#volunt-dialog-box').height())+(100+$(window).scrollTop());
    var dialogLeft = (overlayWidth/2) - ($('#volunt-dialog-box').width()/2);
          	
    $('#volunt-dialog-box a.button.okbutton').attr('href',openUrl);    
    
    $('#volunt-dialog-box a.button.okbutton').click(function(){
        //console.log('click event triggered!');
        $('#volunt-dialog-box .close').click();
        return true; 
    });
    
    $('#volunt-dialog-overlay').css({
        height:overlayHeight, 
        width:overlayWidth
    }).show();
    $('#volunt-dialog-box').css({
        top:dialogTop, 
        left:dialogLeft
    }).show();
			
			
    //Add timeout to close dialog box and go to the link URL
    setTimeout(function(){
        if(!$('#volunt-dialog-box').is(':hidden')) {
            $('#volunt-dialog-box .close').click();
            window.open(openUrl);
        }
    },3000);
			
    return false;
}


function voluteeringDisclamerBox(openUrl) {
    var overlayHeight = $(document).height();
    var overlayWidth = $(window).width();
	
    var dialogTop =  ($(window).height()/3) - ($('#dialog-box').height())+(100+$(window).scrollTop());
    var dialogLeft = (overlayWidth/2) - ($('#dialog-box').width()/2);
	
        
    
        
        
    $('#dialog-overlay').css({
        height:overlayHeight, 
        width:overlayWidth
    }).show();
    $('#dialog-box .button.okbutton').attr('href',openUrl);
    $('#dialog-box a.button.okbutton').click(function(){
        //console.log('click event triggered!');
        $('#dialog-box .close').click();
        return true; 
    });
    
    $('#dialog-box').css({
        top:dialogTop, 
        left:dialogLeft
    }).show();
			
			
    //Add timeout to close dialog box and go to the link URL
    setTimeout(function(){
        if(!$('#dialog-box').is(':hidden')) {
            $('#dialog-box .close').click();
            window.open(openUrl);
        }
    },3000);
			
    return false;
}

$(function() {

    var tmpActivity = 0;
    var tmpObject = null;

    $('#sf-first, #sf-last').hide();
    /*var layerTop =  ($(window).height()/3) - ($('#registerLayer_ctl').height())+(100+$(window).scrollTop());
	var layerLeft = ($(window).width()/2) - ($('#registerLayer_ctl').width()/2);
	$('#registerLayer_ctl').css({top:layerTop, left:layerLeft});*/


    /*$('.centerRight').each(function(){
	   $('.recentReviewed').css('height',$(this).height()-700);
	});*/

    if ($('.center_leftDiv').height() > $('.newlyAdded1').height()) {
        $('.newlyAdded1').css('height', $('.center_leftDiv').height()-10);
    }
    $('#videoContainerGeneral .video object').each(function(e) {
        $(this).attr('width', '330');
    });

    if ($('.center_leftDiv').height() > 158) {
        $('.newlyAdded3').css('height', $('.newlyAdded3').height()+($('.center_leftDiv').height()-158));
    }

    $('#videoContainerGeneral .video embed').each(function(e) {
        $(this).attr('width', '330');
    });

    $('.activityWantTo img').click(function(e) {

        var id =  $(this).closest("tr").attr("id");

        if ($(this).hasClass('enabled'))
            $(this).removeClass('enabled').addClass('disabled').attr('src', '/framework/assets/images/siteimages/activity-wantTo-disable.gif');
        else
            $(this).removeClass('disabled').addClass('enabled').attr('src', '/framework/assets/images/siteimages/activity-wantTo-enable.gif');

        $.ajax({
            type: "POST",
            data: "type=1&id=" + id + "&c=0&s=0&enabled=" + $(this).hasClass('enabled')
        });
    });

    $('#dialog-box .close').click(function() {
        $('#dialog-overlay, #dialog-box').hide();
        return false;
    });
    $('#volunt-dialog-box .close').click(function() {
        $('#volunt-dialog-overlay, #volunt-dialog-box').hide();
        return false;
    });
    $('#sights-dialog-box .close').click(function() {
        $('#sights-dialog-overlay, #sights-dialog-box').hide();
        return false;
    });
    
    $('#advent-dialog-box .close').click(function() {
        $('#advent-dialog-overlay, #advent-dialog-box').hide();
        return false;
    });
    
    $('#extr-dialog-box .close').click(function() {
        $('#extr-dialog-overlay, #extr-dialog-box').hide();
        return false;
    });
    
    $('.dialog-box .close').click(function() {
        $('#dialog-overlay, .dialog-box').hide();
        return false;
    });

    $('#dialog-box .button').click(function () {

        if ($(this).hasClass('done')) {

            var countryID = $('#selCountry').val();
            var stateID = $('#selState').val();
            var activityID = '#' + tmpActivity;


            if (!(stateID > 0)) stateID = -1;

            $.ajax({
                type: "POST",
                data: "type=2&id=" + activityID + "&c=" + countryID + "&s=" + stateID + '&enabled=true',
                success: function(e) {
                    if (e > 0) {
                        $(tmpObject).closest('tr .activityWantTo .enabled').removeClass('enabled').addClass('disabled').attr('src', '/framework/assets/images/siteimages/activity-wantTo-disable.gif');
                        $(tmpObject).closest('.activityDone .disabled').removeClass('disabled').addClass('enabled').attr('src', '/framework/assets/images/siteimages/activity-done-enable.gif');

                    }

                }
            });

        //$(this).removeClass('enabled').addClass('disabled').attr('src', '/framework/assets/images/siteimages/activity-done-disable.gif');
        }
        $('#dialog-overlay, #dialog-box').hide();	
        if ($(this).attr('href') == '#')
            return false;	
        return true;
    });

    $('#selCountry').change(function() {
        var countryID = $('#selCountry option:selected').val();
        var output = [];

        output.push('<option value="">State/Province</option>');
        $.ajax({
            type: "GET",
            data: "country=" + countryID,
            success: function(data) {
                data = jQuery.parseJSON(data);
                $.each(data, function(key, value){
                    output.push('<option value="' + key + '">'+ value +'</option>');
                });

                $('#selState').html(output.join(''));

            }
        });
    });

    $('.activityDone img').click(function(e) {
        var id =  $(this).closest("tr").attr("id");
        tmpActivity = id;
        tmpObject = this;

        if (!$(this).hasClass('enabled') && $('#dialog-box').is(':hidden')) {

            var overlayHeight = $(document).height();
            var overlayWidth = $(window).width();

            var dialogTop =  ($(window).height()/3) - ($('#dialog-box').height())+(100+$(window).scrollTop());
            var dialogLeft = (overlayWidth/2) - ($('#dialog-box').width()/2);

            $('#dialog-message').html('<h2>Where did you do this activity?</h2>');


            $('#dialog-overlay').css({
                height:overlayHeight, 
                width:overlayWidth
            }).show();
            $('#dialog-box').css({
                top:dialogTop, 
                left:dialogLeft
            }).show();

        }

        else if ($(this).hasClass('enabled')) {
            $(this).removeClass('enabled').addClass('disabled').attr('src', '/framework/assets/images/siteimages/activity-done-disable.gif');
            $.ajax({
                type: "POST",
                data: "type=3&id=" + id + "&c=0&s=0&enabled=false",
                success: function(e) {

                }
            });
        }
    });
	
	
	

    $('.btnGetit').live('click', function() {
	
		
		
		
        var overlayHeight = $(document).height();
        var overlayWidth = $(window).width();
	
        var dialogTop =  ($(window).height()/3) - ($('#dialog-box').height())+(100+$(window).scrollTop());
        var dialogLeft = (overlayWidth/2) - ($('#dialog-box').width()/2);
	
        $('#dialog-overlay').css({
            height:overlayHeight, 
            width:overlayWidth
        }).show();
        $('#dialog-box').css({
            top:dialogTop, 
            left:dialogLeft
        }).show();
			
        if($(this).hasClass('sightseeing_link') || $(this).hasClass('adventures_link')){
            //Add timeout to close dialog box and go to the link URL
            setTimeout(function(){
                if(!$('#dialog-box').is(':hidden')) {
                    $('#dialog-box .close').click();
                    window.open($('#dialog-box .button').attr('href'),'');
                }
            },3000);
        } else if ($(this).hasClass('volunteering_link')) {
        //Add timeout to close dialog box and open the button URL
        }
			
			
        return false;
		
    });
    
    $('a.inviteButton').fancybox({
        padding:0,
        margin:0,
        scrolling:'no',
        autoDimensions:false,
        overlayOpacity:0.4,
        overlayColor:'#000',
        width:370,
        height:120,
        showCloseButton:true
    });

    
   /*
    $('ul.sf-menu').superfish({
        animation: {
            height:'show'
        },
        delay: 1200,
        autoArrows: true,
        onShow:     function(){
            if($(this).hasClass('find-level-top-adjust'))
            {
                var OffTop = $(this).parents('ul').offset();
                var OffReg = $(this).offset();
                var topOld = parseInt($(this).css('top'));
                var top = topOld + (OffTop.top - OffReg.top);
                $(this).css('top',top+'px');
            }
        }
    });*/

});

