﻿function fnSelectCentreOnChange(ddl){
    var selectedItem = ddl.options[ddl.selectedIndex];
    var link = selectedItem.getAttribute("link");
    if( link != null && link != ""){
        window.open(link,"_blank");
        setTimeout('$("#selShoppingCentres").val("Our other centres").change();', 1000);
    }
    //ddl.options[0].selected = true;
}

function fnSelectStoresOnChange(ddl){
    var selectedItem = ddl.options[ddl.selectedIndex];
    var link = selectedItem.getAttribute("link");
    if( link != null && link != ""){
        window.location = link;
    }
}

function fnAddToCart(skuId){
    if(skuId == '')
        return; 
    var url = "/CMSTemplates/AMPSCPacificFair/ShoppingCartService.aspx?add=1&skuid=" + skuId + "&quantity=1&rand=" + Math.random() * 1000;
    fnSubmitRequest(url); 
}

function fnRemoveFromCart(skuId){
    if(skuId == '')
        return;         
    var url = "/CMSTemplates/AMPSCPacificFair/ShoppingCartService.aspx?remove=1&skuid=" + skuId + "&rand=" + Math.random() * 1000;
    fnSubmitRequest(url);     
}

function fnSubmitRequest(url)
{
    var _xmlHttp = new xml_http_request(_XML_DEFAULT_HTTP_VERB_GET, url, null, "");
    _xmlHttp.Fetch();
}

function fnRefreshCaptcha(captchaId){
    var captchaImg = $("#" + captchaId);
    captchaImg.attr("src","/JpegImage.aspx?refresh=" + Math.floor(Math.random()*1000));
}

function fnGetOffersCount(divId){
     $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: "/CMSTemplates/AMPSCPacificFair/ShoppingCartService.aspx/JSONCountOffers?rand=" + Math.random() * 1000,
      data: "{'divId' : '" + divId + "'}",
      dataType: "json",
      success: fnGetOffersCountSuccess
    });
}

function fnFormInsertEventReminder(email, mobilenumber, eventname, eventid) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/CMSTemplates/AMPSCPacificFair/FormService.aspx/JSONFormInsertEventReminder?rand=" + Math.random() * 1000,
        data: "{'email' : '" + email + "', 'mobilenumber' : '" + mobilenumber + "' , 'eventname':'" + eventname + "' , 'eventid':'" + eventid + "'}",
        dataType: "json"
    });
}

function fnGetOffersCountSuccess(response){
    var result = response["d"]["0"];
    $("#"+result['divId']).html(result['valueText']);
}

function fnUpdateMainOffers(){
    fnGetOffersCount("spanCountOfferText");
}


//not done yet
function fnFetchCart(){
    var url = "/CMSTemplates/AMPSCPacificFair/ShoppingCartService.aspx?retrieve=1";
    jQuery.getJSON(this.eStoreHostUrl + "/SmallBusinessHotDealsService.aspx?jsoncallback=__eCarousel.refreshContentCallback&foo=?");
}

function fnFlipButtons(skuId){    
    //alert(skuId);  
     
}

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 tweet_click(centre) {
    u=location.href;
    t=document.title;
    copy = "There's plenty on at " + centre + ". Check it out, loads of special offers and more " + u;
    window.open('http://twitter.com/home?status='+encodeURIComponent(copy),'twitter','toolbar=0,status=0,width=800,height=600');
    return false;
}

function tweet_clickEx(centre, url) {
    u=location.href;
    t=document.title;
	
	if (url == '')
	{
		url = u;
	}
	
    copy = "There's plenty on at " + centre + ". Check it out, loads of special offers and more " + url;
    window.open('http://twitter.com/home?status='+encodeURIComponent(copy),'twitter','toolbar=0,status=0,width=800,height=600');
    return false;
}

function delicious_click() {
    u=location.href;
    t=document.title;
    window.open('http://delicious.com/save?url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t),'delicious','toolbar=0,status=0,width=800,height=600');
    return false;
}

function digg_click() {
    u=location.href;
    t=document.title;
    window.open('http://digg.com/submit?phase=2&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t)+'&bodytext='+encodeURIComponent(u),'digg','toolbar=0,status=0,width=800,height=600');
    return false;
}

function myspace_click(centre) {
    u=location.href;
    t=document.title;
    copy = "There's plenty on at " + centre + ". Check it out, loads of special offers and more " + u;
    window.open('http://www.myspace.com/Modules/PostTo/Pages/?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t)+'&c='+encodeURIComponent(copy),'myspace','toolbar=0,status=0,width=800,height=600');
    return false;
}

function stumbleupon_click() {
    u=location.href;
    t=document.title;
    window.open('http://www.stumbleupon.com/submit?url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t),'stumbleupon','toolbar=0,status=0,width=800,height=600');
    return false;
}

function defaultEnterButton(txtId, btnId){
    $(document).ready(function(){
	    $('#'+txtId).keypress(function(event){
            if(event.keyCode == 13){
                $('#' + btnId).click();
                return false;
            }
            return true;
        });
    });
}

function fnOpenPrintPage(nodeId){
    var url = "/ThingsILOVEprintNow.aspx?skuids=" + nodeId;
    window.open(url, '_blank','status=0,toolbar=0,location=0,menubar=0,location=0,directories=0,resizeable=1,scrollbars=1,width=800,height=1000');
}

function fnPageTrackOfferRemove(offerName){
    try{
        pageTracker._trackEvent('Takeaway', 'Delete' , offerName);
    } catch(err) {}; 
    return true;
}

function fnGoogleTrackEvent(category, action, optional_label, optional_value){
    try{

        pageTracker._trackEvent(category, action , optional_label, optional_value);

    } catch(err) {}; 
    return true;
}

function fnNewGoogleTrackEvent(analyticCode, category, action, optional_label, optional_value){
	
    var pageTracker;
   
    pageTracker = _gat._getTracker(analyticCode);
    pageTracker._trackPageview();
   
    pageTracker._trackEvent(category, action , optional_label, optional_value);


    return true;
}

$(document).ready(function(){
    
});

