
/*  Called by: checkout_dialog_confirm_creditcard_removal.jsp 
*/

/*  This method is called to delete the creditcard from profile or order
    cardType - Indicates creditcard to be deleted is from profile/order
*/
function submitCartType(cardType)  {
    if (cardType == "profile")
        document.getElementById('profileDelete').click();
    else if (cardType == "order")
        document.getElementById('orderDelete').click();
}

/* checkout_dialog_confirm_creditcard_removal.jsp ends
*/

/*  Called by: payment_display.jsp
*/

/*  This method opens the confirmation popup for deleting the creditcard
    cardKey - Key of the creditcard to be deleted
    cardType - Indicates creditcard to be deleted is from profile/order
*/
function openRemoveCardPopup(cardKey,cardType) {
	window.name="BillingInfo";
	var dialogUrl = "checkout_dialog_confirm_creditcard_removal.jsp?cardKey="+cardKey+"&cardType="+cardType;
	if (window.showModalDialog) {
		var returnVal = window.showModalDialog(dialogUrl,'Confirm Creditcard Removal','dialogWidth:555px;dialogHeight:147px;resizable:no;help:no;status:no;scroll:no');
	} else {
		var returnVal = window.open(dialogUrl, "Confirm Creditcard Removal", "width=555,height=147,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
	window.location.href="payment_container.jsp";
}
    
    /*  This method opens the confirmation popup for deleting the creditcard
    cardKey - Key of the creditcard to be deleted
    cardType - Indicates creditcard to be deleted is from profile/order
    */
function openRemoveRxCardPopup(cardKey,cardType) {
	window.name="BillingInfo";
	var dialogUrl = "checkout_dialog_confirm_creditcard_removal.jsp?cardKey="+cardKey+"&cardType="+cardType;
	if (window.showModalDialog) {
		var returnVal = window.showModalDialog(dialogUrl,'Confirm Creditcard Removal','dialogWidth:555px;dialogHeight:147px;resizable:no;help:no;status:no;scroll:no');
	} else {
	var returnVal = window.open(dialogUrl, "Confirm Creditcard Removal", "width=555,height=147,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
	window.location.href="rx_payment_container.jsp";
}
    
/*  This method invokes click() on the hidden submit button for editing creditcard
    cardType - Indicates creditcard to be edited is from profile/order/default
    cardKey - Key of the creditcard to be edited (Passed only if cardType is "profile")
*/
function submitEditCard(cardType,cardKey,fsaCard)       {
    var selectedCard = document.getElementById('selectedCard');
    if(cardType=='default')
    {
        selectedCard.value='default';           
    }
    if(cardType=='order')
    {
        selectedCard.value='order';
    }
    if(cardType=='profile')
    {
        selectedCard.value='profile';
        document.getElementById('cardId').value=cardKey
    }
	document.getElementById('fsaCard').value=fsaCard;
    document.getElementById('cardSubmit').click();
}

/*  This method invokes click() on the hidden submit button to call the handle method
*/
function verifyOrder()  {
    document.getElementById('verifyOderSubmit').click();
}

/* payment_display.jsp ends
*/

/*  Called by: payment_edit.jsp,
               payment_enter.jsp,
               ship_enter_location.jsp 
*/

/*  This method turns on/off the copyToProfile checkbox based on the value for makeDefault  
*/
function setCopyToProfile() {
    var makeDefault=document.getElementById("makeDefault");
    var copyToProfile=document.getElementById("copyToProfile");

    if(makeDefault.checked==true)
    {
    document.getElementById("copyToProfile").checked=true;
    document.getElementById("copyToProfile").disabled=true;
    }

    if(makeDefault.checked==false)
    {
    document.getElementById("copyToProfile").checked=false;
    document.getElementById("copyToProfile").disabled=false;
    }
}

/*This method shows mandatory mark next to phone and nickname
when customer chooses to save shipping address to profile*/
function makeMandatory(nickName,phone,savetoProfileCB)
{
	
	if(document.getElementById(savetoProfileCB).checked)
	{
		document.getElementById(nickName).style.display='block';
		document.getElementById(phone).style.display='block';
	}
	else
	{
		document.getElementById(nickName).style.display='none';
		document.getElementById(phone).style.display='none';
	}
	  
}


/*  payment_edit.jsp, payment_enter.jsp, ship_enter_location.jsp ends
*/

/*  Called by: payment_enter.jsp 
*/

/*  This method clears the default value of the expiration date 
    when the user clicks on the text field  
*/
function goToBlankExpiryDate(idField)   {
    if(document.getElementById(idField).value == "MMYY")
    document.getElementById(idField).value = "";
}
/*  payment_enter.jsp ends
*/

/*  Called by: dialog_change_ship_addrs_fs.jsp 
*/

/*  This method is used to submit the form
*/ 
 function submitShipping()  {
    
    document.defaultSelectForm.submit();   
 }

/*  This method invokes click() on the hidden submit button to call the handle method
*/
 function editSubmit(addressId) {
    var elementName = "editSubmit"+addressId;
    document.getElementById(elementName).click();
 }

/*  This method invokes click() on the hidden submit button to call the handle method
*/
 function submitShipping1(ShipId)   {
    var elementName = "submit"+ShipId;
    document.getElementById(elementName).click();
 }

/*  This method invokes click() on the hidden submit button to call the handle method
*/    
function deleteShipping(ShipId) {
    var elementName = "submit2"+ShipId;
    document.getElementById(elementName).click();
    window.close();
}

/*  This method is invoked on body load and
    used to set the focus on select button so that popup can be scrolled down using keys
*/    
function setFocus() {
    if (document.getElementById("selectAddress"))
        document.getElementById("selectAddress").focus();
}


/*  dialog_change_ship_addrs_fs.jsp ends
*/


/*  Called by: ship_select_location.jsp
               shipping_addr.jsp 
*/

/*  This method invokes click() on the hidden submit button to call the handle method   
*/
function editSubmitShippingInfo()   {
    document.getElementById('editSubmit').click();
}

/* ship_select_location.jsp, shipping_addr.jsp ends
*/

/* Called by: ship_select_location.jsp 
*/

/*  This method opens the popup with all the shipping addresses saved in profile    
*/
function openDialog(URL) {
	window.name="select_location_page";
	var dialogUrl = "dialog_change_ship_addrs_fs.jsp?requestPage="+URL;
	if (window.showModalDialog) {
		var returnVal = window.showModalDialog(dialogUrl,'','dialogWidth:580px;dialogHeight:480px;resizable:no;help:no;status:no;scroll:yes');
	} else {
		var returnVal = window.open(dialogUrl, "", "width=580,height=480,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

/*  This method opens the popup with all the shipping addresses saved in profile    
*/
function openDialog_rx(URL) {
	window.name="rx_location_page";
	if (window.showModalDialog) {
		var returnVal = window.showModalDialog('dialog_change_ship_addrs.jsp','ShippingAddress','dialogWidth:565px;dialogHeight:457px;resizable:no;help:no;status:no;scroll:no');
		window.location.href=URL;
	} else {
		var returnVal = window.open("dialog_change_ship_addrs.jsp", "ShippingAddress", "width=565,height=457,scrollbars=yes,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function openDialogedit_rx(URL) {
	window.name="rx_location_page";
	if (window.showModalDialog) {
		var returnVal = window.showModalDialog('dialog_enter_ship_addrs.jsp?enterOrEdit=edit','ShippingAddress','dialogWidth:482px;dialogHeight:591px;resizable:no;help:no;status:no;scroll:yes');
		window.location.href=URL;
	} else {
		var returnVal = window.open("dialog_enter_ship_addrs.jsp?enterOrEdit=edit", "ShippingAddress", "width=482,height=591,scrollbars=yes,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function openDialogenter_rx(URL) {
	window.name="rx_location_page";
	if (window.showModalDialog) {
		var returnVal = window.showModalDialog('dialog_enter_ship_addrs.jsp?enterOrEdit=enter','ShippingAddress','dialogWidth:482px;dialogHeight:591px;resizable:no;help:no;status:no;scroll:yes');
		window.location.href=URL;
	} else {
		var returnVal = window.open("dialog_enter_ship_addrs.jsp?enterOrEdit=enter", "ShippingAddress", "width=482,height=591,scrollbars=yes,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function findStore(Url) {
	window.name="rx_location_page";
	if (window.showModalDialog) {
		window.showModalDialog('/CVSApp/store/checkoutstorefinder.jsp','Instore','dialogWidth:550px;dialogHeight:598px;resizable:no;help:no;status:no');
		window.location.href=Url;
	} else {
	window.open("/CVSApp/store/checkoutstorefinder.jsp", "Instore", "width=550,height=598,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}
    
function setReturnValue(parentURL)
{
        returnValue = parentURL;
        close();    
}


function selectStoreById(storeId)
{
         document.getElementById("currentStoreId").value = storeId;     
         document.getElementById("storeIdsubmit").click();
}

function addAddress() {
	window.name="ChangeAddress";
	if (window.showModalDialog) {
		window.showModalDialog("dialog_enter_ship_addrs.jsp","","dialogWidth:476px;dialogHeight:500px;resizable:no;help:no;status:no;scroll:yes");
		window.location.href="/cvs/checkout/rx/rx_select_location.jsp";
	} else {
		window.open("dialog_enter_ship_addrs.jsp", "", "width=476,height=500,scrollbars=yes,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function addAddress1(enteroredit) {
	window.name="ChangeAddress";
	var dialogUrl = "dialog_enter_ship_addrs.jsp?enterOrEdit="+enteroredit;
	if (window.showModalDialog) {
		window.showModalDialog(dialogUrl,"","dialogWidth:542px;dialogHeight:591px;resizable:no;help:no;status:no;scroll:yes");
		window.location.reload();
	} else {
		window.open(dialogUrl, "", "width=542,height=650,scrollbars=yes,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function addAddress2(enteroredit) {
	window.name="ChangeAddress";
	var dialogUrl = "dialog_enter_ship_addrs.jsp?enterOrEdit="+enteroredit;
	if (window.showModalDialog) {
		window.showModalDialog(dialogUrl,"","dialogWidth:476px;dialogHeight:500px;resizable:no;help:no;status:no;scroll:yes");
		window.location.reload();
	} else {
		window.open(dialogUrl, "", "width=476,height=500,scrollbars=yes,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function changeAddress(enteroredit) {
	window.name="ChangeAddress";
	var dialogUrl = "dialog_enter_ship_addrs.jsp?enterOrEdit="+enteroredit;
	if (window.showModalDialog) {
		window.showModalDialog(dialogUrl,"","dialogWidth:542px;dialogHeight:591px;resizable:no;help:no;status:no;scroll:yes");
		window.location.reload();
		window.close();
	} else {
		window.open(dialogUrl, "", "width=542,height=591,scrollbars=yes,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}


/*  This method is used to submit the form only if addressType is "profile"
*/
function continueToPayment()    {
    var addressType=document.getElementById('addressType').value;
    if(addressType=="profile")
    {
     document.shipSubmitForm.submit();  
    }
}

/* ship_select_location.jsp ends
*/

/*  Called by: shoppingcart_items.jsp 
*/

/*  This method sets the SKU ID in the hidden form field and
    invokes click() on the hidden submit button 
*/
function removeItemFromCart(catalogRefId)   {
    document.getElementById("removalItems").value = catalogRefId;       
    document.getElementById("updatecart_image").click();
}

/* This method asks for a confirmation if a commerce Item has to be removed from shopping cart or not.
*/
function confirmRemoveItemFromCart(catalogRefId, commerceItmId) {
	var dialogURL = "/CVSApp/checkout/fs/dialog_confirm_remove.jsp?commerceItmId=" + commerceItmId;
	if (window.showModalDialog) {
		var result = window.showModalDialog(dialogURL,'Add to Shoppinglist','dialogWidth:603px;dialogHeight:307px;resizable:no;help:no;status:no;scroll:yes');
		 if(result == "Yes") {
			removeItemFromCart(catalogRefId);
		}
	} else {
		var result = window.open(dialogURL, "Add to Shoppinglist", "width=603,height=307,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

/*  This method sets the values for hidden form fields that requiresd to 
    save an item in shoppinglist also invokes click() on the hidden submit button   
    Called by: shoppingcart_items.jsp 
*/
function saveItemToList(commerceItemId, catalogRefId,commercedItemQuantity) {
    document.getElementById("commerceId").value = commerceItemId;       
    document.getElementById("skuId").value = catalogRefId; 
    document.getElementById("quantity").value = commercedItemQuantity;
    document.getElementById("saveToList").click();
}

/*  This method displays confirmation popup after adding an item to Shoppinglist
*/
function showAddConfirmation(giftItemId,giftlistId) {
	if ((giftlistId != null) && (giftlistId != null)) {
		var dialogURL = "/cvs/user/add_shopping_list_confirmation.jsp?giftItemId="+giftItemId+"&giftlistId="+giftlistId;
		if (window.showModalDialog) {
			var returnVal = window.showModalDialog(dialogURL,'Add to Shoppinglist','dialogWidth:540px;dialogHeight:458px;resizable:no;help:no;status:no;scroll:no');
			if (returnVal != null) {
				window.location.href = returnVal;
			}
		} else {
			var returnVal = window.open("dialogURL", "Add to Shoppinglist", "width=540,height=458,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
		}
	}
}

/*  shoppingcart_items.jsp ends
*/

/*  Called by: ship_enter_location.jsp 
*/

/*  This method invokes click() on the hidden submit button to call the handle method   
*/
function submitShippingInfo()   {
    document.getElementById('shipAddressSubmit').click();
}

/*  This method clears the default values of nickName and phoneNumber when the user clicks on it
*/
function clearValues()  { 
    if(document.enterLocationForm.nickName != null)
    {
        if (document.enterLocationForm.nickName.value == "e.g., Work,Home")
        {
            document.enterLocationForm.nickName.value = "";
        }
    }

    if(document.enterLocationForm.phoneNumber != null)
    {
        if(document.enterLocationForm.phoneNumber.value == "000-000-0000")
        {
            document.enterLocationForm.phoneNumber.value = "";
        }
    }
   document.enterLocationForm.submit();
}

/*  ship_enter_location.jsp ends
*/

/*  Called by: verify_order.jsp 
*/

/*  This method invokes click() on the hidden submit button to call the handle method   
*/
function changeBillingInfo(fsaCard)    {
    document.getElementById('fsaCard').value=fsaCard;
    document.getElementById('cardSubmit').click();
}
/*  verify_order.jsp ends
*/

/*  Called by: personal.jsp 
*/

/*  This method opens dialog box allowing the user to edit personal details
*/
function openEditPersonalDetailsDialog() {
	window.name="VerifyOrder";
	if (window.showModalDialog) {
		window.showModalDialog('dialog_edit_personal.jsp','Edit_Personal_Details','dialogWidth:532px;dialogHeight:710px;resizable:no;help:no;status:no;scroll:yes');
		window.location.reload();
	} else {
	window.open("dialog_edit_personal.jsp", "Edit_Personal_Details", "width=532,height=710,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

/*  personal.jsp ends
*/


/*  Called by: rx_verify_order.jsp
*/

/*  This method opens dialog box allowing the user to edit personal details
*/
function editPersonal() {
	window.name="VerifyOrder";
	if (window.showModalDialog) {
		window.showModalDialog('dialog_edit_rx_personal.jsp','Edit_Personal_Details','dialogWidth:525px;dialogHeight:710px;resizable:no;help:no;status:no;scroll:yes');
		window.location.reload();
	} else {
		window.open("dialog_edit_rx_personal.jsp", "Edit_Personal_Details", "width=525,height=710,scrollbars=yes,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

/*  rx_verify_order.jsp ends
*/
/*Find A to Z Medication
*/

  function openMedicationSearchForm(id)
{
        window.open ("/CVSApp/common/rx_hi_dialog_checkout_find_medications.jsp?id="+id,
        "mywindow","resizable=0,scrollbars=0,width=545,height=438"); 
}


/*  Called by: dialog_edit_personal.jsp 
*/

/*  This method opens confirmation dialog box before saving the personal details.
    If the retuen value is "yes", it invokes click() on the hidden submit button.
*/
function displaySaveConfirmationDialog() {
	window.name = "editPersonal";
	if (window.showModalDialog) {
		var returnVal = window.showModalDialog('../fs/dialog_confirm_savechanges.jsp','Save Personal Details','dialogWidth:510px;dialogHeight:270px;resizable:no;help:no;status:no;scroll:no');
		if (returnVal == "yes") {
			if (document.getElementById("updateDetails") != null) {
				document.getElementById("updateDetails").click();
			}
		}
	} else {
		var returnVal = window.open("../fs/dialog_confirm_savechanges.jsp", "Save Personal Details", "width=510,height=270,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function clearPhoneNumbers()
{   
     if(document.add.phoneNumber.value == "000-000-0000")
        document.add.phoneNumber.value = "";
     if(document.add.daytimeTelephoneNumber.value == "000-000-0000")
        document.add.daytimeTelephoneNumber.value = "";
     if(document.add.otherPhone.value == "000-000-0000")
        document.add.otherPhone.value = "";
     document.add.submit();
}

/*  dialog_edit_personal.jsp ends
*/

/*  Called by: dialog_confirm_savechanges.jsp 
*/

/*  This method sets the returnValue for the dialog window and closes it
*/
function savePersonalInfo(buttonClicked)    {
    returnValue=buttonClicked;
    window.close();
}

/*  dialog_confirm_savechanges.jsp ends
*/

function goBack(){
    history.back();
}

// RxTransfer

function selectPharmacy(pharmacy)
        {
            var lContent1=document.getElementById('brooks').innerHTML;
            var lContent2=document.getElementById('eckerd').innerHTML;
            var lContent3=document.getElementById('frys').innerHTML;
            var lContent4=document.getElementById('giant').innerHTML;
            var lContent5=document.getElementById('happy').innerHTML;
            var lContent6=document.getElementById('heb').innerHTML;
            var lContent8=document.getElementById('osco').innerHTML;
            var lContent9=document.getElementById('riteaid').innerHTML;
            var lContent10=document.getElementById('savon').innerHTML;
            var lContent11=document.getElementById('target').innerHTML;
            var lContent12=document.getElementById('walmart').innerHTML;
            var lContent13=document.getElementById('wegmans').innerHTML;
            var lContent14=document.getElementById('walgreens').innerHTML;
            var lContent15=document.getElementById('default').innerHTML;

           if(pharmacy=='OT'){ 
                document.getElementById('otherPharmacy').style.display='block';
                }
                else
                {
                document.getElementById('otherPharmacy').style.display='none';
                }
             if(pharmacy=='BR'){                 
                 document.getElementById('labelGeneral').innerHTML=lContent1;
             }
            else if (pharmacy=='EC')
            {
                document.getElementById('labelGeneral').innerHTML=lContent2;
            }
            else if (pharmacy=='FR')
            {
                document.getElementById('labelGeneral').innerHTML=lContent3;
            }
            else if (pharmacy=='GI')
            {
                document.getElementById('labelGeneral').innerHTML=lContent4;
            }
            else if (pharmacy=='HH')
            {
                document.getElementById('labelGeneral').innerHTML=lContent5;
            }
            else if (pharmacy=='HE')
            {
                document.getElementById('labelGeneral').innerHTML=lContent6;
            }
            else if (pharmacy=='OD')
            {
                document.getElementById('labelGeneral').innerHTML=lContent8;
            }
            else if (pharmacy=='RA')
            {
                document.getElementById('labelGeneral').innerHTML=lContent9;
            }
            else if (pharmacy=='SD')
            {
                document.getElementById('labelGeneral').innerHTML=lContent10;
            }
            else if (pharmacy=='TA')
            {
                document.getElementById('labelGeneral').innerHTML=lContent11;
            }
            else if (pharmacy=='WM')
            {
                document.getElementById('labelGeneral').innerHTML=lContent12;
            }
            else if (pharmacy=='WE')
            {
                document.getElementById('labelGeneral').innerHTML=lContent13;
            }
            else if (pharmacy=='WG')
            {
                document.getElementById('labelGeneral').innerHTML=lContent14;
            }
             else
            {
                 document.getElementById('labelGeneral').innerHTML=lContent15;
            }
        }     

          /*This function adds a new field to the original <div>
      The "target_original" parameter is the main <div>
      The "source" parameter is the div that contains the newly added field
    */
    var b=1;
	var c=0;
	function addextrafields(value)
	{
		c=value-1; 
	 
	}
     function add_extra_fields()
    {
        if(true)
        {
            add_more_fields('target_div','newFields',b,c);
        }
        b++;
    }
    function replaceCharacters(conversionString,inChar,outChar)
    {
      var convertedString = conversionString.split(inChar);
      convertedString = convertedString.join(outChar);
      return convertedString;
    }
        
    function add_more_fields(target_original,source,index,indexvalue)
        {
            var ni = document.getElementById(target_original);
            var newdiv = document.createElement('div');
            newdiv.setAttribute("id","new"+index);
            newdiv.innerHTML = document.getElementById(source).innerHTML;
            var str1=document.getElementById(source).innerHTML;
         
            //Assiging id and name field dynamically
            str1 = str1.replace ('id="textf111"', 'id="textf'+index+'"');
            str1 = str1.replace ('for="textf111"', 'for="textf'+index+'"');
            str1 = str1.replace ('id="PrescriberName"', 'id="PrescriberName'+index+'"');
            str1 = str1.replace ('for="PrescriberName"', 'for="PrescriberName'+index+'"');
            str1 = str1.replace ('id="prescriberPhone"', 'id="prescriberPhone'+index+'"');
            str1 = str1.replace ('for="prescriberPhone"', 'for="prescriberPhone'+index+'"');
            str1 = str1.replace ('id="havePrescriptionPaper"', 'id="havePrescriptionPaper'+index+'"');
            str1 = str1.replace ('for="havePrescriptionPaper"', 'for="havePrescriptionPaper'+index+'"');
            str1 = str1.replace ('id="rxNumber"', 'id="rxNumber'+index+'"');
            str1 = str1.replace ('for="rxNumber"', 'for="rxNumber'+index+'"');
            str1 = replaceCharacters(str1,'findAZ','findAZ'+index); 

			// Assing Value dynamically for PaperPrescription flag.
		   	str1=str1.replace('value=101','value='+index);
		    var value = index+indexvalue; 
		   	str1=str1.replace('value=102','value='+value);   

            // Assigning the dynamic name for prescriber phone number, to clear the initial value
            str1 = replaceCharacters(str1,'newPrescriberPhone','newPrescriberPhone'+index);
            
            var temp='textf'+index;
            str1=str1.replace ("'textf111'","'"+temp+"'");
            
            newdiv.innerHTML = str1;
            ni.appendChild(newdiv);

            document.getElementById("textf"+index).focus();
    }

function clearCouponCode(control)
{
    if (control.value=" ")
    {
        control.value="";
    }

}

function openCouponsDialog(fromPage) {
	var dialogUrl = "dialog_coupon_member.jsp?fromPage="+fromPage;
	if (window.showModalDialog) {
		var retrunVal = window.showModalDialog(dialogUrl,'SC_dialog_coupon_member','dialogWidth:856px;dialogHeight:625px;resizable:no;help:no;status:no;scroll:yes');
		if (retrunVal) {
			window.location.href=retrunVal;
		} else {
			window.location.reload();
		}
	} else {
		var retrunVal = window.open(dialogUrl, "SC_dialog_coupon_member", "width=856,height=680,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function attachExtracareCard(url)
{   
    returnValue=url;
    window.close();
}

//For Checkout for masking the credit card fields
    function setCreditCardNumber()
            {
                
                var newCreditCardNumber = document.getElementById("newCreditCardNumber").value;
                var xIndex=newCreditCardNumber.indexOf("X");


                if (newCreditCardNumber=="")
                {
                    var oldCreditCardNumber = document.getElementById("oldCreditCardNumber").value;
                    document.getElementById("oldCreditCardNumber").value=newCreditCardNumber;

                }

                if(xIndex==-1)

                {
                    var oldCreditCardNumber = document.getElementById("oldCreditCardNumber").value;
                    document.getElementById("oldCreditCardNumber").value=newCreditCardNumber;
                }
                

            
            }

            

   function goToBlankCreditCard(cardId)
     {
      var newCreditCardNumber = document.getElementById(cardId).value;
       var xIndex=newCreditCardNumber.indexOf("X");

            
                if(xIndex==-1)
                {
            
                }
                else
                {
                    document.getElementById(cardId).value="";
                }

            }
            
    /*  This method invokes click() on the hidden submit button to call the handle method to save address
*/
function saveShipping()   {
    document.getElementById('defaultSelect').click();
}

function editShippingAddrs(enteroredit,URL) {
	window.name="EditAddress";
	var dialogUrl = "dialog_edit_ship_addrs.jsp?enterOrEdit="+enteroredit;
	if (window.showModalDialog) {
		var returnVal=window.showModalDialog(dialogUrl,"","dialogWidth:580px;dialogHeight:625px;resizable:no;help:no;status:no;scroll:yes");
		window.location.href=URL;
	} else {
		var returnVal = window.open(dialogUrl, "", "width=580,height=625,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function submitCancel(){
    document.getElementById("cancelRxOrder").click();
}

//Rx Transfer Authenticated scripts

function clearVal()
  {
     if(document.getElementById('patientDateofBirth').value=="MM/DD/YYYY")
         document.getElementById('patientDateofBirth').value="";
     if(document.getElementById('patientphoneNumber').value=="000-000-0000")
          document.getElementById('patientphoneNumber').value="";
   }


    function addForm(s1)
        {               
           var cont=document.getElementById('general').innerHTML;
           var content=document.getElementById('add').innerHTML;
            var content1=document.getElementById('patientinfo').innerHTML;          
            if(s1=='addpatient'){                               
                document.getElementById('general').innerHTML=content;
            }
            else if(s1==''){            
                document.getElementById('general').innerHTML=cont;  
            }
            else {               
             document.getElementById('general').innerHTML=content1;
        }            
        } 
//Rx New Authenticated
 function addFormNew(s1)
        {                
           var cont=document.getElementById('general').innerHTML;  
           var content=document.getElementById('add').innerHTML;
            var content1=document.getElementById('patientinfo').innerHTML;          
            if(s1=='addpatient'){                
                document.getElementById('general').innerHTML=content;
            }
            else if(s1==''){            
                document.getElementById('general').innerHTML=cont;  
            }
            else{               
             document.getElementById('general').innerHTML=content1;
        }            
        }   
 function clearValuesOnSubmit()
{
if(document.getElementById('patientDateofBirth').value=="MM/DD/YYYY")
document.getElementById('patientDateofBirth').value="";
if(document.getElementById('patientphoneNumber').value=="000-000-0000")
document.getElementById('patientphoneNumber').value="";
}

//dialog_enter_ship_enter
function clearValShip()
                    {
                    if(document.getElementById('phoneNumber').value=="000-000-0000")
                    document.getElementById('phoneNumber').value="";
                    if(document.getElementById('nickName').value=="e.g., Work, Home")
                    document.getElementById('nickName').value="";
                    }


function defaultValue(){
                       if(document.add.nickName != null){
                          if(document.add.nickName.value=="")
                            document.add.nickName.value="e.g., Work, Home";
                         }
                        if(document.add.phoneNumber != null){
                         if(document.add.phoneNumber.value=="")
                           document.add.phoneNumber.value="000-000-0000";
                          }
                    }
                          
function showAddConfirmation(giftItemId,giftlistId,returnToShopping) {
	if ((giftlistId != null) && (giftlistId != null)) {
		var dialogURL = "../../user/add_shopping_list_confirmation.jsp?giftItemId="+giftItemId+"&giftlistId="+giftlistId+"&returnToShopping="+returnToShopping;
  		if (window.showModalDialog) {
			var returnVal = window.showModalDialog(dialogURL,'Add to Shoppinglist','dialogWidth:672px;dialogHeight:498px;resizable:no;help:no;status:no;scroll:no');
			if (returnVal != null) {
				window.location.href = returnVal;
			}
		} else {
			var returnVal = window.open(dialogURL, "Add to Shoppinglist", "width=672,height=498,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
		}
	}
}
        
function onEnter(evt) {
            var keyCode = null;

            if( evt.which ) {
            keyCode = evt.which;
            } else if( evt.keyCode ) {
            keyCode = evt.keyCode;
            }
            if( 13 == keyCode ) {
                document.getElementById("commitButton").click();
                return false;
            }
            return true;
            }  
            
function printOrder()
        {   
          
            window.open ("print_storefront.jsp","PrintOrder","resizable=no,menubar=no,status=no,toolbar=no,width=705,height=580,scrollbars=yes");

        }      
        
function checkKey()
{
if ((event.keyCode < 48) || (event.keyCode > 57))
    {
        event.returnValue = false;
    }
}

 /* This function is called from shopping cart page to verify max quantity */ 
function checkQty(count,maxqnty){
    
    var userQnty=document.getElementById("sku"+count).value;
    if(maxqnty != null)
    {
        //UAT defect:100010 added condotion maxqnty > 0 for absorbing maxquantity set to -1
        if(maxqnty > 0 && userQnty>maxqnty)
            var div=document.getElementById("limit"+count).style.display="block";
        else
            document.getElementById("limit"+count).style.display="none";
    }
}
function hideImageDiv(divid,index,size){
	try
	{
			if (size == 100000)
			{
				size = 1000;
			}
		
			var totalcount=Number(index)+Number(size);

			if(divid=='show')
			{ 
				document.getElementById(divid).style.display ="none";
				document.getElementById('hide').style.display ="block";
				
					for(count=index;count<totalcount;count++)
					{
						if (document.getElementById("prod"+count)) {
							var elem=document.getElementById("prod"+count);        
							elem.style.display='block';
						} 
						
					}
				
			}else if(divid=='hide')
			{ 
				document.getElementById(divid).style.display ="none";
				document.getElementById('show').style.display ="block";
							
				for(count=index;count<totalcount;count++)
				{
					if (document.getElementById("prod"+count)) {
						var elem=document.getElementById("prod"+count);
						elem.style.display ='none';
					} 
				}
			} 
	}
	catch(e){}

} 

function hideDiv(divid,size){ 
    if(divid=='show'){ 
    if(document.getElementById(divid)==null)
    {
    }
    else
    {
        document.getElementById(divid).style.display ="block";
    }
    if(document.getElementById('hide')==null)
    {}
    else
    {
        document.getElementById('hide').style.display ="none";
    }
    if(document.getElementById('hideImage')==null)
    {}
    else
    {
        document.getElementById('hideImage').value='show';
    }

    for(count=1;count<=size;count++)
    {
        var elem=document.getElementById("ci"+count);
        if (elem != null)
             elem.style.display='block';
    }

    }else if(divid=='hide'){
        document.getElementById(divid).style.display ="block";
        document.getElementById('show').style.display ="none";
        document.getElementById('hideImage').value='hide';

        for(count=1;count<=size;count++)
        {
            var elem=document.getElementById("ci"+count);
            if (elem != null)
                elem.style.display ='none';
        }
    } 
}    

function nameWindow(){
    window.name="AddAddress";           
}

function pixel()
        {   
        var icstring =".ic-live.com/goat.php?cID=1460&cdid=4870&campID=8";
        var refVar = (document.referrer);
        var locURL = location.href;
        var locHttp = locURL.split(":")[0];
        
        if (!pageAction) { pageAction = 0; };
        if (!sale) { sale=""; }
        if (!price) { price=""; }
        if (!sku) { sku=""; }
        if (!order_code) { order_code=""; }
        if (!user_defined1) { user_defined1=""; }
        if (!user_defined2) { user_defined2=""; }
        if (!user_defined3) { user_defined3=""; }
        if (!user_defined4) { user_defined4=""; }
        if (!currency_id) { currency_id=""; }
        if (!ic_bu) { ic_bu=""; }
        if (!ic_bc) { ic_bc=""; }
        if (!ic_ch) { ic_ch=""; }
        if (!ic_nso) { ic_nso=""; }
        if (!ic_cat) { ic_cat=""; }
        if (!ic_type) { ic_type=""; }
        if (locHttp.toLowerCase( ) == "https")  { prefix="https://www"+icstring+"";}
        if (locHttp.toLowerCase( ) == "http")  { prefix="http://1460"+icstring+"";} 
        if (pageAction > 0) 
        {
            urlA = prefix+"&convID="+pageAction+"&sl="+sale+"&convP="+price+"&curID="+currency_id+"&ordID="+escape(order_code)+"&ud1="+escape(user_defined1)+"&ud2="+escape(user_defined2)+"&ud3="+escape(user_defined3)+"&ud4="+escape(user_defined4)+"&ic_cat="+escape(ic_cat)+"&ic_type="+escape(ic_type)+"&ic_bu="+escape(ic_bu)+"&ic_bc="+escape(ic_bc)+"&ic_ch="+escape(ic_ch)+"&ic_nso="+escape(ic_nso)+"&sku="+escape(sku)+"&refVar="+escape(refVar);
        }
        else
        {
            urlA = prefix+"&ic_cat="+escape(ic_cat)+"&ic_type="+escape(ic_type)+"&ic_bu="+escape(ic_bu)+"&ic_bc="+escape(ic_bc)+"&ic_ch="+escape(ic_ch)+"&ic_nso="+escape(ic_nso)+"&refVar="+escape(refVar);
        }
        
        io.src = urlA;
        }                                

function hideDivOnPageLoad(size){ 
    var imageValue=document.getElementById('hideImage').value;
    if (imageValue=="")
        hideDiv('show',1);
    else
        hideDiv(imageValue,size);
}

// clear the prescriber phone Number 

function goToBlankRxPhoneNumber(idField)
{  
if(idField.value == "000-000-0000")
        idField.value = "";
}

function clearDefaultValues()
{
	 if(document.enterLocationForm.nickName != null)
    {
        if (document.enterLocationForm.nickName.value == "e.g., Work,Home")
        {
            document.enterLocationForm.nickName.value = "";
        }
    }

    if(document.enterLocationForm.phoneNumber != null)
    {
        if(document.enterLocationForm.phoneNumber.value == "000-000-0000")
        {
            document.enterLocationForm.phoneNumber.value = "";
        }
    }
  
}