
var TimeToFade = 1000.0;

function fade(eid)
{
    var element = document.getElementById(eid);
    //		alert(eid);
    element.FadeState = -2;
    element.style.opacity = "0";
    if(element == null)
        return;
    if(element.FadeState == null)
    {
        element.FadeState = -2;
    }
    if(element.FadeState == 1 || element.FadeState == -1)
    {
        element.FadeState = element.FadeState == 1 ? -1 : 1;
        //alert("in if");
        //element.FadeState = element.FadeState == 1;
        element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
    }
    else
    {
        //alert("in else");
        element.FadeState = element.FadeState == 2 ? -1 : 1;
        //element.FadeState = element.FadeState == 1;
        element.FadeTimeLeft = TimeToFade;
        setTimeout("animateFade(" + new Date().getTime()
            + ",'" + eid + "')", 33);
    }
}
function animateFade(lastTick, eid)
{
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;
    var element = document.getElementById(eid);
    if(element.FadeTimeLeft <= elapsedTicks){
        element.style.opacity = element.FadeState == 1 ? '1' : '0';
        element.style.filter = 'alpha(opacity = '+ (element.FadeState == 1 ? '100' : '0') + ')';
        //element.style.filter = 'alpha(opacity = "100")';
        element.FadeState = element.FadeState == 1 ? 2 : -2;
        return;
    }
    element.FadeTimeLeft -= elapsedTicks;
    var newOpVal = element.FadeTimeLeft/TimeToFade;
    if(element.FadeState == 1)
        newOpVal = 1 - newOpVal;
    element.style.opacity = newOpVal;
    element.style.filter =
    'alpha(opacity = ' + (newOpVal*100) + ')';
    setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}
function onSelectiona(alphab)
{	//alert("hi");
    $.post("index.php", {option :"com_store",task:"all_stores",filter:alphab},
    function(data)
    {
        document.getElementById("storeslist").innerHTML=data;
        fade("storeslist");
			
    },"json");
}	

function onSelectionSeasonal(alphab)
{
    if(document.getElementById("SeasonalCategoryslist").innerHTML == "")
    {
        $.post("index.php", {option :"com_SeasonalCategory",task:"all_seasonal_categorys",filter:alphab},
        function(data)
        {
            document.getElementById("SeasonalCategoryslist").innerHTML=data;
            fade("SeasonalCategoryslist");
        },"json");
    }
}	


function showbrands(alphab)
{	
    $.post("index.php", {option :"com_brands",task:"all_brands",filter:alphab},
    function(data)
    {
        document.getElementById("storeslist").innerHTML=data;
        fade("storeslist");
    },"json");
}	




function set_home_page_categories()
{
		
    if(document.getElementById("fragment-5").innerHTML=="")
    {
        $.post("index.php", {option :"com_categories",task:"show_home_page_categories",tmpl:"component"},
        function(data1)
        {
            document.getElementById("fragment-5").innerHTML=data1;
            fade("fragment-5");
            setTimeout(getcategories(),30);
        },"json");
    }
    else
    {
        fade("fragment-5");
        setTimeout(getcategories(),30);
    }
}

function show_category_coupon()
{	
    $.post("index.php", {option :"com_categorypage",task:"show_category_coupon",tmpl:"component"},
    function(category_coupon)
    {
        document.getElementById("freshtoday").innerHTML=category_coupon;
        fade("freshtoday");
        gettabhomecon();
    },"json");
}

function set_home_page_fresh_for_today(seasonal_id)
{
    if(document.getElementById("freshtoday").innerHTML=="")
    {	//alert("here");
        $.post("index.php", {
            option :"com_categorypage",
            task:"set_home_page_fresh_for_today",
            sid:seasonal_id,
            tmpl:"component"
        },
        function(fresh_for_today_category_coupon)
        {
            document.getElementById("freshtoday").innerHTML=fresh_for_today_category_coupon;
            //createAddThis();
            fade("freshtoday");
            //reloadFBScript();
            gettabhomecon();
        },"json");
    }
    else
    {
        fade("freshtoday");
        //gettabhomecon();
    }
//    if(window.addthis != undefined)
//    {
//        delete window.addthis;
//    }
//    //after the ajax call, load the javascript and pass the domready param to it
//    $.getScript("http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4dc8c46b1a6724ea", function(){
//        //alert("window.addthis "+window.addthis);
//        //DO ANY OTHER CODE HERE
//        });
}

