﻿// JScript File

//CommonScripts
    function RedirectPage(PageName)
    {
        location.href=PageName;
        return false;
    }
    
    function showhelp(strURL)
	{
		winStatus = window.open(strURL,'Help','menubar=no,toolbar=no,location=no,hotkeys=no,status=yes,copyhistory=no,width=450,height=230,scrollbars=no,top=120,left=145')
	}
	
    function StripBlanks(Source)
    {
 	    var newString;
	    var i;
	    var j;
	    var blank;
	    blank = " ";
	    newString = "";
	    if(Source == null) Source = " ";
	    aString = Source;	
	    for (i=0; i<aString.length; i++)
	    { 
		    if (aString.charAt(i) != blank && aString.charCodeAt(i)!= 13 && aString.charCodeAt(i) != 10 )
		    {
			    break;
		    }
	    }
	    for (j=aString.length-1; j>=0; j--)
	    {
		    if (aString.charAt(j) != blank   && aString.charCodeAt(j)!= 13 && aString.charCodeAt(j) != 10 )
		    {
				    break;
		    }
	    }
	    for(k=i;k<=j;k++)
	    {
		    newString += aString.charAt(k);
	    }	
	    return newString;	
    }
    
    function OpenPopUpWindow_1(strURL)
	{
		winStatus = window.open(strURL,'PopUp','menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=600,height=410,scrollbars=no,top=150,left=165');
		return false;
	}
	function OpenPopUpWindow_2(strURL)
	{
		winStatus = window.open(strURL,'PopUp','menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=600,height=410,scrollbars=no,top=150,left=165');		
	}
	function OpenPopUpWindow_3(strURL)
	{
		winStatus = window.open(strURL,'PopUp','menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=700,height=500,scrollbars=yes,top=150,left=165');		
	}
	
	function OpenFullImage(strURL)
	{
	    winStatus = window.open(strURL,'PopUp','menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=700,height=500,scrollbars=yes,top=150,left=165');		
	    return false;
	}    
	
	
	function AddToFavourites(strURL,strPageName)
	{
	    var URLFormat_1=/http:/;
	    var URLFormat_2=/https:/;
	    if (!URLFormat_1.test(strURL) && !URLFormat_2.test(strURL)) 
        {
            alert("The gift page link '" + strURL + "' is not a valid link.");
        }
        else
        {
            if (window.sidebar) 
            { 
                window.sidebar.addPanel(strPageName, strURL,""); 
            } 
            else if(window.external) 
            { 
                window.external.AddFavorite(strURL,strPageName);
            } 

	    }
	}
	
	function SetAsHome(strURL)
	{
	    if (window.sidebar) 
        { 
            alert("This feature is no longer permitted in this browser.\n To make this page your home page, just drag the icon to the left of the URL in your location bar onto the 'Home' icon in the toolbar.")
        }
         else if(window.external) 
        {
            document.body.style.behavior='url(#default#homepage)';
            document.body.setHomePage(strURL);
        }    
	}
	
    function isempty(strToCheck)
    {
	    var bStringEmpty = true;
	    //getting the length of the string
	    var nLength = strToCheck.length
	    //checking the length of the contents of the text box
	    if(nLength > 0)
	    {
    		
		    for(i=0;i<nLength;i++)
		    {
			    if (strToCheck.charAt(i) != " " && strToCheck.charAt(i) != "\t" && strToCheck.charCodeAt(i) != 13 && strToCheck.charCodeAt(i) != 10 )
			    {
				    bStringEmpty = false;
				    break;
			    }
		    }
	    }
	    return bStringEmpty;
    }
    
    function AmountCheck(Field)
    {
	    var strTmp = Field.value;  	
	    var intBlankOccurance = 0;
	    var intHypenOccurance = 0;
	    var strAlertMsg;
	    var valid = "1234567890." ;
	    var temp;
    	
	    for (var i=0; i<strTmp.length; i++)
	    {
		    temp = ""+ strTmp.substring(i, i+1);
    				
		    if (valid.indexOf(temp) == -1) 
		    {
			    return false;
			    break;
		    }
	    }
		    return true;   	
    }
   	
    function ValidateMaxLength(source,intLength,strSourceName)
    {
	    if (source.value.length > intLength)
	    {
    	
		    alert("Please enter only " + intLength + " characters in " + strSourceName + "." );
		    source.focus();	
		    source.select();
		    return false;
	    }
	    else
	    {
		    return true;
	    }	
    }	
    
   //Scripts for GiftshareLogin.aspx
    
    function GiftshareLoginValidate()
    {
        var EmailFormat  = /^([a-zA-Z0-9_\.\-'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
         
        if (document.frmLogin.txtEmailAddress.value == "")
        {
            alert("Please enter the Email Address.")
            document.frmLogin.txtEmailAddress.focus();
            return false;
        }
        if (!EmailFormat.test(document.frmLogin.txtEmailAddress.value))
        {
            alert("Please enter a valid Email Address.")
            document.frmLogin.txtEmailAddress.focus();
            return false;
        }
        if(document.frmLogin.txtPassword.value=="")    
        {
            alert("Please enter the Password.")
            document.frmLogin.txtPassword.focus();
            return false;
        }
    
    }
    
    //Scripts for ConfirmIdentity.aspx
    
    function ConfirmIdentityValidate()
    {
        var EmailFormat  = /^([a-zA-Z0-9_\.\-'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (document.frmConfirmIdentity.txtContributerEmailAddress.value=="")
        {
            alert("Please enter the Visitor Email Address.");
            document.frmConfirmIdentity.txtContributerEmailAddress.focus();
            return false;
        }
        if (!EmailFormat.test(document.frmConfirmIdentity.txtContributerEmailAddress.value))
        {
            alert("Please enter a valid Email Address.")
            document.frmConfirmIdentity.txtContributerEmailAddress.focus();
            return false;
        }       
        if (document.frmConfirmIdentity.txtMessage.value=="")
        {
            alert("Please enter the Message.");
            document.frmConfirmIdentity.txtMessage.focus();
            return false;
        }
    }
    
    //Scripts for EditPersonalGiftPage.aspx
    
    function PersonalGiftPageValidate(ValidateDate)
    {
        var NumberFormat = "0123456789";

        if (document.frmEditPersonalGiftPage.txtURL.value=="")
        {
            alert("Please enter the Gift Page Link.");
            document.frmEditPersonalGiftPage.txtURL.focus();
            return false;
        }
        if (SpecialCharactersValidation(document.frmEditPersonalGiftPage.txtURL)!= true)
        {
            return false;
        }
        if (document.frmEditPersonalGiftPage.txtPageTitle.value=="")
        {
            alert("Please enter the Gift Page Title.");
            document.frmEditPersonalGiftPage.txtPageTitle.focus();
            return false;
        }
        if(isempty(tinyMCE.getContent(tinyMCE.getWindowArg('txtTextEditor'))))
	    {
		    alert("Please enter the Personal Message.");
		    return false;
	    }
	    document.frmEditPersonalGiftPage.hdnPersonalMessage.value = tinyMCE.getContent(tinyMCE.getWindowArg('txtTextEditor'));
	    
        if (document.frmEditPersonalGiftPage.txtTargetAmount.value=="")
        {
            alert("Please enter the Target Amount.");
            document.frmEditPersonalGiftPage.txtTargetAmount.focus();
            return false;
        }
        if (!AmountCheck(document.frmEditPersonalGiftPage.txtTargetAmount))
        {
            alert("Please enter only numbers in the Target Amount.");
            document.frmEditPersonalGiftPage.txtTargetAmount.focus();
            return false;
        }
        if (document.frmEditPersonalGiftPage.txtTargetAmount.value==0)
        {
            alert("Target Amount should be greater than zero.");
            document.frmEditPersonalGiftPage.txtTargetAmount.focus();
            return false;
        }
    }
        
    function NumberValidation(Field)
    {
	    var strTmp = Field.value;
    	
	    var valid = "0123456789";
	    var ok = "yes";
	    var temp;
	    for (var i=0; i<strTmp.length; i++)
	    {
		    temp = ""+ strTmp.substring(i, i+1);
    				
		    if (valid.indexOf(temp) == -1) 
		    {
			    ok = "no";
			    break;
		    }
	    }
	    if (ok == "no")
	    {  
		    return false;
	    }	
	    return true;
    }
    
    function SpecialCharactersValidation(Field)
    {
	    var strTmp = Field.value;
	    var valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	    var ok = "yes";
	    var temp;
	    for (var i=0; i<strTmp.length; i++)
	    {
		    temp = ""+ strTmp.substring(i, i+1);
    				
		    if (valid.indexOf(temp) == -1) 
		    {
			    ok = "no";
			    break;
		    }
	    }
	    if (ok == "no")
	    {  
		    alert("Please enter only alphabetic characters and numbers without any space in Gift Page Link.");
		    Field.focus();	
		    return false;
	    }	
	    return true;
    }

     function CurrentDateValidation(objFromDate,strSourceName)
        {
            var intFromMonth = objFromDate.value.substr(3,2)
            if( intFromMonth <= "09" )
	            intFromMonth = parseInt(intFromMonth.substr(1,1)) - 1
            else
	            intFromMonth = parseInt(intFromMonth) - 1
            
            var FromDate = new Date( objFromDate.value.substr(6,4), intFromMonth , objFromDate.value.substr(0,2) );
        	
            var CurrentDate  = new Date();							
            var strDate = CurrentDate.getDate();
            var strMonth = CurrentDate.getMonth();
            var strYear = CurrentDate.getYear();

            var CurrentDate = new Date( strYear,strMonth ,strDate,"00","00","00" );
            if( CurrentDate > FromDate )
            {
	            alert("Please select valid date range. The " + strSourceName + " Date cannot be earlier than the Current Date.");
	            return false;
            }
        }
    
    
    //Scripts for Registration.aspx
    
    function RegistrationValidate()
    {
        var EmailFormat  = /^([a-zA-Z0-9_\.\-'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
         
        if(document.frmRegistration.txtFirstName.value=="")    
        {
            alert("Please enter your First Name.")
            document.frmRegistration.txtFirstName.focus();
            return false;
        }
        if(document.frmRegistration.txtLastName.value=="")    
        {
            alert("Please enter your Last Name.")
            document.frmRegistration.txtLastName.focus();
            return false;
        }
        if (document.frmRegistration.txtEmailAddress.value == "")
        {
            alert("Please enter the Email Address.")
            document.frmRegistration.txtEmailAddress.focus();
            return false;
        }
        if (!EmailFormat.test(document.frmRegistration.txtEmailAddress.value))
        {
            alert("Please enter a valid Email Address.")
            document.frmRegistration.txtEmailAddress.focus();
            return false;
        }
        if (document.frmRegistration.txtConfirmEmailAddress.value == "")
        {
            alert("Please confirm the Email Address.")
            document.frmRegistration.txtConfirmEmailAddress.focus();
            return false;
        }
        if(document.frmRegistration.txtEmailAddress.value.toLowerCase() != document.frmRegistration.txtConfirmEmailAddress.value.toLowerCase())
	    {
	        alert("The email addresses that you have entered do not match. Please try again.");
	        document.frmRegistration.txtConfirmEmailAddress.focus();
	        return false;	    
	    }
        if(document.frmRegistration.txtPassword.value=="")    
        {
            alert("Please enter the Password.")
            document.frmRegistration.txtPassword.focus();
            return false;
        }
        if(document.frmRegistration.txtConfirmPassword.value=="")    
        {
            alert("Please confirm your Password.")
            document.frmRegistration.txtConfirmPassword.focus();
            return false;
        }
        if(document.frmRegistration.txtPassword.value != document.frmRegistration.txtConfirmPassword.value)
	    {
	        alert("The passwords that you entered do not match. Please try again.");
	        document.frmRegistration.txtConfirmPassword.focus();
	        return false;	    
	    }
	    if(document.frmRegistration.txtAddressLine1.value=="")    
        {
            alert("Please enter the Address 1.")
            document.frmRegistration.txtAddressLine1.focus();
            return false;
        }

        if(document.frmRegistration.txtPostalTown.value=="")    
        {
            alert("Please enter the Postal Town.")
            document.frmRegistration.txtPostalTown.focus();
            return false;
        }
        if(document.frmRegistration.txtPostalCode.value=="")    
        {
            alert("Please enter the Postal Code / ZIP.")
            document.frmRegistration.txtPostalCode.focus();
            return false;
        }
         if(document.frmRegistration.drpCountry.value == 0)
	    {
		    alert("Please select a Country");
		    document.frmRegistration.drpCountry.focus();
		    return false;
	    }
	    if(document.frmRegistration.chkTerms.checked == false)
	    {
		    alert("Please accept the Terms and Conditions.");
		    document.frmRegistration.chkTerms.focus();
		    return false;
	    } 
	           
    return true;
    }
    
    //Scripts for MyAccount.aspx
    
    function MyAccountValidate()
    {
        var EmailFormat  = /^([a-zA-Z0-9_\.\-'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
         
        if(document.frmMyaccount.drpTitle.value == "")
	    {
		    alert("Please select a Title");
		    document.frmMyaccount.drpTitle.focus();
		    return false;
	    }
        if(document.frmMyaccount.txtFirstName.value=="")    
        {
            alert("Please enter your First Name.")
            document.frmRegistration.txtFirstName.focus();
            return false;
        }
        if(document.frmMyaccount.txtLastName.value=="")    
        {
            alert("Please enter your Last Name.")
            document.frmRegistration.txtLastName.focus();
            return false;
        }
        if (document.frmMyaccount.txtEmailAddress.value == "")
        {
            alert("Please enter the Email Address.")
            document.frmRegistration.txtEmailAddress.focus();
            return false;
        }
        if (!EmailFormat.test(document.frmMyaccount.txtEmailAddress.value))
        {
            alert("Please enter a valid Email Address.")
            document.frmMyaccount.txtEmailAddress.focus();
            return false;
        }
        if(document.frmMyaccount.chkPassword.checked)
        {
            if(document.frmMyaccount.txtPassword.value=="")    
            {
                alert("Please enter the Password.")
                document.frmMyaccount.txtPassword.focus();
                return false;
            }
            if(document.frmMyaccount.txtConfirmPassword.value=="")    
            {
                alert("Please Confirm your Password.")
                document.frmMyaccount.txtConfirmPassword.focus();
                return false;
            }
            if(document.frmMyaccount.txtPassword.value != document.frmMyaccount.txtConfirmPassword.value)
	        {
	            alert("The passwords that you entered do not match. Please try again.");
	            document.frmMyaccount.txtConfirmPassword.focus();
	            return false;	    
	        }
        }
        
	    if(document.frmMyaccount.txtAddressLine1.value=="")    
        {
            alert("Please enter the Address 1.")
            document.frmMyaccount.txtAddressLine1.focus();
            return false;
        }
        if(document.frmMyaccount.txtPostalTown.value=="")    
        {
            alert("Please enter the Postal Town.")
            document.frmMyaccount.txtPostalTown.focus();
            return false;
        }
        if(document.frmMyaccount.txtPostalCode.value=="")    
        {
            alert("Please enter the Postal Code / ZIP.")
            document.frmMyaccount.txtPostalCode.focus();
            return false;
        }
         if(document.frmMyaccount.drpCountry.value == 0)
	    {
		    alert("Please select a Country");
		    document.frmMyaccount.drpCountry.focus();
		    return false;
	    }        
    return true;
    }
    
    
    //Scripts for GiftListings.aspx
    function GiftListingValidate()
    {
        if(document.frmGiftListing.ddlSearchBy.selectedIndex == 1)
        {
            if(document.frmGiftListing.txtSupplierName.value=="")    
            {
	            alert("Please enter the Supplier Name.");
	            document.frmGiftListing.txtSupplierName.focus();
	            return false;
	        }
	       else
	      {
	      //record it
	      urchinTracker('/SEARCH/SUPPLIER/' + document.frmGiftListing.txtSupplierName.value);
	      }  
        }
        if(document.frmGiftListing.ddlSearchBy.selectedIndex == 2)
        {
            if(document.frmGiftListing.txtKeyword.value=="")    
            {
	            alert("Please enter the Keyword.");
	            document.frmGiftListing.txtKeyword.focus();
	            return false;
	        }
	       else
	      {
	      //record it
	      urchinTracker('/SEARCH/KEYWORD/' + document.frmGiftListing.txtKeyword.value);
	      }   
        }
    }
    
    //Scripts for MakeContribution.aspx
    var intCount=0;
    function StatusBar()
    {
	    intCount++;
	    var dots=""
	    for(var i=1;i<=intCount;i++)
	    {
		    dots+=". "
	    }
	    
	     if (window.sidebar) 
        { 
            document.getElementById("Message").textContent="Please do not close this page or click on the browser Back, Stop or Refresh buttons while your payment is being processed. Once the process is successfully completed you will receive a confirmation message.";
            document.getElementById("Bar").textContent=dots
        } 
        else if(window.external) 
        { 
	        document.all("Message").innerText="Please do not close this page or click on the browser Back, Stop or Refresh buttons while your payment is being processed. Once the process is successfully completed you will receive a confirmation message.";
	        document.all("Bar").innerText=dots
        } 
        
	    if(intCount==5)
	    intCount=0;
    }

    var interval="";
    function CallTimer()
    {
	    interval=window.setInterval("StatusBar()",100);
    }
    
    function ContributionValidate()
    {
        var EmailFormat  = /^([a-zA-Z0-9_\.\-'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        
        if(document.frmContribution.txtFirstName.value=="")    
        {
            alert("Please enter your First Name.")
            document.frmContribution.txtFirstName.focus();
            return false;
        }
        if(document.frmContribution.txtLastName.value=="")    
        {
            alert("Please enter your Last Name.")
            document.frmContribution.txtLastName.focus();
            return false;
        }
        if (document.frmContribution.txtEmailAddress.value == "")
        {
            alert("Please enter the Email Address.")
            document.frmContribution.txtEmailAddress.focus();
            return false;
        }
        if (!EmailFormat.test(document.frmContribution.txtEmailAddress.value))
        {
            alert("Please enter a valid Email Address.")
            document.frmContribution.txtEmailAddress.focus();
            return false;
        }
	    if(document.frmContribution.txtAddressLine1.value=="")    
        {
            alert("Please enter the Address 1.")
            document.frmContribution.txtAddressLine1.focus();
            return false;
        }
        if(document.frmContribution.txtPostalTown.value=="")    
        {
            alert("Please enter the Postal Town.")
            document.frmContribution.txtPostalTown.focus();
            return false;
        }
        if(document.frmContribution.txtPostalCode.value=="")    
        {
            alert("Please enter the Postal Code.")
            document.frmContribution.txtPostalCode.focus();
            return false;
        }  
       
       //start amount validation       
        if(document.frmContribution.txtAmount.value=="")    
        {
            alert("Please enter the Amount.")
            document.frmContribution.txtAmount.focus();
            return false;
        } 
        		 
            if(!isempty(document.frmContribution.txtAmount.value))
        {
            if(isNaN(document.frmContribution.txtAmount.value))
            {
                alert("Please enter only numbers in Amount.")
                document.frmContribution.txtAmount.focus();
                return false;
            }
            if(document.frmContribution.txtAmount.value==0)
            {
                alert("Amount should be greater than zero.")
                document.frmContribution.txtAmount.focus();
                return false;            
            }
            if(!AmountCheck(document.frmContribution.txtAmount))
		    {
			    alert("Please enter only numbers in Amount.");
			    document.frmContribution.txtAmount.focus();
			    return false;
    		}            
        }        
        
        if(document.frmContribution.txtMessage.value!="") 
        {
            if (ValidateMaxLength(document.frmContribution.txtMessage,500,'Message') == false)
		    {		
			    return false;
		    }
        }
        if(document.frmContribution.drpCardType.value == "")
	    {
		    alert("Please select a Card Type");
		    document.frmContribution.drpCardType.focus();
		    return false;
	    }                       
        if (document.frmContribution.txtCardNumber.value == "")
        {
            alert("Please enter the Credit Card Number.")
            document.frmContribution.txtCardNumber.focus();
            return false;
        }        
        if(!isempty(document.frmContribution.txtCardNumber.value))
        {
            if(isNaN(document.frmContribution.txtCardNumber.value) || document.frmContribution.txtCardNumber.value==0)
            {
                alert("Please enter only numbers in Card Number.")
                document.frmContribution.txtCardNumber.focus();
                return false;
            }
            if(!NumberValidation(document.frmContribution.txtCardNumber))
		    {
			    alert("Please enter only numbers in Card Number");
			    document.frmContribution.txtCardNumber.focus();
			    return false;
		    }            
        }     
	    if(document.frmContribution.txtCVVNumber.value=="")    
        {
            alert("Please enter the CVV Number.")
            document.frmContribution.txtCVVNumber.focus();
            return false;
        }
        if(!isempty(document.frmContribution.txtCVVNumber.value))
        {
            if(isNaN(document.frmContribution.txtCVVNumber.value) || document.frmContribution.txtCVVNumber.value==0)
            {
                alert("Please enter only numbers in CVV Number.")
                document.frmContribution.txtCVVNumber.focus();
                return false;
            }
            if(!NumberValidation(document.frmContribution.txtCVVNumber))
		    {
			    alert("Please enter only numbers in CVV Number.");
			    document.frmContribution.txtCVVNumber.focus();
			    return false;
		    }            
        }       
        if(document.frmContribution.drpExpiresMM.value == "")
        {
            alert("Please select the Expiry Month.")
            document.frmContribution.drpExpiresMM.focus();
            return false;        
        }    
        if(document.frmContribution.drpExpiresYYYY.value == "")
        {
            alert("Please select the Expiry Year.")
            document.frmContribution.drpExpiresYYYY.focus();
            return false;        
        }   
        if((document.frmContribution.drpValidFrMM.value > document.frmContribution.drpExpiresMM.value) && (document.frmContribution.drpValidFrYYYY.value == document.frmContribution.drpExpiresYYYY.value))
        {
            alert("Valid from date should be lesser then expiry date.")
            document.frmContribution.drpValidFrMM.focus();
            return false;                
        }   
        if(document.frmContribution.chkTermsAndConditions.checked == false)
        {
            alert("Please accept the Terms and Conditions.")
            document.frmContribution.chkTermsAndConditions.focus();
            return false
        }
    	document.getElementById('loadingmessage').style.display='block';       
    	
	   if (window.sidebar) 
        { 
        } 
        else if(window.external) 
        { 
	      document.getElementById('divSubmit').style.display='none';    
        } 
        
    CallTimer();
    return true;
    }    
    
    //Scripts for PaymentGateway.aspx
        
    function PaymentValidate()
    {
        if(document.frmPaymentGateway.drpTitle.value == "")
	    {
		    alert("Please select a Title");
		    document.frmPaymentGateway.drpTitle.focus();
		    return false;
	    }                  
        if(document.frmPaymentGateway.txtFirstName.value=="")    
        {
            alert("Please enter your First Name.")
            document.frmPaymentGateway.txtFirstName.focus();
            return false;
        }
        if(document.frmPaymentGateway.txtLastName.value=="")    
        {
            alert("Please enter your Last Name.")
            document.frmPaymentGateway.txtLastName.focus();
            return false;
        }
        if(document.frmPaymentGateway.drpCardType.value == "")
	    {
		    alert("Please select a Card Type");
		    document.frmPaymentGateway.drpCardType.focus();
		    return false;
	    }                       
        if (document.frmPaymentGateway.txtCardNumber.value == "")
        {
            alert("Please enter the Credit Card Number.")
            document.frmPaymentGateway.txtCardNumber.focus();
            return false;
        }
        if(!isempty(document.frmPaymentGateway.txtCardNumber.value))
        {
            if(isNaN(document.frmPaymentGateway.txtCardNumber.value) || document.frmPaymentGateway.txtCardNumber.value==0)
            {
                alert("Please enter the valid Card Number.")
                document.frmPaymentGateway.txtCardNumber.focus();
                return false;
            }
            if(!AmountCheck(document.frmPaymentGateway.txtCardNumber))
		    {
			    alert("Please enter the valid Card Number.");
			    document.frmPaymentGateway.txtCardNumber.focus();
			    return false;
		    }            
        }        
	    if(document.frmPaymentGateway.txtCVVNumber.value=="")    
        {
            alert("Please enter the CVV Number.")
            document.frmPaymentGateway.txtCVVNumber.focus();
            return false;
        }
        if(!isempty(document.frmPaymentGateway.txtCVVNumber.value))
        {
            if(isNaN(document.frmPaymentGateway.txtCVVNumber.value) || document.frmPaymentGateway.txtCVVNumber.value==0)
            {
                alert("Please enter the valid CVV Number.")
                document.frmPaymentGateway.txtCVVNumber.focus();
                return false;
            }
            if(!AmountCheck(document.frmPaymentGateway.txtCVVNumber))
		    {
			    alert("Please enter the valid Card Number.");
			    document.frmPaymentGateway.txtCVVNumber.focus();
			    return false;
		    }            
        }            
        if(document.frmPaymentGateway.drpValidFrMM.value == "")
        {
		    alert("Please select the valid from Month.");
		    document.frmPaymentGateway.drpValidFrMM.focus();
		    return false;
        }
        if(isempty(document.frmPaymentGateway.drpValidFrYYYY.value))
        {
		    alert("Please select the valid from Year.");
		    document.frmPaymentGateway.drpValidFrYYYY.focus();
		    return false;
        }                
        if(document.frmPaymentGateway.drpExpiresMM.value == "")
        {
            alert("Please select the Expiry Month.")
            document.frmPaymentGateway.drpExpiresMM.focus();
            return false;        
        }    
        if(document.frmPaymentGateway.drpExpiresYYYY.value == "")
        {
            alert("Please select the Expiry Year.")
            document.frmPaymentGateway.drpExpiresYYYY.focus();
            return false;        
        }   
        if((document.frmPaymentGateway.drpValidFrMM.value > document.frmPaymentGateway.drpExpiresMM.value) && (document.frmPaymentGateway.drpValidFrYYYY.value == document.frmPaymentGateway.drpExpiresYYYY.value))
        {
            alert("Valid from date should be lesser then expiry date.")
            document.frmPaymentGateway.drpValidFrMM.focus();
            return false;                
        }
    return true;
    }   
        
    
     //Scripts for GiftPageSearch.aspx
    function GiftPageSearchValidate()
    {
        if(document.frmGiftPageSearch.ddlSearchBy.selectedIndex == 0)
        {
            if(document.frmGiftPageSearch.txtEmailAddress.value=="")    
            {
	            alert("Please enter the Email Address.");
	            document.frmGiftPageSearch.txtEmailAddress.focus();
	            return false;
	        }
        }
        if(document.frmGiftPageSearch.ddlSearchBy.selectedIndex == 1)
        {
            if(document.frmGiftPageSearch.txtGiftpage.value=="")    
            {
	            alert("Please enter the Gift Page Title.");
	            document.frmGiftPageSearch.txtGiftpage.focus();
	            return false;
	        }
        }
        if(document.frmGiftPageSearch.ddlSearchBy.selectedIndex == 2)
        {
            if(document.frmGiftPageSearch.txtSurname.value=="")    
            {
	            alert("Please enter the Surname.");
	            document.frmGiftPageSearch.txtSurname.focus();
	            return false;
	        }
        }
    }

    // Scripts for GiftsharerAdmin.aspx
    function OpenAccountHistory(strURL)
	{
		winStatus = window.open(strURL,'AccountHistory','menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=850,height=550,scrollbars=yes,top=100,left=75')
		return false;
	}
	function CloseAccount(strURL)
	{
	    if(document.frmGiftsharerAdmin.hdnCloseAccountFlag.value == 1)
		{
		    if(confirm("Are you sure you want to close your account?\nIf you click 'OK', Giftshare will close your account and confirm this to you by email."))
		    {
		        //winStatus = window.open(strURL,'AccountHistory','menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=600,height=350,scrollbars=yes,top=250,left=200')		    
		        document.frmGiftsharerAdmin.hdnCloseAccount.value = 1;		    
		    }
		    else
		    {
		        document.frmGiftsharerAdmin.hdnCloseAccount.value = 0;
		        return false;
		    }
		}
		else
		    {
		        document.frmGiftsharerAdmin.hdnCloseAccount.value = 0;		       
		    }	
		 
	}
	

// Calender Scripts
    var oldLink = null;
    function setActiveStyleSheet(link, title) 
    {
      var i, a, main;
      for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
          a.disabled = true;
          if(a.getAttribute("title") == title) a.disabled = false;
        }
      }
      
    }
    function selected(cal, date) 
    {
      cal.sel.value = date; 
      if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
        cal.callCloseHandler();
    }
    
    function closeHandler(cal) {
       cal.hide();                     
      _dynarch_popupCalendar = null;
    }
    
    function showCalendar(id, showsTime, showsOtherMonths) 
    {
      var format = "%d/%m/%Y";
      var el = document.getElementById(id);
      
      if (_dynarch_popupCalendar != null) {
        _dynarch_popupCalendar.hide(); 
      } else {

        var cal = new Calendar(1, null, selected, closeHandler);
       
        if (typeof showsTime == "string") {
               
          cal.showsTime = true;
          cal.time24 = (showsTime == "24");
        }
        if (showsOtherMonths) {
          cal.showsOtherMonths = true;
        }
        _dynarch_popupCalendar = cal; 
        cal.setRange(1900, 2070);
        cal.create();
      }
      _dynarch_popupCalendar.setDateFormat(format); 
      _dynarch_popupCalendar.parseDate(el.value);
      _dynarch_popupCalendar.sel = el; 
      _dynarch_popupCalendar.showAtElement(el, "Br"); 
      return false;
    }
    
    var MINUTE = 60 * 1000;
    var HOUR = 60 * MINUTE;
    var DAY = 24 * HOUR;
    var WEEK = 7 * DAY;

    function isDisabled(date) 
    {
      var today = new Date();
      return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
    }

    function flatSelected(cal, date) 
    {
      var el = document.getElementById("preview");
      el.innerHTML = date;
    }

    function showFlatCalendar() 
    {
    
      var parent = document.getElementById("display");
      var cal = new Calendar(0, null, flatSelected);
      cal.weekNumbers = false;
      cal.setDisabledHandler(isDisabled);
      cal.setDateFormat("%A, %B %e");
      cal.create(parent);
      cal.show();
    }
    
//End of Calendar Scripts


//Scripts for SearchSupplier.aspx
    function SearchSupplierValidate()
    {
        if(document.frmSearchSupplier.ddlSearchBy.selectedIndex == 1)
        {
            if(document.frmSearchSupplier.txtSupplierName.value=="")    
            {
	            alert("Please enter the Supplier Name.");
	            document.frmSearchSupplier.txtSupplierName.focus();
	            return false;
	        }
        }
        if(document.frmSearchSupplier.ddlSearchBy.selectedIndex == 2)
        {
            if(document.frmSearchSupplier.txtKeyword.value=="")    
            {
	            alert("Please enter the Keyword.");
	            document.frmSearchSupplier.txtKeyword.focus();
	            return false;
	        }
        }        
    }
    
     function SearchSupplierSubmitValidate(strbalance)
    {    
            
             var fltbalance = parseFloat(strbalance);
            var fltprice = parseFloat(document.frmSearchSupplier.txtPrice.value);
            if(document.frmSearchSupplier.hdnSupplierID.value=="")    
            {
	            alert("Please select any one of the suppliers.");
	            //document.frmSearchSupplier.txtSupplierName.focus();
	            return false;
	        }
	        
	        if(document.frmSearchSupplier.txtDescription.value=="")    
            {
	            alert("Please enter the Item Description.");
	            document.frmSearchSupplier.txtDescription.focus();
	            return false;
	        }
	        if(document.frmSearchSupplier.txtPrice.value=="")    
            {
	            alert("Please enter the Price.");
	            document.frmSearchSupplier.txtPrice.focus();
	            return false;
	        }
	        
	         if (isNaN(document.frmSearchSupplier.txtPrice.value) || document.frmSearchSupplier.txtPrice.value==0)
            {
                alert("Please enter a valid Price.");
                document.frmSearchSupplier.txtPrice.focus();
                return false;
            }
            
            if(!AmountCheck(document.frmSearchSupplier.txtPrice))
		    {
			    alert("Please enter a valid Price.");
			    document.frmSearchSupplier.txtPrice.focus();
			    return false;
    		} 
    		if(fltprice < 100.00)
    		{
    		    alert("Please note only Gifts with a value of £100.00 or more may be purchased through Giftshare.");
	            document.frmSearchSupplier.txtPrice.focus();
	            return false;
    		}     
	        if(fltbalance < fltprice)
	        {
	            alert("Please enter a Price which is lower than the Balance Amount.");
	            document.frmSearchSupplier.txtPrice.focus();
	            return false;
	        }
    }
    
    
 //Scripts for RecommendSupplier.aspx   
      function SearchRecommendSupplierValidate(strbalance)
    {    
            var fltbalance = parseFloat(strbalance);
            var fltprice = parseFloat(document.frmRecommendSupplier.txtPrice.value);
            
            if(document.frmRecommendSupplier.txtSupplierName.value=="")    
            {
	            alert("Please enter the Supplier Name.");
	            document.frmRecommendSupplier.txtSupplierName.focus();
	            return false;
	        }
	        
	        if(document.frmRecommendSupplier.txtDescription.value=="")    
            {
	            alert("Please enter the Item Description.");
	            document.frmRecommendSupplier.txtDescription.focus();
	            return false;
	        }
	        if(document.frmRecommendSupplier.txtPrice.value=="")    
            {
	            alert("Please enter the Price.");
	            document.frmRecommendSupplier.txtPrice.focus();
	            return false;
	        }
	        if (isNaN(document.frmRecommendSupplier.txtPrice.value) || document.frmRecommendSupplier.txtPrice.value==0)
            {
                alert("Please enter a valid Price.");
                document.frmRecommendSupplier.txtPrice.focus();
                return false;
            }
            if(!AmountCheck(document.frmRecommendSupplier.txtPrice))
		    {
			    alert("Please enter a valid Price.");
			    document.frmRecommendSupplier.txtPrice.focus();
			    return false;
    		}
    		if(fltprice < 100.00)
	        {
	            alert("Please note only Gifts with a value of £100.00 or more may be purchased through Giftshare.");
	            document.frmRecommendSupplier.txtPrice.focus();
	            return false;
	        }   
	        if(fltbalance < fltprice)
	        {
	            alert("Please enter a Price which is lower than the Balance Amount.");
	            document.frmRecommendSupplier.txtPrice.focus();
	            return false;
	        }
    }
    
     //Scripts for ForgotPassword.aspx   
    function Validate()
    {
        var EmailFormat  = /^([a-zA-Z0-9_\.\-'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if(document.frmForgotPassword.txtEmailAddress.value=="")    
            {
	            alert("Please enter the Email Address.");
	            document.frmForgotPassword.txtEmailAddress.focus();
	            return false;
	        }
	    if (!EmailFormat.test(document.frmForgotPassword.txtEmailAddress.value))
        {
            alert("Please enter a valid Email Address.")
            document.frmForgotPassword.txtEmailAddress.focus();
            return false;
        }
	        
        
    } 
    //Scripts for GiftSharerEmailURL.aspx
    function ValidateGiftSharerEmailURL()
    {        
        if(document.frmEmailURL.lstEmailList.length == 0)    
            {
	            alert("Please Add the Email Address.");
	            document.frmEmailURL.lstEmailList.focus();
	            return false;
	        }
	 
         var ListLength = document.frmEmailURL.lstEmailList.length;
         if (ListLength > 0)
         {
            for (i=0;i<ListLength;i++)
            {
                if (document.frmEmailURL.hdnEmail.value=="")
                {
                    document.frmEmailURL.hdnEmail.value = document.frmEmailURL.lstEmailList.options[i].value;
                }
                else
                {
                    document.frmEmailURL.hdnEmail.value = document.frmEmailURL.hdnEmail.value + "," + document.frmEmailURL.lstEmailList.options[i].value;
                }                
            }
         }	        
	}  
	
	// email list signup
	
	
	function alertContents() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            result = http_request.responseText;
            alert("Thank you, we have added you to the list");
        } else {
            alert("sorry, but there has been a problem adding you to the list");
        }
    }
}

function makePOSTRequest(url, parameters) {
    http_request = false;
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest;
    } else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
            }
        }
    }
    if (!http_request) {
        alert("Your browser does not support AJAX, so we cannot complete this request.");
        return false;
    }
    http_request.onreadystatechange = alertContents;
    http_request.open("POST", url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.send(parameters);
}

	   function makeMailingListCall() {
	  
            var targetElementEmail = document.getElementById("Email");
             makePOSTRequest("https://www.giftshare.com/poster.asp", "Email=" + targetElementEmail.value);
             targetElementEmail.value = '';      
}



