var _strScene7QltFlag = "";
/*
    Name        :   jumpToEpraiseGroup
    Purpose     :   Jumps to the ecard group page
    Author      :   JohnD (Baudville) - 7/27/2009
    Note(s)     :   
*/
function jumpToEpraiseGroup(intGrpId) {
    
    intGrpId = getElementId(intGrpId).options[getElementId(intGrpId).selectedIndex].value;
    
    window.location = getElementId(_strCPId + 'hidSiteDomain').value  + 'epraise/epgrp/' + intGrpId;
    
}

/*
    Name        :   jumpToEpraiseCard
    Purpose     :   Jumps to the epraise card personalization page
    Author      :   JohnD (Baudville) - 7/27/2009
    Note(s)     :   
*/
function jumpToEpraiseCard(intCardId) {

    intCardId = getElementId(_strCPId + 'hidCardId' + intCardId).value;
    
    window.location = getElementId(_strCPId + 'hidSiteDomain').value + 'epraise/personalize/' + intCardId;
    
}

/*
    Name        :   clearCards
    Purpose     :   Clears out the cards currently displayed
    Author      :   JohnD (Baudville) - 7/27/2009
    Note(s)     :   
*/
function clearCards() {
    for (i=1;i<=3;i++) {
        getElementId( 'tdImgSlot' + i).className = 'no-show';
    }
}


/*
    Name        :   bringUpCards
    Purpose     :   Displays the cards
    Author      :   JohnD (Baudville) - 7/27/2009
    Note(s)     :   
*/
function bringUpCards(strImgUrl) {
    var hidSlot1 = getElementId(_strCPId + 'hidSlot1');
    var hidSlot2 = getElementId(_strCPId + 'hidSlot2');
    var intStart = hidSlot1.value;
    var intEnd = hidSlot2.value;
    var intCard = 1;
      
        
    clearCards();
    
    for (i=intStart;i<=intEnd;i++) {
    
        if (parseInt(i) -1 > (arrEpraiseData.length -1)) {
            break;
        }
        var arrData = arrEpraiseData[i -1].split('|');
        getElementId(_strCPId + 'imgSlot' + intCard).src = strImgUrl.replace('EPRAISECARDIMAGE',arrData[1]);
        getElementId(_strCPId + 'imgSlot' + intCard).alt = arrData[5];
        getElementId('tdImgSlot' + intCard).className = 'show-inline';
        getElementId(_strCPId + 'hidCardId' + intCard).value = arrData[0];
        getElementId(_strCPId + 'hidCardImg' + intCard).value = arrData[1];
                
        intCard = parseInt(intCard) + 1;
        
        
        if (parseInt(intCard) > 3) {
            break;
        }
       
    }
    
       var strCardImg = _strCPId + 'hidCardImg1';
            var strCardId = _strCPId + 'hidCardId1';
            
      
          displayCardProducts (strCardId, strCardImg);
         
}


/*
    Name        :   previousSet
    Purpose     :   Displays the previous set of products
    Author      :   JohnD (Baudville) - 7/27/2009
    Note(s)     :   
*/
function previousSet() {

  
  var hidSlot1 = getElementId(_strCPId + 'hidSlot1');
  var hidSlot2 = getElementId(_strCPId + 'hidSlot2');
  var imgLeftArrow = getElementId(_strCPId + 'imgLeftArrow');
  var imgLeftDisabled=getElementId(_strCPId + 'imgLeftDisabled');
  var imgRightArrow = getElementId(_strCPId + 'imgRightArrow');
  var imgRightDisabled=getElementId(_strCPId + 'imgRightDisabled');
  var hidCurrPage = getElementId(_strCPId + 'hidCurrPage');
  var hidTotalPages = getElementId(_strCPId + 'hidTotalPages');
  var strCardImgUrl = getElementId(_strCPId + 'hidCardImg').value;
  var hidNumSlides = getElementId(_strCPId + 'hidNumSlides');
  
  var intDiff = parseInt(hidNumSlides.value) % 3;
  if (intDiff >0) {
    intDiff = 3 - intDiff;
  }

  imgRightArrow.className = "show-inline img-no-border mouse-pointer";
  imgRightDisabled.className = "no-show img-no-border";
  
  
  var intSlot2 = parseInt(hidSlot2.value) - 3;
  var intSlot1 = parseInt(hidSlot1.value) - 3;    
  
  hidSlot2.value = intSlot2;
  hidSlot1.value = intSlot1;
  
  
  
    hidCurrPage.value -= 1;
  
  if (parseInt(hidCurrPage.value) < 1) {
    hidCurrPage.value = 1;
  }
      
    
    if (parseInt(hidSlot1.value)  <= parseInt(1)) {
        hidSlot1.value = 1;
        imgLeftArrow.className = "no-show img-no-border mouse-pointer";
        imgLeftDisabled.className="show-inline img-no-border";
        hidSlot2.value = 3;
    }
    
    if (parseInt(hidSlot2.value) < 3 ) {
        imgLeftArrow.className = "no-show img-no-border mouse-pointer"
        imgLeftDisabled.className="show-inline img-no-border";
        hidSlot2.value = 3;
    }
    
    
    bringUpCards(strCardImgUrl);

}