//function set_home_page_expiring_coupon()
//{
//    if(document.getElementById("expiring").innerHTML=="")
//    {
//        $.post("index.php", {option :"com_categorypage",task:"set_home_page_expiring_coupon",tmpl:"component"},
//        // document.getElementById("expiring").innerHTML=''
//        function(home_page_expiring_coupon)
//        {
//            document.getElementById("expiring").innerHTML=home_page_expiring_coupon;
//            fade("expiring");
//            gettabhomecon();
//        },"json");
//    }
//    else
//    {
//        fade("expiring");
//        gettabhomecon();
//    }
//    if(window.addthis != undefined)
//    {
//        delete window.addthis;
//    }
//    //after the ajax call, load the javascript and pass the domready param to it
//    $.getScript("http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4dc8c46b1a6724ea", function(){
//        //alert("window.addthis "+window.addthis);
//        //DO ANY OTHER CODE HERE
//        });
//}

function set_seasonal_for_home(str,seasonalId,urlstr)
{
    if(document.getElementById(str).innerHTML=="")
    {
        $.post("index.php", {option :"com_categories",task:"get_seasonal_for_home",tmpl:"component",sid:seasonalId},
        function(home_page_seasonal_coupon)
        {
            document.getElementById(str).innerHTML=home_page_seasonal_coupon;
            fade(str);
            gettabhomecon();
            scriptc(urlstr+"/templates/beez_20/javascript/slider.js","slider" );
        },"json");
    }
    else
    {
        fade(str);
        gettabhomecon();
    }

}
function scriptc(a,b){
    var __d=document;
    var __h = __d.getElementsByTagName("head")[0];
    var s = __d.createElement("script");
    s.setAttribute("src", a);
    s.id = b;
    __h.appendChild(s);
}



function set_seasonal_for_homeBottom(str,seasonalId)
{
    str = str +"bottom";
    //alert(str+"--"+seasonalId);
    if(document.getElementById('seasonalbottom').innerHTML=="")
    {
        //alert(str);
        $.post("index.php", {option :"com_categorypage",task:"get_seasonal_coupons",tmpl:"component",sid:seasonalId},
        function(home_page_seasonal_coupon)
        {
            document.getElementById('seasonalbottom').innerHTML=home_page_seasonal_coupon;
            //createAddThis();
            fade('seasonalbottom');
            gettabhomecon();
        },"json");
    }
    else
    {
        fade('seasonalbottom');
        gettabhomecon();
    }
}

function set_home_page_seasonal_coupon()
{	
    //alert(document.getElementById("seasonal"));
    if(document.getElementById("seasonal").innerHTML=="")
    {
        $.post("index.php", {option :"com_categorypage",task:"set_home_page_sasonal_coupon",tmpl:"component"},
        function(home_page_seasonal_coupon)
        {
            document.getElementById("seasonal").innerHTML=home_page_seasonal_coupon;
            fade("seasonal");
        //gettabhomecon();
        },"json");
    }
    else
    {
        fade("seasonal");
    //gettabhomecon();
    }
		
}

function set_home_page_slider_seasonal_coupon()
{
    if(document.getElementById("fragment-4").innerHTML=="")
    {
        $.post("index.php", {option :"com_categories",task:"show_home_page_slider_seasonal_coupon",tmpl:"component"},
        function(slider_seasonal_coupon)
        {
            document.getElementById("fragment-4").innerHTML=slider_seasonal_coupon;
            fade("fragment-4");
            get_seasonal_coupon();
        },"json");
    }
    else
    {
        fade("fragment-4");
    //get_seasonal_coupon();
    }
	
}

