
var _previewMediaOff = true;
//var html = "<div><table cellspacing='0' cellpadding='4' border='0' id='Table1' style='color: #333333;font-size: Smaller; border-collapse: collapse; width:500px'><tr style='color: White; background-color: #507CD1; font-weight: bold;'><th scope='col' style='height: 23px; width:50%'>CARD</th><th scope='col' style='height: 23px; width:25%'>AMOUNT</th><th scope='col' style='height: 23px; width:25%'># OF CARDS</th></tr><tr style='background-color: #EFF3FB;'></tr> </table></div>";

var html ="<div><table id='Table1' style='FONT-SIZE: smaller; width: 500px; COLOR: #333333; BORDER-COLLAPSE: collapse' cellspacing='0' cellpadding='3' border='2'><tbody><tr style='font-weight: bold; color: white; background-color: #507cd1'><th colspan='3' scope='col' style='height: 31px; text-align: left'><span style='font-size: 14pt'>Giant Eagle Gift Cards</span><img src='~Images/GiftCards/Close.JPG'/></th></tr>"
    html+="<tr style='font-weight: bold; color: white; background-color: #507cd1'><th colspan='3' scope='col' style='height: 31px; text-align: left'><span style='font-size: 12pt'>Shipping Giant Eagle cards to Maryland ?</span><img src='' /></th></tr>"   
    html+="<tr style='font-weight: bold; COLOR: white; background-color:#507cd1'><th style='width: 50%; height: 31px' scope='col'>CARD</th><th style='width: 25%; height: 31px' scope='col'>AMOUNT</th><th style='width: 25%; height: 31px' scope='col'># Of CARDs</th></tr></tbody>"
var id =null;
var giftcardname;
var add = new Array();
//add[0] = new Array();
//add[1] = new Array();
//add[2] = new Array();
function previewOff() {
    if (_previewMediaOff)
    {
        document.getElementById("PreviewPane").style.display = "none";
    }
}
function previewMedia(showHide,identity,code,price,groupcode) 
{
    var previewElement = document.getElementById("PreviewPane");
    //var brandname =document.getElementById(id).innerHTML;
    if (!showHide)
    {
        _previewMediaOff = true;
        setTimeout("previewOff()", 500);
        return;
    }
    id = identity;
   GiantEagle.Applications.InternetSites.Web.Services.GiftCardService.GetCardsByPriceAndCode(code,price,groupcode,callbackGiftCard, callbackAjaxError);
   
    var path ="../Images/StoreLocator/gelogo.gif";
   
    //var html = "<img src='"+path+"' />";
 //   var html = "<div><table cellspacing='0' cellpadding='4' border='0' id='Table1' style='color: #333333;font-size: Smaller; border-collapse: collapse;'><tr style='color: White; background-color: #507CD1; font-weight: bold;'><th scope='col' style='height: 23px'>CARD</th><th scope='col' style='height: 23px'>AMOUNT</th><th scope='col' style='height: 23px'># OF CARDS</th></tr><tr style='background-color: #EFF3FB;'></tr> </table></div>";
   // previewElement.innerHTML = html;
    previewElement.style.left = event.clientX   + 25;
    previewElement.style.top =  event.clientY   + document.body.scrollTop;
    if (!_previewMediaOff)
    {
        _previewMediaOff = false;
        showPreviewMedia();
    }
    else
    {
        _previewMediaOff = false;
        // setTimeout("showPreviewMedia()", 1000);  
    }    
}


function showPreviewMedia() {

    if (_previewMediaOff)
    {
        return;
    }
    var previewElement = document.getElementById("PreviewPane");
    previewElement.style.display = "block";
}

function previewPaneMouseOver() {
///debugger;
    _previewMediaOff = false;
}

function previewPaneMouseOut() {

    _previewMediaOff = true;
    
    //setTimeout("previewOff()", 500);
}

function document_onmouseover(e) 
{
//debugger;
//    e = getSourceElement(e);
//    if (e.className == "nodeItem")
//    {
//        e.style.textDecoration = "underline";
//        e.style.color = "blue";
//    }
//    else if (e.className == "node")
//    {
//        e.style.color = "#b22222";
//    }
}
function document_onmouseout(e) 
{
//debugger;

//    e = getSourceElement(e);
//    if (e.className == "nodeItem")
//    {
//        e.style.textDecoration = "";
//        e.style.color = "";
//    }
//    else if (e.className == "node")
//    {
//        e.style.color = "";
//    }
}

 function menuOver(o)
 {
    _menuOn = true;
    o.style.background = "#FAFAD2";
 }
 
 function menuOut(o)
 {
    _menuOn = false;
    o.style.background = "white";
    setTimeout("checkMenuOn()", 500);
 }



