function mailMe(sDom, sUser){
  return("mail"+"to:"+sUser+"@"+sDom.replace(/%23/g,"."));
}

window.onerror = handleErrors;
var jsErrors = 0; 
$().ajaxError(function(ev,xhr,o,err) {
    if (jsErrors < 2){
    var postVars = { 'error': '\nURL: '+location.pathname + '\n\nHTML: '+ xhr.responseText };
    $.post('/index.php?com=errors&option=tracking&xml=1', postVars);
    jsErrors = jsErrors + 1;
    }
                //location.reload(true);    
}); 
 

$.getScript = function(url, callback, cache){ $.ajax({ type: "GET", url: url, success: callback, dataType: "script", cache: cache }); };

function handleErrors(errorMessage, url, line){
    if (jsErrors < 2){
    var postVars = { 'error': url + (line ? ' : Line Number:' + line : '') + ' - ' + errorMessage };
    $.post('/index.php?com=errors&option=js-tracking&xml=1', postVars);
    jsErrors = jsErrors + 1;
    }
    return true;
}

function writeJsError(html, error){
    if (jsErrors < 2){
    var postVars = { 'error': 'URL: '+location.pathname + '\nHTML: '+ html + '\nERROR:'+error };
    $.post('/index.php?com=errors&option=tracking&xml=1', postVars);
    jsErrors = jsErrors + 1;
    }
    return;
}

function updateBirth(){
        var chosenDay     = $('#beg_day').val();
        var chosenMonth = $('#beg_month').val();
        var chosenYear     = $('#beg_year').val();
        $('#dateofbirth').val(chosenYear+"-"+chosenMonth+"-"+chosenDay);
    return true;
}

function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}

function addToFavourites() {
    var title = document.title;
    var url = location.href;
        if (window.sidebar) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(title, url,"");
        } 
        else if( window.external ) { // IE Favorite
            window.external.AddFavorite( url, title); }
        else if(window.opera && window.print) { // Opera Hotlist
            return true;
        }
        return false;
    }


function validEmail(_3){invalidChars=" /:,;";if(_3==""){return false;}for(i=0;i<invalidChars.length;i++){badChar=invalidChars.charAt(i);if(_3.indexOf(badChar,0)>-1){return false;}}atPos=_3.indexOf("@",1);if(atPos==-1){return false;}if(_3.indexOf("@",atPos+1)>-1){return false;}periodPos=_3.indexOf(".",atPos);if(periodPos==-1){return false;}if(periodPos+3>_3.length){return false;}return true;}


function roundNumber(_9,_a){var _b=_9;var _c=_a;if(_b>8191&&_b<10485){_b=_b-5000;var _d=Math.round(_b*Math.pow(10,_c))/Math.pow(10,_c);}else{var _e=Math.round(_b*Math.pow(10,_c))/Math.pow(10,_c);}return _e;}

function Set_Cookie( name, value, expires, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );

    if ( expires )
        expires = expires * 1000 * 60 * 60 * 24;

    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
    }

   
function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

var oldSubmitImage;

function preRequest(formData, jqForm, options){
            if  (window.performValidation) {
                if (!performValidation())
                    return false;
             }   
             
             $("#ajax_form .buttons button[type=submit]").attr("disabled","disabled");
    return true;
}

function postRequest(msg){    
        checkForErrors(msg);
        
        $(".buttons button[type=submit]").removeAttr("disabled");
        
        if ($("#ajax_form").size()>0){
        $("#ajax_form .buttons button[type=submit] img[width=16]").attr("src",oldSubmitImage);
        }
        else {
        $(".ajax_form .buttons button[type=submit] img[width=16]").attr("src",oldSubmitImage);
        }
        
        if (typeof window.doAfterAjax == 'function') {
                doAfterAjax();
        }
        
        return true;
}


var options = {
            dataType: "json",
            timeout:  15000, 
            beforeSubmit: preRequest,
            success: postRequest
         };
    
function checkForErrors(json){    
        
        processJSON(json);
        
        if ($("#ajax_form, .ajax_form").size()>0)
            $("#ajax_form, .ajax_form").ajaxForm(options);

    return true;
}


