var giftNewsActiveCtrl;
var giftNewsActivePopup;

function GiftNewsClick(ctrl,popupId)
{

	if(ctrl!=null)
		ctrl.blur();

	var deactivate=false;

	if(giftNewsActiveCtrl!=null)
	{
		giftNewsActiveCtrl.className='modHeadEllos1980-divGiftNews';

		if(giftNewsActiveCtrl==ctrl || ctrl==null)
			deactivate=true;
	}

	if(!deactivate)
	{
		ctrl.className='modHeadEllos1980-divGiftNewsActive'
		giftNewsActiveCtrl = ctrl;
	}
	else
	{
		giftNewsActiveCtrl = null;
		giftNewsActivePopup.fadeOut();
		giftNewsActivePopup = null;
	}

	var popup=null;

	if ( (popupId != null) && (popupId != "") )
		popup = $("#"+popupId);

	if ( giftNewsActivePopup != null )
		giftNewsActivePopup.fadeOut();

	if( (giftNewsActiveCtrl != null) && (popup != null) )
	{        
		popup.fadeIn();
		var topPosition = giftNewsActiveCtrl.offsetTop + giftNewsActiveCtrl.offsetHeight;
		popup.css('top',topPosition+'px');    
		giftNewsActivePopup=popup;
	}

}


function OpenNewsLetterWarning(windowTitle)
{
	newsLetterWarning = dhtmlmodal.open('newsLetterWarningLayer', 'iframe', '/modules/moduleHeaderEllos1980/newsLetterWarningLayer.aspx', windowTitle, 'width=405px,height=155px,center=1,resize=0,scrolling=0')
}

function aspxCustomPagerClickPrevious() {
    var inputElement = dv.GetPageIndexInputElement();
    //Previous Button
    if (inputElement.value != 0) {
        aspxDVPagerClick(ASPxDataView1, 'PBP');

        if (basketCarousel.cpPageCount <= (parseInt(inputElement.value)))
            document.getElementById('basketNextBtn').setAttribute('src', '../modules/moduleHeader1980/images/NextBtnDisabled.gif');
        else
            document.getElementById('basketNextBtn').setAttribute('src', '../modules/moduleHeader1980/images/NextBtn.gif');
        if ((parseInt(inputElement.value) - 1) == 0)
            document.getElementById('basketPrevBtn').setAttribute('src', '../modules/moduleHeader1980/images/PrevBtnDisabled.gif');
        else
            document.getElementById('basketPrevBtn').setAttribute('src', '../modules/moduleHeader1980/images/PrevBtn.gif');
    }

}

function aspxCustomPagerClickNext() {
    var inputElement = dv.GetPageIndexInputElement();
    //Next Button
    if (basketCarousel.cpPageCount != (parseInt(inputElement.value) + 1)) {
        aspxDVPagerClick(ASPxDataView1, 'PBN');

        if (basketCarousel.cpPageCount <= (parseInt(inputElement.value) + 2))
            document.getElementById('basketNextBtn').setAttribute('src', '../modules/moduleHeader1980/images/NextBtnDisabled.gif');
        else
            document.getElementById('basketNextBtn').setAttribute('src', '../modules/moduleHeader1980/images/NextBtn.gif');
        if ((parseInt(inputElement.value) + 1) == 0)
            document.getElementById('basketPrevBtn').setAttribute('src', '../modules/moduleHeader1980/images/PrevBtnDisabled.gif');
        else
            document.getElementById('basketPrevBtn').setAttribute('src', '../modules/moduleHeader1980/images/PrevBtn.gif');
    }
}

//Performs panel callback inorder to remove an item from cart
function RemoveItemFromCart(productRef, productSize, quantity) {
    cartPanel.PerformCallback("Remove;" + productRef + ";" + productSize);
    //-- Update the No of Items in Cart (top of page) --//
    var spanItemsInCart = document.getElementById('spanItemsInCart');
    if (spanItemsInCart == null)
        spanItemsInCart = parent.document.getElementById('spanItemsInCart');

    var noOfItemsInCart = parseInt(spanItemsInCart.innerHTML) - parseInt(quantity);
    spanItemsInCart.innerHTML = noOfItemsInCart;

    var dv = aspxGetControlCollection().Get(ASPxDataView1);
    var inputElement = dv.GetPageIndexInputElement();

    removeItem = true;
}

//Checks whether a variable is defined
function isdefined(variable) {
    return (typeof (window[variable]) == "undefined") ? false : true;
}

//Updates live cart with the newly added product
function AddToLiveCart() {
    if (isdefined('cartPanel')) {
        if (cartPanel != null)
            cartPanel.PerformCallback('Add;');
    }
}

//Checks the visibilty of div 'BasketContent'. If visibility is 'hidden', hide Cart.
function CheckVisibility(BasketContent) {
    if (document.getElementById(BasketContent).style.visibility == 'hidden')
        setTimeout('cartPopup.Hide()', 500);
}

//Called on ASPxDataView Init event
function ASPxDataView_Init() {
    var dv = aspxGetControlCollection().Get(ASPxDataView1);
    var inputElement = dv.GetPageIndexInputElement();

    /*Check Previous Button*/
    if (inputElement != null) {
        if (inputElement.value != 0)
            document.getElementById('basketPrevBtn').setAttribute('src', '../modules/moduleHeader1980/images/PrevBtn.gif');
        else
            document.getElementById('basketPrevBtn').setAttribute('src', '../modules/moduleHeader1980/images/PrevBtnDisabled.gif');

        /*Check Next Button*/
        if (basketCarousel.cpPageCount != (parseInt(inputElement.value) + 1))
            document.getElementById('basketNextBtn').setAttribute('src', '../modules/moduleHeader1980/images/NextBtn.gif');
        else
            document.getElementById('basketNextBtn').setAttribute('src', '../modules/moduleHeader1980/images/NextBtnDisabled.gif');

        if (parseInt(basketCarousel.cpItemCount) >= 3) {
            document.getElementById(ASPxDataView1).style.height = '310px';
        }
    }

}