/*
    Name        :   nextSet
    Purpose     :   Pulls in the next set of products
    Author      :   JohnD (Baudville) - 7/27/2009
    Note(s)     :   
*/
function nextSet() {
  var hidSlot1 = getElementId(_strCPId + 'hidSlot1');
  var hidSlot2 = getElementId(_strCPId + 'hidSlot2');
  var imgLeftArrow = getElementId(_strCPId + 'imgLeftArrow');
  var imgLeftDisabled=getElementId(_strCPId + 'imgLeftDisabled');
  var imgRightArrow = getElementId(_strCPId + 'imgRightArrow');
  var imgRightDisabled=getElementId(_strCPId + 'imgRightDisabled');
  var hidCurrPage = getElementId(_strCPId + 'hidCurrPage');
  var hidTotalPages = getElementId(_strCPId + 'hidTotalPages');
  var strCardImgUrl = getElementId(_strCPId + 'hidCardImg').value;
  var hidNumSlides = getElementId(_strCPId + 'hidNumSlides');
  
  var intDiff = parseInt(hidNumSlides.value) % 3;
  if (intDiff >0) {
    intDiff = 3 - intDiff;
  }
  
  
  
    
  hidCurrPage.value = parseInt(hidCurrPage.value) + 1;
  
  if (parseInt(hidCurrPage.value) > parseInt(getElementId(_strCPId + 'hidTotalPages').value)) {
    hidCurrPage.value = getElementId(_strCPId + 'hidTotalPages').value;
  }
  
  imgLeftArrow.className = "show-inline img-no-border mouse-pointer";
  imgLeftDisabled.className = "no-show img-no-border";
  hidSlot1.value = parseInt(hidSlot2.value) + 1;
  hidSlot2.value = parseInt(hidSlot2.value) + 3;
  

    if (parseInt(hidSlot2.value) >= parseInt(hidNumSlides.value)) {
        imgRightArrow.className = "no-show img-no-border mouse-pointer";
        imgRightDisabled.className="show-inline img-no-border";
        hidSlot2.value = parseInt(hidNumSlides.value) + intDiff;
    }
    bringUpCards(strCardImgUrl);
}

/*
    Name        :   clearProducts
    Purpose     :   Clears the product section on the epraise home page
    Author      :   JohnD (Baudville) - 7/27/2009
    Note(s)     :   
*/
function clearProducts () {
    for (i=1;i<=4;i++) {
        getElementId('tdProd' + i).className = "no-show";
    }
}