function afterThickbox(){

    if ($("#ajax_form, .ajax_form").size()>0)
            $("#ajax_form, .ajax_form").ajaxForm(options);
}

function processJSON(json){
    
    if (json.errors){
    
        if (json.errors[0].alert){
            var errorText = "";
            for (er=0; er<(json.errors.length); er++){
            if (json.errors[er].message){
                errorText += json.errors[er].message+"\n";
                
                    $("#"+json.errors[er].input).addClass("error");
                
            }
            }
            alert(errorText);
        }
        else {
    
        $(".field").removeClass("error");
        
        
        var error_text = "<ul class=\"islist\">";
        for (er=0; er<(json.errors.length); er++){
            if (json.errors[er].message){
            error_text += "<li>"+json.errors[er].message+"</li>";
            $("#"+json.errors[er].input).addClass("error");
            }
        }
        error_text += "</ul>";
            
        $("#error").html("<div class=\"box light spacer content clear\"><div class=\"box-c\"><div class=\"box-t\"></div><div class=\"image-right fullheight\"><img src=\"/images/alerts/error.gif\" height=\"35\" width=\"35\" alt=\"Error\" /></div><div class=\"px14\"><p style=\"color:#\"><strong>There are Errors in your Submission</strong></p></div>"+error_text+"<div class=\"clearer\"></div></div><div class=\"box-b\"><div></div></div></div>");
        $(window).scrollTo("#error", 800);
    }
    
        if ($("div.panel").size()>0){
            var container = $('#'+json.errors[0].input).parents("div.panel").attr("id");
            $("a[href='#"+container+"']").click();
            $(json.errors[0].input).focus();
        }
         
        else {
            $("#"+json.errors[0].input).focus();
        }
    }
    
    else {
        var success_text     = "";
        var html1             = "<div class=\"box light spacer content clear\"><div class=\"box-c\"><div class=\"box-t\"></div>";
        var html2             = "<div class=\"clearer\"></div></div><div class=\"box-b\"><div></div></div></div>";
        var image_text         = "";


    for (su=0; su<(json.complete.length); su++){
       
      
                   
       if (json.complete[su].type=="hideElement")
            $("#"+json.complete[su].id).fadeOut("medium");
                
       else if (json.complete[su].type=="showElement")
             $("#"+json.complete[su].id).slideDown();
             
      
       if (json.complete[su].type=="replaceContent"){
             $("#"+json.complete[su].id).html(json.complete[su].content);
       }
       
       else if  (json.complete[su].type=="after"){
             $("#"+json.complete[su].id).after(json.complete[su].content);
       }
       
       else if  (json.complete[su].type=="append"){
             $("#"+json.complete[su].id).append(json.complete[su].content);
       }
         
        else if (json.complete[su].type=="attribute"){
            $("#"+json.complete[su].id).attr(json.complete[su].attribute, json.complete[su].content);      
        }
        
        else if (json.complete[su].type=="html"){
            $("#"+json.complete[su].id).html(json.complete[su].content);      
        }
        
        
        else if (json.complete[su].type=="alert"){
            alert(json.complete[su].content);
        }
        
        else if (json.complete[su].type=="redirect"){     
            location.href = json.complete[su].content;
            break;
        }
                    
        else if (json.complete[su].type=="value"){
            $("#"+json.complete[su].id).val(json.complete[su].content);
        }
        
        else if (json.complete[su].type=="createImage"){
            $("#"+json.complete[su].id).html('<img src="'+json.complete[su].content+'" width="'+json.complete[su].width+'" height="'+json.complete[su].height+'" />');
        }
        
        else if (json.complete[su].type=="confirmationBox"){
            var image_text = "";
        if (json.complete[su].graphic){   
            image_text = "<div class=\"image-right fullheight\"><img src=\"http://static.parkatmyhouse.com/images/alerts/"+json.complete[su].graphic+".gif\" height=\"35\" width=\"35\" alt=\""+json.complete[su].graphic+"\" /></div>";
        }
            $("#"+json.complete[su].id).html(html1+image_text+json.complete[su].content+html2);
        }
        
        else if (json.complete[su].type=="remove")
             $("#"+json.complete[su].id).fadeOut("medium", function(){$(this).remove()});
             
        else if (json.complete[su].type=="delete")
             $("#"+json.complete[su].id).remove();

        else if (json.complete[su].content){
            $("#"+json.complete[su].id).html(json.complete[su].content).css("visibility","hidden").slideDown("slow", function (){
                    $(this).css("visibility","visible"); 
            });
         }
         
         
         if (json.complete[su].scrollTo){
            var scrollTo = json.complete[su].scrollTo;
         }
         
         if (json.complete[su].keepThickbox){
            var keepThickbox = true;
         }

         
        }
        
        if (typeof window.pageTracker == 'function') {
                pageTracker._trackPageview(location.pathname+"success");
        }
     

        if ((typeof window.tb_remove == 'function') && !keepThickbox){
            tb_remove();
         }
            
        if (scrollTo=="none")
            var donothing;
        else if (scrollTo)
            $(window).scrollTo($("#"+scrollTo), 800);
        else
            $(window).scrollTo("#breadcrumb", 800);
         
         
        if (typeof window.tb_init == 'function')  
                tb_init("a.thickbox");
    
        reBindCore();
        
    }
return true;
}

