﻿function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
        curtop += obj.offsetTop;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
        curleft += obj.offsetLeft;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function ShowCalendar(ProdID) {
    document.getElementById("ctl00_ContentPlaceHolder1_CalLineID").value = ProdID;
    document.getElementById("ctl00_ContentPlaceHolder1_PopupCalendar").style.display = 'block';
    document.getElementById("ctl00_ContentPlaceHolder1_PopupCalendar").style.position = 'absolute';
    try {
        document.getElementById("ctl00_ContentPlaceHolder1_PopupCalendar").style.top = (window.event.y - window.event.offsetY) - 26;  //-(40-window.event.offsetY);  //190; //10 + GetScrollTopValue();
    }
    catch (e) {
        document.getElementById("ctl00_ContentPlaceHolder1_PopupCalendar").style.top = (findPosY(document.getElementById("img_" + ProdID))-346);
    }
    document.getElementById("ctl00_ContentPlaceHolder1_PopupCalendar").style.left = 770;
}

function GetScrollTopValue() {
    var ScrollTop = document.body.scrollTop;

    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
    return ScrollTop;
} 

function imposeMaxLength(Object, MaxLen){
    return (Object.value.length <= MaxLen);
}

function ShowDelivery(){
    document.getElementById("DeliveryMessage").style.display = 'block';
}
function CloseDelivery(){
    document.getElementById("DeliveryMessage").style.display = 'none';
}

function ShowDelivery_Prod() {
    document.getElementById("DeliveryMessage_Product").style.display = 'block';
}
function CloseDelivery_Prod() {
    document.getElementById("DeliveryMessage_Product").style.display = 'none';
}

function ShowChristmas(){
    document.getElementById("ChristmasMessage").style.display = 'block';
}
function CloseChristmas(){
    document.getElementById("ChristmasMessage").style.display = 'none';
}
function setShipping(varID) {
    self.location.href = "displaycart.aspx?ShippingID=" + varID;
}

function addfav() {
    var title = "hampers.co.uk";
    var url = "http://www.hampers.co.uk";
    if (window.sidebar) {
        // Mozilla Firefox Bookmark  
        window.sidebar.addPanel(title, url, "");}
    else if (window.opera) { //Opera
        alert("opera");
        var a = document.createElement("A");
        a.rel = "sidebar";
        a.target = "_search";
        a.title = title;
        a.href = url;
        a.click();}
    else if (window.external) {
        // IE Favorite  
        window.external.AddFavorite(url, title);}
}

function ShowMore1() {
    document.getElementById("More1").style.display = 'block'; 
}

function ShowCheque() {
    document.getElementById("Cheque").style.display = 'block';
    document.getElementById("Card").style.display = 'none';
}

function ShowCard() {
    document.getElementById("Card").style.display = 'block';
    document.getElementById("Cheque").style.display = 'none';
}

function HideMore1() {
	document.getElementById("More2").style.display = 'none';
	document.getElementById("More3").style.display = 'none';
}

function ShowMore2() { document.getElementById("More2").style.display = 'block'; }

function HideMore2() {
	document.getElementById("More1").style.display = 'none';
	document.getElementById("More3").style.display = 'none';
}

function ShowMore3() { document.getElementById("More3").style.display = 'block'; }

function HideMore3() {
	document.getElementById("More1").style.display = 'none';
	document.getElementById("More2").style.display = 'none';
}


function popUp(URL, width, height, scroll) {
	var settings
	settings = "width=" + width + ",height=" + height + ",scrollbars=" + scroll + ",toolbar=no";
	popwin = window.open(URL, "FAFSPORT", settings);
	popwin.focus();
}

function CheckPayment() {
    var sMsg = '';
    if (document.getElementById("tandc").value == '') { sMsg = sMsg + 'Please enter your Postcode.\n'; }
    if (sMsg == '') { return true; } else { alert(sMsg); return false; }
}

function ShowMonth(Month){
    if (document.getElementById("Month" + Month).style.display=='block'){
        document.getElementById("Month" + Month).style.display='none'}
    else {
        document.getElementById("Month" + Month).style.display='block'}
}

function ShowWishListInstructions(){
    document.getElementById("WishListInstructions").style.display = 'block';
    document.getElementById("SendWishList").style.display = 'none';
}

function CloseWishListInstructions() {
    document.getElementById("SendWishList").style.display = 'none';
    document.getElementById("WishListInstructions").style.display = 'none';
}

function ShowSendWishList(){
    document.getElementById("SendWishList").style.display = 'block';
    document.getElementById("WishListInstructions").style.display = 'none';
}

function CloseSendWishList(){
    document.getElementById("SendWishList").style.display = 'none';
    document.getElementById("WishListInstructions").style.display = 'none';
}

function CloseEventMsg() {
    document.getElementById("EventAdd_Message").style.display = 'none';
}

function CopyValues(varID, varTag, varName) {

    var bStart = false;
    var sData = '';
    var node_list = document.getElementsByTagName(varTag);

    for (var i = 0; i < node_list.length; i++) {
        var node = node_list[i];

        if (node.getAttribute('name').substring(0, varName.length) == varName && bStart == true) {
            node.value = sData;
        }
        if (node.getAttribute('name') == varName + varID) {
            bStart = true;
            sData = node.value;
        }        
    }
}

function ApplyToAll(varID) {
    CopyValues(varID, 'textarea', 'GiftMessage_');
    CopyValues(varID, 'input', 'TextBox1');
    CopyValues(varID, 'select', 'EventContactAd_');
} 
