//      on the aspx page there is
//		ID=litJSList replaced with array of cards 
//		var gcPackage = new Array ... -- aray of cards
//		id="mCardID" -- selected card ID

var imgNum = 0;		//selected card index
var cursorX=0;
var cursorY=0;
var orderID=0;
var trackingNumber = "";
var packageName = "";
var batchName = "";
var manufactureName = "";
var gcsPackageID = "";

window.onload = init;
function init() 
{
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function ietruebody()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function getXY(e) 
{
  cursorX = (window.Event) ? e.pageX : event.clientX +ietruebody().scrollLeft;;
  cursorY = (window.Event) ? e.pageY : event.clientY +ietruebody().scrollTop;;

  // Use x and y to do what ever you want
}

function SelectPOPCard(cardIndex)
{
    // Modal for the Option 4 warning
    var mdlConfirm = $find('mpePopCards');
    if(mdlConfirm != null) mdlConfirm.hide();	
    
    document.getElementById("sliderIndex").value = cardIndex;
    if(document.getElementById("mNumOfPackages").value > 4)
    {
	    InitHorizSlider(cardIndex);
    }
	updateCard(cardIndex, false);
	Page_ClientValidate("total")
	//if(!Page_ClientValidate("total"))
	//{
	//    Page_ClientValidate();
	//}
	//document.getElementById("divAllGifts").style.display = "none";

		
	//__doPostBack("btnConfirmOk","");
	calcTotalGrid();
}

function SelectCard(cardIndex)
{
    // Modal for the Option 4 warning
    var mdlConfirm = $find('mpePopCards');
    if(mdlConfirm != null) mdlConfirm.hide();	
    
    document.getElementById("sliderIndex").value = cardIndex;
	updateCard(cardIndex, true);
	Page_ClientValidate("total");
	//document.getElementById("divAllGifts").style.display = "none";	
	
	//__doPostBack("btnConfirmOk","");
	calcTotalGrid();
}

function SelectCardInitial(cardIndex)
{
    // Modal for the Option 4 warning
    var mdlConfirm = $find('mpePopCards');
    if(mdlConfirm != null) mdlConfirm.hide();	
    
    document.getElementById("sliderIndex").value = cardIndex;
	updateCard(cardIndex, false);	
	Page_ClientValidate("total");
	//document.getElementById("divAllGifts").style.display = "none";	
	
	//__doPostBack("btnConfirmOk","");
	calcTotalGrid();
}

//Update the image and selected Radio Button
function updateCard(imgNum,validate) 
{
	var packageArray = gcPackage[imgNum].split("|");
	//document.Form1.mCardLarge.src=packageArray[1];
	document.Form1.imgRewardPopCard.src=packageArray[3];
	document.Form1.imgAMEXDisclaimer.src=packageArray[3];
	//document.getElementById("mCardName").innerHTML = packageArray[2];	
	//document.getElementById("mCardLarge").alt = packageArray[2];
	document.getElementById("mCardID").value = packageArray[0];
	document.getElementById("mCardWCSID").value = packageArray[6];
	
	try
	{
	    document.getElementById("Left_Nav2_tbBankName").value = packageArray[4];
	    document.getElementById("Left_Nav2_tbReward").value = packageArray[7];	
	
	    // Set the bank info based on the bank
	    if(packageArray[4] == "AXP" || packageArray[4] == "AXPR")
	    {
	        if(packageArray[4] == "AXPR")
	        {
	            document.getElementById("lblAMEXDisclaimer").innerHTML = "The American Express / Simon Rewardcard:  Use only at US merchants that accept American Express Cards except cruise lines and casinos.  Not for use at ATMs or for recurring payments.  Not redeemable for cash.  No fees after purchase.  Funds expire on the date printed on the back of the card.   For more information, customer service, or Cardholder Agreement visit www.simon.com/rewardcard or call 1-800-297-7327. Issued by AEPCMC by license from American Express Travel Related Services Co., Inc. ";
	        }
	        else
	        {
	            document.getElementById("lblAMEXDisclaimer").innerHTML = "Use only at US merchants that accept American Express Cards except cruise lines and casinos.  Not for use at ATMs or for recurring payments.  Not redeemable for cash.  No fees after purchase.  For more information, customer service, or Cardholder Agreement visit simongiftcard.com or call 1-800-331-5479. Issued by AEPCMC by license from American Express Travel Related Services Co., Inc.";
	        }
	        document.getElementById("phVisa").style.display = "none";
	        document.getElementById("phAmex").style.display = "";
	    }
	    else
	    {
	        document.getElementById("phVisa").style.display = "";
	        document.getElementById("phAmex").style.display = "none";
	    }
	    // Try and loop through the grid amount validations and update for the new card selected
	    // Need to also update the label with the min-max
	    //window.alert("UP-2");
	    var NumCards = document.getElementById("mNumOfCards").value;
	    if(NumCards > 20) NumCards = 20;
	    var message = "Must be $" + packageArray[8] + "-$" + packageArray[9];
	    var messageError = "Please enter an amount between " + packageArray[8] + " and " + packageArray[9];
	    var iGrid = 3;
	    for(i = 1; i<=NumCards; i++) 
        {
            // Set the compare and range validator to the value passed in
            var tempString = '';
            if(iGrid < 10) tempString = '0' + iGrid;
            else tempString = iGrid;
            var strControl = "dgItems_ctl" + tempString + "_rvGridAmount";
            document.getElementById(strControl).maximumvalue = packageArray[9];
            document.getElementById(strControl).innerHTML = messageError;
            iGrid = iGrid + 1;
        }
        //window.alert("UP-3");
        // Update the DIV highlighting with the select package
        ResetAllHighlights();
        var sVar = '';
        if(imgNum < 10) sVar = '0' + imgNum;
        else sVar = imgNum;
        document.getElementById("rptCardsInSelector_ctl" + sVar + "_dvSlider").className = 'simonSlidePod_Custom on';
        //window.alert("rptCardsInSelector_ctl" + sVar + "_dvSlider on");
                
        // Format the labels
        //if(validate) Page_ClientValidate();
        //window.alert(message);
        if(document.getElementById("labelAmountDescription") != null) document.getElementById("labelAmountDescription").innerHTML = message;
        if(document.getElementById("labelAmountDescription1") != null) document.getElementById("labelAmountDescription1").innerHTML = message;
        if(document.getElementById("labelAmountDescription2") != null) document.getElementById("labelAmountDescription2").innerHTML = message;
        
        /* init slider if sliderIndex value set */
	    //var initIndex = $("input[type=hidden][id*=sliderIndex]").val();
	    //if (initIndex != 'undefined'){
	    
	    
	    // Call the server to update the rows for MAX value in the grid
	    Simon.Volume.OrderSystem.ResetPackageLimits(packageArray[0], packageArray[4]);
        
	}
	catch(err)
	{
	    //window.alert(err);
	}	
	
}

function LoadInitialCardImageLock()
{
    try
    {
        //window.alert("Started");
        //ResetAllHighlights();
        var sVar1 = '' ;
        var imgNumLocal = 0;
        var bFound = false;
        var NumCards = document.getElementById("mNumOfPackages").value;
        //window.alert(document.getElementById("mCardID").value);
        for(i = 0;i<=NumCards; i++)
        {
            var packageArray = gcPackage[i].split("|");  
            //window.alert(packageArray);
            if(document.getElementById("mCardID").value == packageArray[0])
            {
                //window.alert("Selecting Card....");
                SelectCardInitial(i);
                bFound = true;
                if(NumCards > 4)
                {
                    //window.alert("Slider spot " + imgNumLocal);
                    //window.alert("Init-Slider " + imgNumLocal);
                    InitHorizSlider(imgNumLocal);
                }
                break;
            }
            imgNumLocal = imgNumLocal + 1;
        } 
       //window.alert("2-Init"); 
       if(!bFound)
       {   
       //     SelectCard(0);                
       //     if(document.getElementById("mNumOfPackages").value > 4)
       //     {
       //         InitHorizSlider(0);
        //    }
        }
    }
    catch(err)
	{
	    //window.alert("Init Card Location Error " + err);
	}
}

function InitHorizSlider(index) 
{
    try
    {
        if (index >= 0) {
            var contentHolder = $(".simonSlideContentHolder");
            //var nextPodWidth = contentHolder.children(".simonSlideContent").children("div").eq(index).width() + 1;
            contentHolder.children(".simonSlideContent").css({ "left": "-" + (140 * index) + "px" });
            var currCountLoc = $(".simonSlideRight").siblings(".simonSlidePodCount");
            currCountLoc.text(index);
        }
    }
    catch(err)
	{
	    window.alert("Slider Index Error");
	}
}

function ResetAllHighlights()
{
    try
    {
        var sVar1 = '' ;
        for(i = 0;i<document.getElementById("mNumOfPackages").value; i++)
        {
            if(i < 10) sVar1='0' + i;
            else sVar1 = i;
            //window.alert("rptCardsInSelector_ctl" + sVar1 + "_dvSlider");
            document.getElementById("rptCardsInSelector_ctl" + sVar1 + "_dvSlider").className = 'simonSlidePod_Custom'; 
               
        }   
    }
    catch(err)
    {}
    
}

//Move to Left Card
function moveLeft() 
{
    var packageArray = gcPackage[imgNum].split("|");
    if(parseInt(packageArray[5]) > 2)
    {
        ShowAllGifts();
        //return true;
    }
    else
    {
	    if (imgNum > 0) {
		    imgNum--;				
	    } else {
		    imgNum = gcPackage.length-1;				
	    }
	    updateCard(imgNum, true);
	}
}

//Move to Right Card
function moveRight() 
{
    var packageArray = gcPackage[imgNum].split("|");
    if(parseInt(packageArray[5]) > 2)
    {
        ShowAllGifts();
        //return false;
    }
    else
    {
	    if (imgNum < gcPackage.length -1) {
		    imgNum++;				
	    } else {
		    imgNum = 0;				
	    }
	    updateCard(imgNum, true);
	}
}

function CallFAQWindow()
{
    //window.open('terms_and_conditions_pop.aspx?TCID=' + document.getElementById("Left_nav2_lblBankName").innerHTML,'','left=100,top=50,width=780,height=500,scrollbars=1');
    try
    {
        var lbBank = document.getElementById('Left_Nav2_tbBankName');
        var lbReward = document.getElementById('Left_Nav2_tbReward');
        //window.alert(lbBank.value);
        if(lbBank != null)
        {
            if(lbReward.value == "REWARD") document.getElementById("Left_Nav2_Iframe1").src = "faq_pop2_reward.aspx";
            else document.getElementById("Left_Nav2_Iframe1").src = "faq_pop2.aspx";
        }
        else
            document.getElementById('Left_Nav2_Iframe1').src = "faq_pop2.aspx";
    }
    catch (err)
    {
        //window.alert("CrappedOut-tbBankName.value");
        document.getElementById('Left_Nav2_Iframe1').src = "faq_pop2.aspx";
    }
    
}

function CallTCWindow()
{
    //window.open('terms_and_conditions_pop.aspx?TCID=' + document.getElementById("Left_nav2_lblBankName").innerHTML,'','left=100,top=50,width=780,height=500,scrollbars=1');
    try
    {
        var lbBank = document.getElementById('Left_Nav2_tbBankName');
        var lbReward = document.getElementById('Left_Nav2_tbReward');
        //window.alert(lbBank.value);
        if(lbBank != null)
        {
            if(lbReward.value == "REWARD") document.getElementById("Left_Nav2_ILNTerms").src = "terms_and_conditions_pop.aspx?TCID=REWARD";
            else document.getElementById("Left_Nav2_ILNTerms").src = "terms_and_conditions_pop.aspx?TCID=" + lbBank.value;
        }
        else
            document.getElementById('Left_Nav2_ILNTerms').src = "terms_and_conditions_pop.aspx?TCID=AMEX";
    }
    catch (err)
    {
        //window.alert("CrappedOut-tbBankName.value");
        document.getElementById('Left_Nav2_ILNTerms').src = "terms_and_conditions_pop.aspx?TCID=AMEX";
    }
    
}
function CallTCWindowFees()
{
    //window.open('terms_and_conditions_pop.aspx?TCID=' + document.getElementById("Left_nav2_lblBankName").innerHTML + '#fees','','left=100,top=50,width=780,height=500,scrollbars=1');
    try
    {
        var lbBank = document.getElementById("Left_Nav2_tbBankName");
        var lbReward = document.getElementById('Left_Nav2_tbReward');
        if(lbBank != null)
        {
            if(lbReward.value == "REWARD") document.getElementById("Left_Nav2_ILNTerms").src = "terms_and_conditions_pop.aspx?TCID=REWARD#fees";
            else document.getElementById("Left_Nav2_ILNTerms").src = "terms_and_conditions_pop.aspx?TCID=" + lbBank.value;
        }
        else
            document.getElementById('Left_Nav2_ILNTerms').src = "terms_and_conditions_pop.aspx?TCID=AMEX#fees";
        return;
    }
    catch (err)
    {        
    }
    
    //window.open('terms_and_conditions_pop.aspx?TCID=' + document.getElementById("Left_nav2_lblBankName").innerHTML + '#fees','','left=100,top=50,width=780,height=500,scrollbars=1');

}

function ShowAllGifts()
{
	//var divPop;
	//divPop=document.getElementById("divAllGifts");
	//divPop.style.display = "inline";
	//divPop.style.top = "100px";//parseInt(20+((document.body.clientHeight - divPop.offsetHeight) / 2),10) + "px"  ;						
	//divPop.style.left = parseInt(10 + ((document.body.clientWidth - divPop.offsetWidth) / 2),10) + "px";
	
	
	// Modal for the Option 4 warning
    var mdlConfirm = $find('mpePopCards');
    if(mdlConfirm != null) mdlConfirm.show();
}

function ShowAllCards()
{
	var divPop;
	divPop=document.getElementById("divAllCards");
	divPop.style.display = "inline";
	//divPop.style.top = "200px";//parseInt(20+((document.body.clientHeight - divPop.offsetHeight) / 2),10) + "px"  ;						
	//divPop.style.left = parseInt(10 + ((document.body.clientWidth - divPop.offsetWidth) / 4),10) + "px";	
	divPop.style.position = "absolute";
	divPop.style.zIndex = -1;	//set behind to not show moving				
	positionPop("divAllCards");
	if (cursorY - 200 > 0) divPop.style.top = cursorY - 200 + "px";
	
	divPop.style.zIndex = 99;
	
}

function ShowEditShipping()
{
	var divPop;
	divPop=document.getElementById("divShippingAddress");
	divPop.style.display = "inline";
	divPop.style.top = "300px";//parseInt(20+((document.body.clientHeight - divPop.offsetHeight) / 2),10) + "px"  ;						
	divPop.style.left = parseInt(10 + ((document.body.clientWidth - divPop.offsetWidth) / 4),10) + "px";	
	divPop.style.position = "absolute";
	divPop.style.zIndex = -1;	//set behind to not show moving				
	positionPop("divShippingAddress");
	if (cursorY - 200 > 0) divPop.style.top = cursorY - 200 + "px";
	
	divPop.style.zIndex = 99;
	
}

function closeAllGiftsPop()
{
	document.getElementById("divAllGifts").style.display = "none";		
}

function closeAllGiftsPop()
{
	document.getElementById("divAllGifts").style.display = "none";		
}

//#######################
function ShowPop()
{
	var f = document.forms[0];
		
	if (typeof(Page_Validators) == "undefined") {			        
		
		DisplayDropDowns("none");
		setVisibleStyle() ;
	} else {
		if (Page_IsValid ) {				
			DisplayDropDowns("none");
			setVisibleStyle() ;
		}
	}
	return false;	
}

function setVisibleStyle() 
{
	if (document.all) {
		dvPop.style.display = "inline";
		dvPop.style.position = "absolute";
		dvPop.style.zIndex = 99;
		
//				dvPop.style.top = parseInt((550 - 200)/2,10) + "px";		
		dvPop.style.left =  parseInt(10 + ((document.body.clientWidth  - 398) / 2)) + "px";						
		
	} else { 
		var dvpop = document.getElementById("dvPop");
		dvpop.style.display = "inline";
		dvpop.style.position = "absolute";
		dvpop.style.zIndex = 99;		
		dvpop.style.top = parseInt(70 +((document.body.clientHeight - dvpop.offsetHeight) / 2),10) + "px"  ;						
		dvpop.style.left = parseInt(10 + ((document.body.clientWidth - dvpop.offsetWidth) / 2),10) + "px";	
	}
//			if (document.forms[0].bank_card_choose1_txtGCNumber) 
//				document.forms[0].bank_card_choose1_txtGCNumber.focus();
//			else if (document.forms[1].bank_card_choose1_txtGCNumber) 
//				document.forms[1].bank_card_choose1_txtGCNumber.focus();
	 
}

function positionPop() 
{
	if (document.all) {
		dvPop.style.top = parseInt((550 - 200)/2,10) + "px";		
		dvPop.style.left =  parseInt(10 + ((document.body.clientWidth  - 398) / 2)) + "px";								
	} else { 
		var dvpop = document.getElementById("dvPop");		
		dvpop.style.top = parseInt(70 +((document.body.clientHeight - dvpop.offsetHeight) / 2),10) + "px"  ;						
		dvpop.style.left = parseInt(10 + ((document.body.clientWidth - dvpop.offsetWidth) / 2),10) + "px";	
	}
	
}

function HidePop()
{
	if (document.all) 
	{	
		dvPop.style.display = "none";		
		DisplayDropDowns("inline");
	} 
	else 
	{
		document.getElementById("dvPop").style.display = "none";		
		DisplayDropDowns("inline");
	}
	btnConfirmOk_clientClick('cancel');
}

function btnConfirmOk_clientClick(param)
{
    var okBtn=document.getElementById("lnkConfirmOk")
    var canBtn=document.getElementById("lnkConfirmCancel");
    var msg=document.getElementById("msgProcessing")
    try
    {
        if (param=="ok")
        {
	        //alert("btnConfirmOk_clientClick ok");
	        okBtn.style.display="none";
	        canBtn.style.display="none";
	        msg.style.display="inline";
	        __doPostBack("lnkConfirmOk","");
	        return false;
	    }
	    else if (param=="cancel")
	    {
	        //alert("btnConfirmOk_clientClick cancel");
	        okBtn.style.display="inline";  
	        msg.style.display="none";
	        __doPostBack("lnkConfirmCancel","");
	        return false;
	    }  		    
	}	
    catch (err)
    {}
}

function btnConfirmRewardsOk_clientClick(param)
{    
    var chkBox=document.getElementById("cbRewardsVerify");
    var args=document.getElementById("lblRewardRequired");
    var okBtn=document.getElementById("lnkConfirmRewardsOk")
    var canBtn=document.getElementById("lnkConfirmCancel");
    //var msg=document.getElementById("msgProcessing")
    try
    {
        if (param=="ok")
        {
    	    if (isNull(chkBox))
	        {
		        args.style.display="";
		        return false;
	        }
	        if (chkBox.checked == false)
	        {
	            //window.alert("false");
		        args.style.display="";
		        return false;
	        }
	        args.IsValid=false;
	        args.style.display="none";	    
        
	        //alert("btnConfirmOk_clientClick ok");
	        okBtn.style.display="none";
	        canBtn.style.display="none";
	        //msg.style.display="inline";
	        __doPostBack("lnkConfirmRewardsOk","");
	        return true;
	    }
	    else if (param=="cancel")
	    {
	        //alert("btnConfirmOk_clientClick cancel");
	        okBtn.style.display="none";
	        canBtn.style.display="none";
	        __doPostBack("lnkConfirmCancel","");
	        return true;
	    }  		    
	}	
    catch (err)
    {}
}


function ShowSignInPopup()
{
    // Set the div properties
    //var dvpop = document.getElementById("dvPop");
	//dvpop.style.display = "inline";
	//dvpop.style.position = "";
	//dvpop.style.zIndex = 99;
	//if (ValidateReviewOrderPage())
    //{
        // Spawn receipt modal
        var mdlConfirm = $find("mpePopConfirm");
        mdlConfirm.show();
        
	    //DisplayDropDowns("none");
	    //setVisibleStyle();
	    return false;
	//}
}

function launch_order()
{
    // Spawn receipt modal
    var mdlConfirm = $find("mpePopTCS");
    mdlConfirm.show();
    
	//DisplayDropDowns("none");
	//setVisibleStyle();
	return false;
}

function OFAC_Verify(sender, args)
{
	var chkBox=document.getElementById("chkOFAC");
	if (isNull(chkBox))
	{
		args.IsValid = true;
		return;
	}
	if (chkBox.checked == true)
	{
		args.IsValid = true;
		return;
	}
	args.IsValid=false;
}

function REW_Verify(sender, args)
{
	var chkBox=document.getElementById("cbRewardsVerify");
	if (isNull(chkBox))
	{
		args.IsValid = true;
		return;
	}
	if (chkBox.checked == true)
	{
		args.IsValid = true;
		return;
	}
	args.IsValid=false;
}

function CHECK_Verify(sender, args)
{
	var chkBox=document.getElementById("cbCheckDisclosure");
	if (isNull(chkBox))
	{
		args.IsValid = true;
		return;
	}
	if (chkBox.checked == true)
	{
		args.IsValid = true;
		return;
	}
	args.IsValid=false;
}

function tc_Verify(sender, args)
{
    var chkBox=document.getElementById("cbAcceptTC");
	if (isNull(chkBox))
	{
		args.IsValid = true;
		return;
	}
	if (chkBox.checked == true)
	{
		args.IsValid = true;
		return;
	}
	args.IsValid=false;
}

		//shipping pop
		//function closeShippingPop()
		//{
		//	document.getElementById("divShippingAddress").style.display = "none";
		//	DisplayDropDowns("inline");
		//}

function positionThePop(popName) 
{
	var element = document.getElementById("root");
	var dvpop = document.getElementById(popName);
	dvpop.style.zIndex = -1;
	
	if (dvpop) {	
		if (element) {		
			dvpop.style.left = calculateOffsetLeft(element) + parseInt(element.offsetWidth/2) - parseInt(dvpop.offsetWidth/2) + "px";;
			//dvpop.style.top = calculateOffsetTop(element) + parseInt(element.offsetHeight/2) -  parseInt(dvpop.offsetHeight/2) + "px";					
						
		} else {
			//dvpop.style.top = parseInt(70 +((document.body.clientHeight - dvpop.offsetHeight) / 2),10) + "px"  ;						
			dvpop.style.left = parseInt(10 + ((document.body.clientWidth - dvpop.offsetWidth) / 2),10) + "px";	
	
		}	
	}
}

//########################

//Calculates total in the grid dgItems for the textboxes txtGridAmount 
//  and writes it to the lblSub
//used in Option2, option3
function calcTotalGrid()
{
    try
    {
        //re ".": On different servers there were different separators ":" "$"  not sure why.
        reAmount = new RegExp("(dgItems.)[a-zA-Z0-9_]*(.txtGridAmount)");
        reQuantity = new RegExp("(dgItems.)[a-zA-Z0-9_]*(.txtGridQuantity)");
        
        theTotal=0;
        cardTotal=0;
        
        for(i = 0; i<document.forms[0].elements.length; i++) 
        {
            txtGridAmount = document.forms[0].elements[i];
            if (
			    txtGridAmount.type == 'text' && 
			    reAmount.test(txtGridAmount.name) &&
			    !isNaN(txtGridAmount.value) && txtGridAmount.value != ""
			    )
		    {
       
			    // Next, check to see if the previous item
			    // is a Quantity box.            
			    txtGridQuantity = document.forms[0].elements[i - 1];

			    if (
				    txtGridQuantity != null &&
				    txtGridQuantity.type == "text" && 
				    reQuantity.test(txtGridQuantity.name) &&
				    !isNaN(txtGridQuantity.value) && txtGridQuantity.value != "" 
				    )
			    {
				    theTotal = eval(theTotal + (parseFloat(txtGridAmount.value) * parseFloat(txtGridQuantity.value)));
				    cardTotal = eval(cardTotal + (parseInt(txtGridQuantity.value)));
    						
			    }
			    else
			    {					
				    //theTotal = eval(theTotal + parseFloat(txtGridAmount.value));					
			    }
    					
            }
        
        }
        
        label = document.getElementById("lblSub");
        cardLabel = document.getElementById("lblCards");
        
        if (label != null)
            label.innerHTML = "$" + CommaFormatted(theTotal + ".00");
        
        // Set Card number total
        if (cardLabel != null)
            cardLabel.innerHTML = " " + cardTotal;
            
        // Remove the style from the check panel and let the CSS do it's thing
        document.getElementById('select_payment').attributes.removeNamedItem('style');
        document.getElementById("select_payment").style.display = "none";
        
        //var background = document.getElementById("AJAXPopup_backgroundElement");    
        //if (background != null) 
        //{
         //   background.style.left = "0";
        //    background.style.top = "0";    
        //}
    }
    catch(err)
    {}
        
}

function jsFillDown(e)
{
    
	    var targ;
	    //var e = window.event;
	    if (e.target) targ = e.target;
	    else if (e.srcElement) targ = e.srcElement;
	    if (targ.nodeType == 3) // defeat Safari bug
		    targ = targ.parentNode;
        
        NUMBERS="1234567890";
        for (beginLength=8; beginLength<targ.id.length; beginLength++)
        {
            if (NUMBERS.indexOf(targ.id.charAt(beginLength))>0)
                break;
        } 
        beginString=targ.id.substring(0,beginLength);
        endString=targ.id.substring(beginLength);
        itemIndex=endString.substring(0,endString.indexOf("_"));
        endString=endString.substring(endString.indexOf("_"));

        addZero=false;//on some servers it is 2 on others 02 
        if (!isNull(document.getElementById(beginString+2+"_txtGridName")) || !isNull(document.getElementById(beginString+3+"_txtGridName")))
            addZero=false;
        else
            addZero=true;
        
        itemIndex=parseInt(itemIndex);
        itemIndexString=itemIndex<10 && addZero?"0"+itemIndex:""+itemIndex;
        
        
        var Name= document.getElementById(beginString+itemIndexString+"_txtGridName");
        var Message= document.getElementById(beginString+itemIndexString+"_txtGridMessage");
        var Quantity= document.getElementById(beginString+itemIndexString+"_txtGridQuantity");
        var Amount= document.getElementById(beginString+itemIndexString+"_txtGridAmount");
        
        NameText=Name.value;
        MessageText=Message.value;
        AmountText=Amount.value;
        QuantityText="1";

        if (NameText=="" || AmountText=="")
        {
            return;////////////////////////////////////////////////////////////////////////////////////
        }
        
        itemIndex++;
        itemIndexString=itemIndex<10 && addZero?"0"+itemIndex:""+itemIndex;
        Name= document.getElementById(beginString+(itemIndexString)+"_txtGridName");
        Message= document.getElementById(beginString+(itemIndexString)+"_txtGridMessage");
        Quantity= document.getElementById(beginString+itemIndexString+"_txtGridQuantity");
        Amount= document.getElementById(beginString+itemIndexString+"_txtGridAmount");
        
        while(!isNull(Name) && !isNull(Message))
        {
            if (Name.value=="" && Message.value=="" && Amount.value=="")
            {
                Name.value=NameText;
                Message.value=MessageText;
                Amount.value=AmountText;
                Quantity.value=QuantityText;
            }
            
            itemIndex++;
            itemIndexString=itemIndex<10 && addZero?"0"+itemIndex:""+itemIndex;
            
            Name= document.getElementById(beginString+itemIndexString+"_txtGridName");
            Message= document.getElementById(beginString+itemIndexString+"_txtGridMessage");
            Quantity= document.getElementById(beginString+itemIndexString+"_txtGridQuantity");
            Amount= document.getElementById(beginString+itemIndexString+"_txtGridAmount");
        }   

        //update total calculation
        calcTotalGrid();
  
}

function CheckPanelChange(param)
{
    // Reset validation boxes
    document.getElementById("validationSummaryCheck1").ShowSummary = false;
    document.getElementById("validationSummaryCheck2").ShowSummary = false;
    document.getElementById("validationSummaryCheck3").ShowSummary = false;
    
    document.getElementById("pnlConvertCheck").style.display = "none";
    document.getElementById("pnlCreateCheck").style.display = "none";
	document.getElementById("pnlDraftCheck").style.display = "none";

    // This will show and hide the panels of the eCheck selection pop
    if (param=="Check1")
    {
	    document.getElementById("pnlConvertCheck").style.display = "block";
	    document.getElementById("tbCheckNumber01").focus();
	    
	    // Show the check image from the background
	    //document.getElementById("pnlCheckImage").style.display = "inline";
	    
	}
	else if (param=="Check2")
	{
	    document.getElementById("pnlCreateCheck").style.display = "block";
	    document.getElementById("tbCheckNumber02").focus();
	    
	    // Show the check image from the background
	    //document.getElementById("pnlCheckImage").style.display = "inline";
	}
	else if (param=="Check3")
	{
	    document.getElementById("pnlDraftCheck").style.display = "block";
	    
	    // Show the check image from the background
	    document.getElementById("pnlCheckImage").style.display = "none";
	}
	else
	{	    
	    // Remove the check image from the background
	    document.getElementById("pnlCheckImage").style.display = "none";
	}  		    
}

function CheckForOption4()
{
    var resStates = document.getElementById("lblRestrictedStates");
    
    if(resStates.innerHTML != "Label" && document.getElementById("lblFinished").innerHTML == "")
    {
        // Modal for the Option 4 warning
        var mdlConfirm = $find('mpePopMSGOption4');
        if(mdlConfirm != null) mdlConfirm.show();
        
        //__doPostBack('btnShowStates','OnClick');
        document.getElementById("lblFinished").innerHTML = "done";
    }
    else
    {
        // Modal for the Option 4 warning
        var mdlConfirm = $find('mpePopMSGOption4');
        if(mdlConfirm != null) mdlConfirm.hide();
    }

}

function HidePaymentDropDown()
{
    var paymentDrop = document.getElementById("ddlPaymentSelection");
    if (paymentDrop != null) paymentDrop.visible = false;
    
    // Need to add in the Shipping drop as well
    var shippingDrop = document.getElementById("ddlShippingMethod");
    if (shippingDrop != null) shippingDrop.visible = false;
}


function JSTest()
{
    try
    {
        // enablethe submit button because JS is turned on
        //var LoginBtn = document.getElementById("btnLogin");
        var login = document.getElementById("txtLogin");
        var password = document.getElementById("txtPassword");
        var JSLabel = document.getElementById("lblJSNot");
        //LoginBtn.style.display = "inline";
        login.disabled = false;
        password.disabled = false;
        JSLabel.innerHTML = "";            
        
        return false;
    }
    catch (err)
    {}
}

function ChangeToAMEX()
{
    // Get the elements of the page and test
    var pnlAMEX = document.getElementById("pnlAMEX");
    var pnlVisa = document.getElementById("pnlVisa");
    pnlAMEX.style.display = "";
    pnlVisa.style.display = "none";    
    
}

function ChangeToVISA()
{
    // Get the elements of the page and test
    var pnlAMEX = document.getElementById("pnlAMEX");
    var pnlVisa = document.getElementById("pnlVisa");
    pnlAMEX.style.display = "none";
    pnlVisa.style.display = ""; 
    
}

function SetPageElements()
{
    // Set initial panel attribs
    var pnlAMEX = document.getElementById("pnlAMEX");
    pnlAMEX.style.display = "none";

}

function MoveToEdit()
{
    //window.open('terms_and_conditions_pop.aspx?TCID=' + document.getElementById("Left_nav2_lblBankName").innerHTML + '#fees','','left=100,top=50,width=780,height=500,scrollbars=1');
    try
    {
        document.location.hash = "EDIT01";
    }
    catch (err)
    {        
    }
    
}

function ShowShippingPop()
{	
    // Spawn receipt modal
    var mdlConfirm = $find("mpePopShippingDef");
    mdlConfirm.show();
	return true;
}

function ShowCardOptions(param,imgNum)
{	
    // Spawn receipt modal
    var packageArray = gcPackage[imgNum].split("|");
    var mdlCardOptions = $find("mpeCardOptions");
    
    // Set the image
    document.Form1.imgCardOptions.src = packageArray[1];
    document.getElementById("lblCardOptionsName").innerHTML = packageArray[2];
    
    // reset the panels
    document.getElementById("pnlAmexCardOptions").style.display = "none";
    document.getElementById("pnlAMEXRewardCardOptions").style.display = "none";
    document.getElementById("pnlVisaCardOptions").style.display = "none";
    
    if(mdlCardOptions != null)
    {
        // Change the image based on the param sent in
        if (param == 1)
        {
	        document.getElementById("pnlAMEXRewardCardOptions").style.display = "";      
	        document.getElementById("lblCardOptionTerms").innerHTML = "The American Express Rewardcard: Use only at US merchants that accept American Express Cards except cruise lines and casinos. Not for use at ATMs or for recurring payments. Not redeemable for cash. No fees after purchase. Funds expire on the date printed on the back of the card. For more information, customer service, or Cardholder Agreement visit www.simon.com/rewardcard or call 1-800-297-7327. Issued by AEPCMC by license from American Express Travel Related Services Co., Inc.";
	   
	         	     
	    }
	    else if (param == 2)
	    {    	
    	    document.getElementById("pnlAmexCardOptions").style.display = "";
    	    document.getElementById("lblCardOptionTerms").innerHTML = "The American Express Simon Giftcard: Use only at US merchants that accept American Express Cards except cruise lines and casinos. Not for use at ATMs or for recurring payments. Not redeemable for cash. No fees after purchase. For more information, customer service, or Cardholder Agreement visit simongiftcard.com or call 1-800-331-5479. Issued by AEPCMC by license from American Express Travel Related Services Co., Inc.";
	    }
	    else if (param == 3)
	    {    	
    	    document.getElementById("pnlVisaCardOptions").style.display = "";
    	    document.getElementById("lblCardOptionTerms").innerHTML = "The Simon Visa Giftcard: Terms and conditions apply (including an administrative fee of up to $2.95 per month beginning in the thirteenth month after card purchase, or after 13 consecutive months of nonuse for cards sold in or shipped to NY). Complete details, including information about additional fees which may apply, are available at participating Simon malls, on-line at www.simongiftcard.com, and in materials that accompany each card. The Simon Visa Giftcard is issued by MetaBank or U.S. Bank National Association.";
	    }
	    // Show the options pop
        mdlCardOptions.show();
    }
    else window.alert("false");
}