function set_home_page_brand()
{
    //alert('asdfasdf');
    if(document.getElementById("fragment-3").innerHTML=="")
    {
        $.post("index.php", {option :"com_categories",task:"show_home_page_brand",tmpl:"component"},
        function(slider_brand)
        {
            document.getElementById("fragment-3").innerHTML=slider_brand;
            fade("fragment-3");
            get_brands();
        },"json");
    }
    else
    {
        fade("fragment-3");
    }
}

function categoryfadeinout(divid)
{
    if(document.getElementById(divid).style.display!="none")
    {
        fadeinout(divid);
        document.getElementById(divid).style.display="none";
    }
    else
    {
        document.getElementById(divid).style.display="";
        fadeinout(divid);
    }
	
}
function fadeinout(eid)
{

    var element = document.getElementById(eid);
    //element.FadeState = element.FadeState = -2;
    element.style.opacity = "0";
    if(element == null)
        return;
    if(element.FadeState == null)
    {
        element.FadeState = -2;
    }
    if(element.FadeState == 1 || element.FadeState == -1)
    {
        element.FadeState = element.FadeState == 1 ? -1 : 1;
        //alert("in if");
        //element.FadeState = element.FadeState == 1;
        element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
    }
    else
    {
        //alert("in else");
        element.FadeState = element.FadeState == 2 ? -1 : 1;
        //element.FadeState = element.FadeState == 1;
        element.FadeTimeLeft = TimeToFade;
        setTimeout("animateFade(" + new Date().getTime()
            + ",'" + eid + "')", 33);
    }
}
// functions for ajax on stores tab display

function storepage_all_coupons(store_id_val)
{
    if(document.getElementById("all_coupons").innerHTML=="")
    {
        $.post("index.php", {option :"com_storepage",task:"storepage_all_coupons",tmpl:"component","store_id": store_id_val},
        function(storepage_all_coupon)
        {
            document.getElementById("all_coupons").innerHTML=storepage_all_coupon;
            fade("all_coupons");
        //gettabhomecon();
        },"json");
    }
    else
    {
        fade("all_coupons");
    //gettabhomecon();
    }
}

function validateWebsiteName()
{
    var urlStr = document.getElementById('website').value;
    if(!isValidURL(urlStr))
    {
        $.confirm(
                    {
                    'title' : 'Invalid Website Name',
                    'message' : 'Please enter website name with prefix http:// only',
                    'buttons' : {
                        'Ok' : {
                                    'class' : 'blue',
                                    'action': function(){
                                    }
                        }
                    }
                })
        return false;
    }
}
function isValidURL(url){
    var RegExp = /(http):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}
//function storepage_expiring(store_id_val)
//{
//    if(document.getElementById("expiring").innerHTML=="")
//    {
//        $.post("index.php", {option :"com_storepage",task:"storepage_expiring",tmpl:"component","store_id": store_id_val},
//        function(storepage_expiring_coupon)
//        {
//            document.getElementById("expiring").innerHTML=storepage_expiring_coupon;
//            fade("expiring");
//        //gettabhomecon();
//        },"json");
//    }
//    else
//    {
//        fade("expiring");
//    //gettabhomecon();
//    }
//}

//function storepage_seasonal(store_id_val)
//{
//    if(document.getElementById("seasonal").innerHTML=="")
//    {
//        $.post("index.php", {option :"com_storepage",task:"storepage_seasonal",tmpl:"component","store_id": store_id_val},
//        function(storepage_seasonal_coupon)
//        {
//            document.getElementById("seasonal").innerHTML=storepage_seasonal_coupon;
//            fade("seasonal");
//        //gettabhomecon();
//        },"json");
//    }
//    else
//    {
//        fade("seasonal");
//    //gettabhomecon();
//    }
//
//}

// eof functions for ajax on stores tab display