document.onmouseover = document_onmouseover;
document.onmouseout = document_onmouseout;


// Function to get the current location of the control on the scree,,
function findPos(obj)
{

//debugger;
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function callbackGiftCard(result)
{
    if (!result.OperationSucceeded)
    {
        alert("There was an error retrieving the folder.\n\n" + result.ClientErrorMessage);
        return;
    }
    // Clear out any selected items
   
    var GiftCardDetails = result.ClientData;
    //debugger;
//    var previewElement = document.getElementById("PreviewPane");
//    //var html = "<div><table cellspacing='0' cellpadding='4' border='0' id='Table1' style='color: #333333;font-size: Smaller; border-collapse: collapse;'><tr style='color: White; background-color: #507CD1; font-weight: bold;'><th scope='col' style='height: 23px'>CARD</th><th scope='col' style='height: 23px'>AMOUNT</th><th scope='col' style='height: 23px'># OF CARDS</th></tr><tr style='background-color: #EFF3FB;'></tr> </table></div>";
//    previewElement.innerHTML = html;
//    previewElement.style.left = event.clientX   + 25;
//    previewElement.style.top =  event.clientY   + document.body.scrollTop;
//    if (!_previewMediaOff)
//    {
//        _previewMediaOff = false;
//        showPreviewMedia();
//    }
//    else
//    {
//        _previewMediaOff = false;
//         setTimeout("showPreviewMedia()", 500);  
//    }    

       
        for (var i = 0; i < GiftCardDetails.length; i++)
        {
        var itemName = GiftCardDetails[i].ItemTypeName;
        var createdname = itemName.replace("&reg;","");
        createdname = createdname.replace("'","");
        createdname = createdname.replace("$","");
        
           html+="<tr><td style=display:inline-table; width:50%; >"
                +"<img src='http://www.gianteagle.com"+GiftCardDetails[i].ImageLocation+"'; style='text-align: center'></td>"
                +"<td style=display:inline-table; width: 25%  text-align: center;>"
                +"<b>$"+GiftCardDetails[i].DenominationAmount.Value+" </b></td>"
                +"<td style=display:inline-table; width: 25%; text-align: center;>"
                //+"<select name=PriceDropDown"+"'"+[i]+"' id=PriceDropDown"+"'"+[i]+"' onchange='test('"+GiftCardDetails[i].DenominationAmount.Value+"','"+GiftCardDetails[i].DenominationAmount.Value+"');'>" '"+i+"'
                +"<select name=PriceDropDown"+""+[i]+"; id=PriceDropDown"+""+[i]+";  onchange=additems('"+GiftCardDetails[i].ItemTypeId.Value+"','"+GiftCardDetails[i].ItemGroupCode+"','"+GiftCardDetails[i].DenominationAmount.Value+"',this);>"
                +"<option value='All' selected='selected'></option>"
                +"<option value='1'>1</option>"
                +"<option value='2'>2</option>"
                +"<option value='3'>3</option>"
                +"<option value='4'>4</option>"
                +"<option value='5'>5</option>"
                +"<option value='6'>6</option>"
                +"<option value='7'>7</option>"
                +"<option value='8'>8</option>"
                +"<option value='9'>9</option>"
                +"<option value='10'>10</option>"
                +"<option value='11'>11</option>"
                +"<option value='12'>12</option>"
                +"<option value='13'>13</option>"
                +"<option value='14'>14</option>"
                +"<option value='15'>15</option>"
                +"</select>"
                +"</td></tr>"
           

            
        }
       
    html+="<tr><td style=display:inline-table; width:50%;>Terms&Conditions</td><td></td><td style=display:inline-table; width: 25%>&nbsp; &nbsp; &nbsp;&nbsp;"
    html+="<input id='Button1' type='button' value='Add To Cart' onclick='addtocart()'/></td></tr>"
    //html+="<asp:Button ID='Button2' runat='server' Text='Button' /></td></tr>"
    html+="</table>";
    
        
    var previewElement = document.getElementById("PreviewPane");
     previewElement.innerHTML = html;
    html ="";
    html ="<div><table id='Table1' style='FONT-SIZE: smaller; width: 500px; COLOR: #333333; BORDER-COLLAPSE: collapse' cellspacing='0' cellpadding='3' border='2'><tbody><tr style='font-weight: bold; color: white; background-color: #507cd1'><th colspan='3' scope='col' style='height: 31px; text-align: left'><span style='font-size: 14pt'>Giant Eagle Gift Cards</span></th></tr>"
    html+="<tr style='font-weight: bold; color: white; background-color: #507cd1'><th colspan='3' scope='col' style='height: 31px; text-align: left'><span style='font-size: 12pt'>Shipping Giant Eagle cards to Maryland ?</span></th></tr>"   
    html+="<tr style='font-weight: bold; COLOR: white; background-color:#507cd1'><th style='width: 50%; height: 31px' scope='col'>CARD</th><th style='width: 25%; height: 31px' scope='col'>AMOUNT</th><th style='width: 25%; height: 31px' scope='col'># Of CARDs</th></tr></tbody>" //     var sd  =document.getElementById(id);
    
   
  }
  
  
  
  
  
function callbackAjaxError(result)
{
    var message = "There was an error with the remote call : \n" + 
        result._exceptionType + 
        result._message +
        result._stackTrace +
        "\nTime Out: " + result._timedOut;
        alert(message);
   
} 

function additems(itemTypeId,itemGroupCode,denaminationValue,item)
{
//debugger;
GiantEagle.Applications.InternetSites.Web.Services.GiftCardService.GetCardsByitemid(itemTypeId,callbackGiftCardName, callbackAjaxError);
var presentcount=add.length;
var noOfCards = item.selectedIndex;
sum = 0;
    add[presentcount] = new Array();
   
    add[presentcount][0] = itemTypeId;
    add[presentcount][1] = denaminationValue;
    add[presentcount][2] = noOfCards;
    
    add[presentcount][3] = giftcardname;
    

    
    
//for (x = 0; x < add.length; x++)
//{
//   
////        ////( add[x][1]==itemTypeId ) add[x].length==0
////        if( add[x][0]==itemTypeId)
////            {
////            //Code To update the array
////                presentcount = x;
////                add[presentcount][0] = itemTypeId;
////                add[presentcount][1] = denaminationValue;
////                add[presentcount][2] = noOfCards;
////             break;
////            }
////        else if(add[x].length==0)
////        {
////        //Code to insert it in the array
////            add[x] = new Array();
////            presentcount = x;
////            add[presentcount][0] = itemTypeId;
////            add[presentcount][1] = denaminationValue;
////            add[presentcount][2] = noOfCards;
////            alert("u r doing it correctly");
////            break;
////        }
//}

}


/* Add window.event to Firefox  */

if(!window.event && window.captureEvents) {
  // set up event capturing for mouse events (add or subtract as desired)
  window.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT|Event.CLICK|Event.DBLCLICK);
  // set window event handlers (add or subtract as desired)
  window.onmouseover = WM_getCursorHandler;
  window.onmouseout = WM_getCursorHandler;
  window.onclick = WM_getCursorHandler;
  window.ondblclick = WM_getCursorHandler;
  // create an object to store the event properties 
  window.event = new Object;
}
function WM_getCursorHandler(e) {
  // set event properties to global vars (add or subtract as desired)
  window.event.clientX = e.pageX;
  window.event.clientY = e.pageY;
  window.event.x = e.layerX;
  window.event.y = e.layerY;
  window.event.screenX = e.screenX;
  window.event.screenY = e.screenY;
  // route the event back to the intended function
  /*if ( routeEvent(e) == false ) {
    return false;
  } else {
    return true;
  }*/
}