/*
    Name        :   displayCardProducts
    Purpose     :   Displays the products associated with the selected card.
    Author      :   JohnD (Baudville) - 7/27/2009
    Note(s)     :   
*/
function displayCardProducts(hidCardId, hidCardImg) {

    
    var intSlot1 = getElementId(_strCPId + 'hidSlot1').value;
    var intSlot2 = getElementId(_strCPId + 'hidSlot2').value;
    var lngProdCount = 1;

    clearProducts()

    hidCardId = getElementId(hidCardId);
    hidCardImg = getElementId(hidCardImg);
    
    for (i=0; i<= arrEpraiseProdData.length -1; i++) {
    
        var arrProdData = new Array();
        arrProdData = arrEpraiseProdData[i].split('|');
        
        if (arrProdData[7] == hidCardImg.value) {
            var strProdImg = getElementId(_strCPId + 'hidProdImg').value;
            strProdImg = strProdImg.replace("EPRAISECARDIMAGE","BV_" + arrProdData[0] + "_FRONT");
            getElementId('imgProd' + lngProdCount).src= strProdImg;
            getElementId('imgProd' + lngProdCount).alt = arrProdData[8];
            
            getElementId('tdProd' + lngProdCount).className = "show-inline";
            getElementId('lnkProd' + lngProdCount).href=getElementId(_strCPId + 'hidSiteDomain').value + arrProdData[1];
            getElementId('spnLink').innerHTML = arrProdData[2] + ' | ';
            getElementId('lnkCardProd').innerHTML = arrProdData[4];
            getElementId('lnkCardProd').href = getElementId(_strCPId + 'hidSiteDomain').value + arrProdData[5];
            
            lngProdCount += 1;
            if (lngProdCount > 4) {
                break;
            }
        }
    
    }
    

    

}

/*
 Name            :       ShowHelpPopup
 Author          :       ToddH (Baudville)
 Date            :       7/22/2009
 
 Note(s)         :       JohnD (Baudville) - 7/24/2009 
                         Made the function a little bit more generic, in that I can pass in what
                         file I want to show up.
 */
function ShowHelpPopup(strFileToPopup) {

    if (strFileToPopup == null) {
        strFileToPopup = "epraise/help";
    }
    var strSiteDomain = getElementId(_strCPId + 'hidSiteDomain').value;
    var strUrl = strSiteDomain + strFileToPopup;
    window.radopen(strUrl, "radwEpraiseHelp");
}        


/*
 Name            :       cardcreator.js
 Purpose         :       Handles all of the functionality of creating epraise cards
 Author          :       ToddH
 Date            :       7/7/2009
 */
//----------------------------------------------------------------------------------------------------------------------------

var _errColor = "#F9555E";  

/*
 Name            :       ValidateControlsClient
 Purpose         :       Validates controls on the page -- if successful performs a postback
 Author          :       ToddH (Baudville)
 Date            :       7/7/2009
 */
function ValidateControlsClient(id) {
    var controlsOK = true;
    // Recipient Email
    if (!validateMultipleEmailAddresses(getElementId(_strCPId + 'txtRecipEmail'))) {
        getElementId(_strCPId + 'lblRecipEmail').style.color = _errColor;
        controlsOK = false;
    } else {
        getElementId(_strCPId + 'lblRecipEmail').style.color = "";
    }
    // CC Email (not required)
    if(document.getElementById(_strCPId + 'txtCCRecipEmail').value.trim().length > 0) {
        if (!validateEmailAddress(getElementId(_strCPId + 'txtCCRecipEmail'))) {
            getElementId(_strCPId + 'lblCCRecipEmail').style.color = _errColor;
            controlsOK = false;
        } else {
            getElementId(_strCPId + 'lblCCRecipEmail').style.color = "";
        }
    } else {
        getElementId(_strCPId + 'lblCCRecipEmail').style.color = "";
    }
    // Sender Name
    if (getElementId(_strCPId + 'txtSenderName').value == "" ) {
        getElementId(_strCPId + 'lblSenderName').style.color = _errColor;
        controlsOK = false;
    } else {
        getElementId(_strCPId + 'lblSenderName').style.color = "";
    }
    // Sender Email
    if (!validateEmailAddress(getElementId(_strCPId + 'txtSenderEmail'))) {
        getElementId(_strCPId + 'lblSenderEmail').style.color = _errColor;
        controlsOK = false;
    } else {
        getElementId(_strCPId + 'lblSenderEmail').style.color = "";
    }
    // Message Text
    if (getElementId(_strCPId + 'txtMessage').value == "" ) {
        getElementId(_strCPId + 'lblMessage').style.color = _errColor;
        controlsOK = false;
    } else {
        getElementId(_strCPId + 'lblMessage').style.color = "";
    }
    // Do postback if passes validation
    if (controlsOK) {
        __doPostBack(id,'');
    } else {
        getElementId(_strCPId + 'divErrors').style.visibility = 'visible';
    }
}