$(document).ready(function(){

    $(".star-rating li a").click(function(){
        $(this).parents("span").next("input").val($(this).html());
        $(this).parents("ul").children("li.current-rating").css("width",($(this).html()*20)+"%");
        return false;
    });

    $(".buttons button[type=submit]").click(function(){
        oldSubmitImage = $(this).find("img:first").attr("src");
        $(this).find("img:first").attr("src","/images/loading/arrows-16x16.gif");
    });
        

    if ($("#ajax_form").size())
           $("#ajax_form").ajaxForm(options);
    else if ($(".ajax_form").size())
           $(".ajax_form").ajaxForm(options);
        
    $("#reliability").click( function () {
        return openWindow("/faq/reliability/xml/", 450, 550);
    });
     
    $("a[rel*='external']").attr("title","Opens in a new window").click(function(){
        var thisURL = $(this).attr("href");
        $(this).attr("title","Opens in a new window");
        
     var trackingURL = thisURL.replace("http://", "");
     var trackingURL = thisURL.replace("/external/redirect.php?url=", "");

     var temp = new Array();
     temp = trackingURL.split('/');
     trackingURL = temp[0];
        
        if (window.pageTracker) { 
            pageTracker._trackPageview ('/outgoing/'+trackingURL);
        }
     
        window.open(thisURL);
        return false; 
    });
       
    $("body a[href*='parkatmyhouse']").click(function(){
    
     var hostURL = $(this).attr("href").replace("http://", "");
     var temp = new Array();
     temp = hostURL.split('/');
     hostURL = temp[0];
    
    if (location.host!=hostURL && window.pageTracker){
        pageTracker._link($(this).attr("href"));
        return false;
    }
        return true;
    });
    


            $(".dropdown div.head").click(function() {
                $(".dropdown div ul").toggle();
            });
                        
            $(".dropdown div ul li").click(function() {
                $("#input_local").val($(this).children("img").attr("alt"));
                $(".dropdown div.head").html($(this).html());
                $(".dropdown div.dropdown_list ul").hide();
            });
    
    
    $("#backButton").click( function () {
       history.back();
       return false;
    });
        
    
    if ($("#submitButton").size()>0)
        $("#submitButton").removeAttr("disabled");
    
    $("#changeLocal").change(function () {
        if (window.pageTracker){
             pageTracker._link($(this).val()+location.pathname);   
        }   
        location.href = $(this).val()+location.pathname;
      });    
    
    reBindCore();

    
});

    function reBindCore(){
 $(".field").focus( function () {     
        $(".focused").removeClass("focused");
        $(this).addClass("focused");
        return true;
    });
    
    $("#referral1").change( function () { 

        var values  = $(this)[0].selectedIndex;
        var results = "";
        
var data = eval({"referrers": [[],["Google","Yahoo","MSN","Ask","AOL","Other"],[],[],[],
                    ["By phone", "By e-mail", "By post"],[],
                    ["At a train/subway station","In a shop","Through the door","From a friend"],[], 
                    ["Zipcar","Parkopedia","My Neighbourhoods","Nestoria","Globrix","Other"]],
            "text": ["","Which search engine?","Which newspaper?","Which TV programme?","Which radio station?", "How did we contact you?", "Which magazine?","Where did you get the flyer?","Which Website?","Which partner?","Where did you find us online?","Which friend?","Please give us a clue?"]
            });
 
  
 if (!data.referrers[values] || !data.referrers[values].length){
    results = '<input type="text" name="referral2" id="referral2" class="field text medium" />';

 }

 else {
    results = '<select id="referral2" class="field select medium" name="referral2">';
    
    for (var i=0; i<(data.referrers[values]).length; i++){
        results += '<option value="'+data.referrers[values][i]+'">'+data.referrers[values][i]+'</option>';
    }
        results += '</select>';
 }

 if (!values)
    $('#referral2_div').html("");
 else
    $('#referral2_div').html('<label class="desc"> '+data.text[values]+' </label>'+results);
   
    return true;    
    
});
    }