function addtocart()
{
//debugger;
     //alert("i'm herer");
//     var loginmail =document.getElementById("Hidden1");
    
     var htmlForCart="";
for ( var x = 0; x < add.length; x++)
{
       htmlForCart+= "<tr><td style=display:inline-table; width: 50%  text-align: center;>"
                     +"<b>"+add[x][3]+" </b></td>"
                     +"<td style=display:inline-table; width: 25%  text-align: center;>"
                     +"<b>"+add[x][2]+"@      </b></td>"
                     +"<td style=display:inline-table; width: 25%  text-align: center;>"
                     +"<b>"+add[x][1]+" </b></td></tr>"
}              
htmlForCart+= "<tr><td></td><td><a href='GiftCard.asmx'>View Cart</a></td><td></td>"

var tab =document.getElementById("Cart");
tab.outerHTML+= htmlForCart;

//     if(loginmail ==null)
//     {
//     
//     }
//     else
//     {
//     
//     }
     
}

function callbackGiftCardName(result)
{
var giftcards =result.ClientData;
 giftcardname = giftcards[0].ItemTypeName;
}

function OpenChild() 
{
//    var ParmA = retvalA.value;
//    var ParmB = retvalB.value;
//    var ParmC = retvalC.value;
    var ParmA = "123";
    var ParmB = "354";
    var ParmC = "345";
    var MyArgs = new Array(ParmA, ParmB, ParmC);
    var WinSettings = "center:yes;resizable:no;dialogHeight:300px"
    //ALTER BELOW LINE - supply correct URL for Child Form
    var MyArgs = window.showModalDialog(
   "CartPopUp.aspx", MyArgs, WinSettings);
    if (MyArgs == null)
    {
        window.alert(
          "Nothing returned from child. No changes made to input boxes")
    }
    else
    
    {
    alert("Returning Something");
//        retvalA.value=MyArgs[0].toString();
//        retvalB.value=MyArgs[1].toString();
//        retvalC.value=MyArgs[2].toString();
    }
}

