﻿function AddMailingList() {
    var theEmail = trim(document.getElementById("mailListBox").value);

    if (theEmail.length == 0) {
        alert("You must enter an email address");
        return;
    }

    var sXml = "<Contents>";
    sXml = sXml + "<Type>MAILING_LIST</Type>";
    sXml = sXml + "<Email><![CDATA[" + theEmail + "]]></Email>";
    sXml = sXml + "</Contents>";

    callAsyncRPC(AppRoot + 'AJAXCaller.aspx', sXml, MailingListCallBack);
}

function MailingListCallBack() {
    //get return XML
    var ret;
    if (xmlRequester.readyState == 4) {
        ret = eval("(" + xmlRequester.responseText + ")");
    }
    else {
        return;
    }

    if (ret.error != "") {
        alert(ret.error);
    }
    else {
        alert(ret.ReturnMessage);
    }
}

function AddToCart(theProdID, theSize, theColor, theQuantity) {
    if (theSize == "")
        theSize = "0";

    if (theColor == "")
        theColor = "0";

    if (theQuantity == "")
        theQuantity = "1";

    if (theProdID == "") {
        alert('Product ID Not Supplied');
        return;
    }

    var sUrl = AppRoot + "ShoppingCart.aspx?addProdID=" + theProdID + "&addSizeID=" + theSize + "&addColorID=" + theColor + "&addQuantity=" + theQuantity;
    window.location.href = sUrl;
}

function AddToCartText(theProdID, theSize, theColor, theQuantity) {

    theSize = escape(theSize);
    theColor = escape(theColor);

    if (theQuantity == "")
        theQuantity = "1";

    if (theProdID == "") {
        alert('Product ID Not Supplied');
        return;
    }

    var sUrl = AppRoot + "ShoppingCart.aspx?addProdID=" + theProdID + "&addSize=" + theSize + "&addColor=" + theColor + "&addQuantity=" + theQuantity;
    window.location.href = sUrl;
}

function QDAddToCart(ProductID) {
    var theSize = "";
    var theColor = "";
    var theQuantity = "1";

    var drpSize = document.getElementById("drpQDProdSizes");
    var drpColor = document.getElementById("drpQDProdColors");

    theSize = GetDropDownVal(drpSize);
    theColor = GetDropDownVal(drpColor);

    var theSizeText = GetDropDownText(drpSize);
    var theColorText = GetDropDownText(drpColor);

    var theQuanData = document.getElementById("hdnQuanData").value;
    if (IsVariantAvailable(theQuanData, theSizeText, theColorText) == false) {
        var theMsg = "We are sorry, but the item you have selected";
        if (theSizeText.length > 0)
            theSizeText = "in size '" + theSizeText + "'";
        if (theColorText.length > 0) {
            if (theSizeText.length > 0)
                theColorText = " and color '" + theColorText + "'";
            else
                theColorText = "in color '" + theColorText + "'";
        }
        theSizeText = theSizeText + theColorText;

        if (theSizeText.length > 0)
            theMsg = theMsg + " " + theSizeText;

        theMsg = theMsg + ", is currently not in stock.\r\n\r\nPlease select a different product, or email us at help@playfulthreads.com if you are interested in back-ordering.";

        alert(theMsg);
        return;
    }

    AddToCart(ProductID, theSize, theColor, theQuantity);
}

function IsVariantAvailable(theQuantityData, theSize, theColor) {
    var theReturn = false;
    var theOuterArray = theQuantityData.split("|");
    for (var x = 0; x < theOuterArray.length; x++) {
        var theInnerArray = theOuterArray[x].split("~");
        if (theSize == theInnerArray[0] && theColor == theInnerArray[1]) {
            if (theInnerArray[2] != "0" && theInnerArray[2] != "") {
                theReturn = true;
            }
            else if (theInnerArray[3].length > 0) {
                if (theInnerArray[3] != "" && theInnerArray[3] != "0") {
                    theReturn = true;
                }
            }

            break;
        }
    }

    return theReturn;
}

function GetDropDownVal(drp) {
    if (drp) {
        var val = drp.options[drp.selectedIndex].value;
        return val;
    }
    else
        return "";
}

function GetDropDownText(drp) {
    if (drp) {
        var val = drp.options[drp.selectedIndex].text;
        return val;
    }
    else
        return "";
}

function bookmark(url, sitename) {
    var ns = "Netscape and FireFox users, use CTRL+D to bookmark this site."
    if ((navigator.appName == 'Microsoft Internet Explorer') &&
            (parseInt(navigator.appVersion) >= 4)) {
        window.external.AddFavorite(url, sitename);
    }
    else if (navigator.appName == 'Netscape') {
        alert(ns);
    }
}


function AddFan() {
    window.open(AppRoot + "tt.aspx");
    return true;
}

function AddTwitter() {
    window.open(AppRoot + "tt.aspx?twitter=1");
    return true;
}

function enterInBox(e) {
    var characterCode;

    if (e && e.which) {
        e = e;
        characterCode = e.which;
    }
    else {
        e = event;
        characterCode = e.keyCode;
    }

    if (characterCode == 13) {
        RunSearch();
        return false;
    }
    else {
        return true;
    }
}

    var currentAdNum = 1;   
    function TopImageClick()
    {	    
        if(currentAdNum == 1)
        {
            window.location.href = AppRoot + "exotic-dancewear.aspx";
        }   
        else if(currentAdNum == 2)
        {
            window.location.href = AppRoot + "clubwear.aspx";
        }
        else
        {
            window.location.href = AppRoot + "plus-size.aspx";
        }
    }
    
    function BottomLinkClick(theAdNum)
    {
        if(theAdNum == 1)
        {
            window.location.href = AppRoot + "exotic-dancewear.aspx";
        }
        else if(theAdNum == 2)
        {
            window.location.href = AppRoot + "clubwear.aspx";
        }
        else
        {
            window.location.href = AppRoot + "plus-size.aspx";
        }
    }	    
    
    var timerID = null;
    function PauseRotate()
    {
        clearInterval(timerID);
    }
    
    function ResumeRotate()
    {
        timerID = setInterval("TopImageScroll()", 4000);    
    }
    	    
    function TopImageScroll()
    {
        if(currentAdNum == 1)
        {
            document.getElementById('imgMain').src = "images/clubwear_splash.jpg";
            document.getElementById('imgMain').alt = "Clubwear & Lingerie At PlayfulThreads.com";
            document.getElementById('rotateDiv1').className="rotateDisabled";
            document.getElementById('rotateDiv2').className="rotate";
            document.getElementById('rotateDiv3').className="rotateDisabled";
            currentAdNum = 2;
        }
        else if(currentAdNum == 2)
        {
            document.getElementById('imgMain').src = "images/plus_splash.jpg";
            document.getElementById('imgMain').alt = "Plus-Size Selections At PlayfulThreads.com";
            document.getElementById('rotateDiv1').className="rotateDisabled";
            document.getElementById('rotateDiv2').className="rotateDisabled";
            document.getElementById('rotateDiv3').className="rotate";
            currentAdNum = 3;	        
        }
        else
        {
            document.getElementById('imgMain').src = "images/damce_splash.jpg";
            document.getElementById('imgMain').alt = "The Hottest Dancewear & Stripper Products At Playful Threads";
            document.getElementById('rotateDiv1').className="rotate";
            document.getElementById('rotateDiv2').className="rotateDisabled";
            document.getElementById('rotateDiv3').className="rotateDisabled";
            currentAdNum = 1;
        }
    }	 
    