function openWindow(url, width, height){
    window.open(url, 'newWindow',
'left=200,top=200,width='+width+',height='+height+',toolbar=1,resizable=0');
    return false;
}

function showTabs(tabIDs){
    chosenTab = ((this.location.hash) && (tabIDs[this.location.hash])) ? tabIDs[this.location.hash] : 0;
    
    var tabContainers = $('#tab-container > div');
       $("#tab-container ul.isTab li").mouseover(
            function(){$(this).addClass("tabHover"); }).mouseout(
            function(){$(this).removeClass("tabHover");
        });

    
    $('#tab-container > ul.isTab a').click(function () {
        tabContainers.hide().filter(this.hash).show();
        
        $('#tab-container > ul.isTab li').removeClass('current');
        $(this).parent("li").addClass('current');
        
        return false;
    }).eq(chosenTab).click();
}

function customRange(input) { 
    return { minDate: (input.id == "end_date_temp" ? $("#start_date_temp").datepicker("getDate") : null)}; 
} 


$(document).ready(function(){

$(".isMial").hover(function(){
	$(this).attr("href",mailMe('parkatmyhouse%23com','press'));
}).click(function(){
	$(this).attr("href",mailMe('parkatmyhouse%23com','press'));

});


    $(".sqbuttons button").click(function(){
    var thisID = $(this).attr("id");
        $("#tab-pane div.selected").fadeOut("medium", function(){
            $(".sqbuttons button.active").removeClass("active");
            $("#top-pane-content #"+thisID+"-tab").addClass("selected").fadeIn();
            $("#"+thisID).addClass("active");
        }).removeClass("selected");
    
    
    return true;
});

    $(".sqbuttons button").hover(function(){
        $(".sqbuttons button.selected").removeClass("selected");
        $(this).addClass("selected");
    return true;
});

/* Airport Tracking & Manipulation */

$("#ddm").change(function(){
    var arriving_dates = $(this).val().split(",");
    $("#arriving_m").val(arriving_dates[0]);
    $("#arriving_y").val(arriving_dates[1]);
});

$("#rdm").change(function(){
    var returning_dates = $(this).val().split(",");
    $("#returning_m").val(returning_dates[0]);
    $("#returning_y").val(returning_dates[1]);
});

$("form.airport button[type='submit']").click(function(){
    pageTracker._trackPageview ('/outgoing/airport_parking/');
    return true;
});

/* Airport Tracking & Manipulation */

if ($("input.selectdate").size()>0){
            $("body").append('<input type="hidden" id="temp_date" />');
            
        $("input.selectdate").datepicker({
            closeText: 'X',
            beforeShow: customRange,
            duration: '',
            dateFormat: date_format, 
            altField: '#temp_date', 
            altFormat: 'yy-mm-dd',
            firstDay: 1,
            constrainInput: true,
            onSelect: function(){
                var date_id = $(this).attr("id").replace(/_temp/g, "");
                $("#"+date_id).val($("#temp_date").val());
                
                if  (typeof window.onSelectCalendar == 'function') {
                    onSelectCalendar();
                    }
            },
            onClose: function(){
                var date_id = $(this).attr("id").replace(/_temp/g, "");
                $("#"+date_id).val($("#temp_date").val());
            }
        }).attr("readonly", "readonly");
        
        }




});