/*
 Name            :       UpdateCardText
 Author          :       ToddH (Baudville)
 Date            :       7/7/2009
 History         :       ToddH 8/4/2009 
                         Added '&op_sharpen=1&qlt=95' to szUrl
 */
function UpdateCardText() {
    
    var intMaxChars = 900;
    var strMessageBox = getElementId(_strCPId + 'txtMessage');
    var intCurrentChars = strMessageBox.value.length;
    if(intCurrentChars > intMaxChars) {
        strMessageBox.value = strMessageBox.value.substring(0,intMaxChars);
        getElementId(_strCPId + 'lblMessage').style.color = _errColor;
        getElementId(_strCPId + 'lblMessage').innerHTML = 'Maximum Message Length Reached';
        return false;
    } 
    if(intCurrentChars != intMaxChars) {
        getElementId(_strCPId + 'lblMessage').style.color = "";
        getElementId(_strCPId + 'lblMessage').innerHTML = 'Write your Personal Message';
    }
    var strMsg = getElementId(_strCPId + 'txtMessage').value;
    var szUrl = "http://s7d2.scene7.com/is/image/Baudville/";
    var Scene7Template = getElementId(_strCPId + 'hidScene7Template').value;
    var Scene7Image = getElementId(_strCPId + 'hidScene7Image').value;
    var Font = getElementId(_strCPId + 'ddlFont').value;
    var FontSize = getElementId(_strCPId + 'hidFontSize').value;
    var colorPicker = $find(_strCPId + 'rcpFontColor');
    if (colorPicker != null) {
        getElementId(_strCPId + 'hidFontColor').value = colorPicker.get_selectedColor();
    }
    var selectedColor = getElementId(_strCPId + 'hidFontColor').value; 
    selectedColor = selectedColor.replace('#','');
    var strRed = HexToR(selectedColor);
    var strGreen = HexToG(selectedColor);
    var strBlue = HexToB(selectedColor);    
    strMsg = escapeSpecialCharacters(strMsg);
    strMsg = escapeLineBrakes(strMsg,"\\par","");
    getElementId(_strCPId + 'hidEncodedMessage').value = strMsg;
    szUrl += Scene7Template + "?layer=0&src=" + Scene7Image + "&layer=1&$line1=" + strMsg;
    szUrl += "&$red=" + strRed + "&$green=" + strGreen + "&$blue=" + strBlue;    
    szUrl += "&$line1fs=" + FontSize;
    szUrl += "&$fn=" + Font;
    szUrl += "&op_sharpen=1" + _strScene7QltFlag;
    getElementId(_strCPId + 'imgCard').src = szUrl;
} 

/*
    Name            :       escapeLineBrakes
    Purpose         :       Removes line breaks (yes, I know....hehehe)
    Author          :       JohnD (Baudville) - 2/3/2009
*/
function escapeLineBrakes(strText,replaceWith){ 
    var strReturn = "";
    strReturn = strText.replace(new RegExp("\\n","g"),"\\par%20");
    strReturn = strReturn.replace(new RegExp("\\r","g"),"");
    return strReturn;
}

/*
    Name            :       List of functions to pull back the rgb value of hex value for colours
    Purpose         :       Well the name says it all, so I won't go into this.
    Author          :       Was not me
    Date            :       10/10/2008
*/
function HexToR(h) { return parseInt((cutHex(h)).substring(0,2),16) }
function HexToG(h) { return parseInt((cutHex(h)).substring(2,4),16) }
function HexToB(h) { return parseInt((cutHex(h)).substring(4,6),16) }
function cutHex(h) { return (h.charAt(0)=="#") ? h.substring(1,7) : h}