function Done() {
    var ParmA = tbParamA.value;
    var ParmB = tbParamB.value;
    var ParmC = tbParamC.value;
    var MyArgs = new Array(ParmA, ParmB, ParmC);
    window.returnValue = MyArgs;
    window.close();
}
function doInit() {
    var ParmA = "Aparm";
    var ParmB = "Bparm";
    var ParmC = "Cparm";
    var MyArgs = new Array(ParmA, ParmB, ParmC);
    MyArgs =  window.dialogArguments;
    tbParamA.value = MyArgs[0].toString();
    tbParamB.value = MyArgs[1].toString();
    tbParamC.value = MyArgs[2].toString();
}


// These is required for the New desgin

function previewMedia2(showHide,identity,code,price,groupcode) 
{
debugger;
    var previewElement = document.getElementById("PreviewPane");
    //var brandname =document.getElementById(id).innerHTML;
    if (!showHide)
    {
        _previewMediaOff = true;
        setTimeout("previewOff()", 500);
        return;
    }
    id = identity;
   //GiantEagle.Applications.InternetSites.Web.Services.GiftCardService.GetCardsByPriceAndCode(code,price,groupcode,callbackGiftCard, callbackAjaxError);
   
//    var html = "<img src='" + _geApplicationRoot + "/GiftCardDetails.aspx?Code=" + code + "' &>";
//    previewElement.innerHTML = html;

   
    previewElement.style.left = event.clientX   + 25;
    previewElement.style.top =  event.clientY   + document.body.scrollTop;
    if (!_previewMediaOff)
    {
        _previewMediaOff = false;
        showPreviewMedia();
    }
    else
    {
        _previewMediaOff = false;
        // setTimeout("showPreviewMedia()", 1000);  
    }    
}


function PreformatDiv(obs)
{
alert(obs);
}

function ShowTerms()
{

 if(Terms.style.visibility =="hidden")
             {
             
                Terms.style.visibility ="visible";
                Terms.style.display ="inline";
                document.getElementById("Image2").src="../Images/StoreLocator/DownCircleArrow.gif" ;
             }
            else if(Terms.style.visibility =="visible")
             {
                Terms.style.visibility ="hidden";
                Terms.style.display ="none";
                 document.getElementById("Image2").src="../Images/StoreLocator/CircleArrowRight.gif" ;
             }

}
function adjustQty(quantityElementId, direction) {
    var quantityElement = document.getElementById(quantityElementId);
    var iValue = parseInt(quantityElement.value);
    
    if (!isNaN(iValue)) {
        if (direction == "+") {
            iValue = iValue + 1;
        } else {
            iValue = iValue - 1;
        }
        
        if (iValue < 0)
        {
            iValue = 0;
        }
        
        quantityElement.value = iValue;
    } else {
        alert("The value you chose to increment/decrement was not a valid number.  This value has been reset to 0.");
        quantityElement.value = 0;
    }
}