﻿/*
*******************************Xpanxion changes*****************************                   
*   Purpose: This file will contain all the client side validation functions
*	WHO Date	    Description
*	--- ----------  --------------------------------------------------------------------
*   MVN 2006.07.07  File created
**************************************************************************
*/

/*Put this function in to common.js*/
function hidestatus(){
window.status='Done';
return true
}

function IsNumeric(strString)
{
    var strValidChars = "0123456789.";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
    {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
            {
                blnResult = false;
            }
     }
    return blnResult;
}
   
function IsAlphaNumeric(strString)
{
    var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
    {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
            {
                blnResult = false;
            }
     }
    return blnResult;
}

function ValidateQty(sender, args)
{
    var sValue = args.Value;       
    if (isNaN(sValue) || sValue <= 0 || (sValue.indexOf('.') != -1))
    {
        args.IsValid = false;
        return;
    }
    args.IsValid = true;
}

function ValidateUSZip(sender, args)
{
    var sValue = args.Value;            
    if (!IsNumeric(sValue))
    {
        args.IsValid = false;
        return;
    }
    if (sValue.length != 5)
    {
        args.IsValid = false;
        return;
    } 
    args.IsValid = true;
}

function ValidateCanadaZip(sender, args)
{
    var sValue = args.Value;        
    if (sValue.length != 6)
    {
        args.IsValid = false;
        return;
    }
   
    if (IsNumeric(sValue))
    {
        args.IsValid = false;
        return;
    }
    
    if (!IsAlphaNumeric(sValue))
    {
        args.IsValid = false;
        return;
    }
    args.IsValid = true;
  
}

function ValidateUSCanadaZip(sender, args)
{
    var sValue = args.Value;        
    if (sValue.length != 6 && sValue.length != 5)
    {
        args.IsValid = false;
        return;
    }
        
    if (sValue.length == 5)
    {
        if (!IsNumeric(sValue))
        {
            args.IsValid = false;
            return;
        }
    }
    
    if (sValue.length == 6)
    {
        if (IsNumeric(sValue))
        {
            args.IsValid = false;
            return;
        }
        
        if (!IsAlphaNumeric(sValue))
        {
            args.IsValid = false;
            return;
        }
    }
 
    args.IsValid = true;
}

function Confirmation(cboValue)
{        
    if(cboValue.value == "0")
    {
        alert("Please select quote to delete");
        return false;    
    }
    else
    {        
        var UserInput = confirm('Delete selected quote?');
        if(UserInput)
            return true;            
        else
            return false;
    }
}

function change(v)
{
    for(i = 0; i < document.forms["aspnetForm"].elements.length; i ++)
    {
        elm = document.forms["aspnetForm"].elements[i] 
        if (elm.type == 'radio') 
        { 
                if (elm.value == v.value) 
                { 
                    elm.checked = true; 
                }
                else
                {
                    elm.checked = false; 
                } 
        } 
    }            
}

function Validate()
{
    var flag;
    flag = false;
    for(i = 0; i < document.forms["aspnetForm"].elements.length; i ++)
    {
        elm = document.forms["aspnetForm"].elements[i] 
        if (elm.type == 'radio') 
        { 
            if(elm.checked == true)
                flag = true;
        } 
    }
    if(flag == false)
    {
        alert("Please select at least one address");
        return false;
    }
    return true;
}      

function ValidateZip(sender, args)
{
   var sValue = args.Value;        
    if (sValue.length < 5)
    {
        args.IsValid = false;
        return;
    }
    args.IsValid = true;
}

    

function ChangePurchaseQty(tradeInQtyID, promoQtyID)
{
    promoQtyID.value = tradeInQtyID.value;        
}          

function OpenWindow(sPage, keyValue, width, height)
{
    window.open(sPage,keyValue,'toolbar=0,width='+ width + ',height=' + height + ',resizable=1,scrollbars=1');
    return false;        
}


function ValidateCheckBox(sender, args)
    {
        if (document.getElementById("ctl00_ContentPlaceHolder_chkEmail").checked == false && document.getElementById("ctl00_ContentPlaceHolder_chkPhone").checked == false && document.getElementById("ctl00_ContentPlaceHolder_chkMail").checked == false && document.getElementById("ctl00_ContentPlaceHolder_chkContact").checked == false)
        {
            args.IsValid = false;
            return;
        }        
    }
    
        
    function DontContact()
    {
        var chkEmail = document.getElementById("ctl00_ContentPlaceHolder_chkEmail");
        var chkPhone = document.getElementById("ctl00_ContentPlaceHolder_chkPhone");
        var chkMail = document.getElementById("ctl00_ContentPlaceHolder_chkMail");
        var chkContact = document.getElementById("ctl00_ContentPlaceHolder_chkContact");
        var rdHTML = document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormat_0");
        var rdText = document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormat_1");
    
        if(chkContact.checked == true)
        {
            chkEmail.checked = false;
            chkPhone.checked = false;
            chkMail.checked = false;
            rdHTML.checked = false;
            rdText.checked = false;
        }               
    }
    function ContactMe()
    {
        var chkEmail = document.getElementById("ctl00_ContentPlaceHolder_chkEmail");
        var chkPhone = document.getElementById("ctl00_ContentPlaceHolder_chkPhone");
        var chkMail = document.getElementById("ctl00_ContentPlaceHolder_chkMail");
        var chkContact = document.getElementById("ctl00_ContentPlaceHolder_chkContact");
        var rdHTML = document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormat_0");
        var rdText = document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormat_1");

        if(chkEmail.checked == true || chkPhone.checked == true || chkMail.checked == true)
        {
            chkContact.checked = false;
        }   
        
        if (chkEmail.checked == true && rdText.checked == false)
        {
            rdHTML.checked = true;           
        }
        if (chkEmail.checked == false)
        {
            rdHTML.checked = false;
            rdText.checked = false;            
        }
    }
    function CheckEmail()
    {
        document.getElementById("ctl00_ContentPlaceHolder_chkEmail").checked = true;
        document.getElementById("ctl00_ContentPlaceHolder_chkContact").checked = false;
    }
    function ValidateEmailFormat()
    {
        if (document.getElementById("ctl00_ContentPlaceHolder_rdEmailNew_0").checked == true)
        {
            document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormatNew_0").checked = true;
            document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormatNew_0").disabled = false;
            document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormatNew_1").disabled = false;
        }
        if (document.getElementById("ctl00_ContentPlaceHolder_rdEmailNew_1").checked == true)
        {
            document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormatNew_0").disabled = true;
            document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormatNew_0").checked = false;            
            document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormatNew_1").disabled = true;
            document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormatNew_1").checked = false;
        }        
    }
    
    function ValidateEmail()
    {
        if (document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormatNew_0").checked == true ||
            document.getElementById("ctl00_ContentPlaceHolder_rblEmailFormatNew_1").checked == true )
        {            
            document.getElementById("ctl00_ContentPlaceHolder_rdEmailNew_0").checked = true;            
        }
    }


function ValidateMultiLoc(tRadioID, tRFVID, tRFVID1) 
        {                           
            tRFVID.enabled = tRadioID.checked;                                     
            tRFVID1.enabled = tRadioID.checked;
        }
        
function ValidateMultiLoc(tRadioID, tRFVID1) 
        {                           
            //tRFVID.enabled = tRadioID.checked;                                     
            tRFVID1.enabled = tRadioID.checked;
        }
        
        
 function ShowTab(iTab)
    {
	    var oFrm = document.forms['frmTab'];
    	
	    if(iTab==1)
	    {
		    oFrm.action = "Terms.aspx?hdnTerms=1"; 
	    }
	    else
	    {
	        oFrm.action = "Terms.aspx?hdnTerms=2";
	    }

	    oFrm.submit();
    }
    
    function Printform()
    {
        window.print();
        return false;
    }
    
    function ValidateLargeTradeFields(sender, args)
    {
        var sValue = args.Value;
        if ( sValue == "0" )
        {
            args.IsValid = false;
            document.location = '#TimeOfTrade';
            return;
        }        
        args.IsValid = true;
    }
    
    function ValidateMaxQty(sender, args)
    {
        var sValue = args.Value;                  
        var iMax = parseInt(document.getElementById("ctl00_ContentPlaceHolder_hdMaxQty").value);
        if (isNaN(sValue) || sValue <= 0 || (sValue.indexOf('.') != -1))
        {
            args.IsValid = true;
            return;
        }
        else if (sValue > 1 && sValue <= iMax)
        {
            document.getElementById("ctl00_ContentPlaceHolder_txtQuantity").value = 1;
            args.IsValid = false;
            return;            
        }
        args.IsValid = true;
    }
    //Update Total Purchase Ports based on quantity changes
    function UpdatePurchasePorts(txtPromoQty, hdnPurchasePorts, txtTotalPurchasePorts)
    {
        if (hdnPurchasePorts.value != '')
        {
            txtTotalPurchasePorts.value = txtPromoQty.value * hdnPurchasePorts.value;
        }
    }


    function OpenSaveQuote()
    {
        var bSave = confirm('To save the content of current quote list press the Cancel button, \n' +
		        'and then save the quote list. Else, Press the OK button to load a saved quote list.')
        if(bSave)		//display the template list
        {
	        var rtn = window.showModalDialog('/LoadBasket.aspx','_blank','dialogWidth:400px;dialogHeight:125px;menubar:no;scrollbars:no;resizable:no;location:no;status:no;help:no');
	        if (rtn)
	        {	            
	            var rtnArray = rtn.split(';');	           	            		            
		         if (rtnArray[0])
		        {
		            document.getElementById("ctl00_ContentPlaceHolder_hdnSavedCartID").value = rtnArray[0];	
		            document.getElementById("ctl00_ContentPlaceHolder_hdnReturnQuoteName").value = rtnArray[1];
		            __doPostBack('ctl00_ContentPlaceHolder_btnOpen','');			        
			        //document.forms['aspnetForm'].submit();
			        //WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00_ContentPlaceHolder_btnOpen", "", true, "openQuote", "", false, false));
		        }
	        }
        }
    }
    
    
    function SaveBasket()
    {
        var aName = "";
        aName = prompt('Please choose a name for this quote list:', aName);
       
        if(aName == null)
        {
            return false;
        }
        else if(aName.replace(/^\s+|\s+$/g,"") == "")
        {
            alert("Please enter name for this quote.");
            SaveBasket();
            return false;
        }
        
        if(IsAlphaNumeric(aName.replace(/\s/g, "")))
        {
          document.getElementById("ctl00_ContentPlaceHolder_hdnSaveQuote").value = aName.replace(/^\s+|\s+$/g,"");
          //document.forms['aspnetForm'].submit();
       
        }
        else        
        {
             alert("Please enter valid quote name. Quote name should have only alpha numeric characters.");
             SaveBasket();             
        }        
    }
    
    function ResetErrorMsg()
    {
        if(document.aspnetForm.ctl00_ContentPlaceHolder_drpCustCategory.options[document.aspnetForm.ctl00_ContentPlaceHolder_drpCustCategory.selectedIndex].value != "0")
        {
           document.getElementById("ctl00_ContentPlaceHolder_spCatErrorMessage").innerHTML = "";
        }
        if(document.aspnetForm.ctl00_ContentPlaceHolder_drpTimeOfTrade.options[document.aspnetForm.ctl00_ContentPlaceHolder_drpTimeOfTrade.selectedIndex].value != "0")
        {
           document.getElementById("ctl00_ContentPlaceHolder_spTimeErrorMessage").innerHTML = "";           
        }   
        if(document.getElementById("ctl00_ContentPlaceHolder_txtMultipleLoc").value != '')      
        {
            document.getElementById("ctl00_ContentPlaceHolder_spLocErrorMsg").innerHTML = ""; 
        }
        else
        {
            document.getElementById("ctl00_ContentPlaceHolder_spLocInvalidErrorMsg").innerHTML = "";                 
        }
    }    
    
    function ResetErrorMsgFromButton()
    {
           if(document.getElementById("ctl00_ContentPlaceHolder_spCatErrorMessage")!=null)
	   {
	   document.getElementById("ctl00_ContentPlaceHolder_spCatErrorMessage").innerHTML = ""; 
           }   
            if(document.getElementById("ctl00_ContentPlaceHolder_spTimeErrorMessage")!=null)
           {
           document.getElementById("ctl00_ContentPlaceHolder_spTimeErrorMessage").innerHTML = ""; 
           }
	  if(document.getElementById("ctl00_ContentPlaceHolder_spLocErrorMsg")!=null)
	   {
           document.getElementById("ctl00_ContentPlaceHolder_spLocErrorMsg").innerHTML = "";            
	   }
           if(document.getElementById("ctl00_ContentPlaceHolder_spFileMsg") != null) 
           {
             document.getElementById("ctl00_ContentPlaceHolder_spFileMsg").innerHTML = "";                 
           }
           //   AAS_1698_20080320 Start: Hide validation error messeges in option1 and option2 sections when option 3 submit button is clicked
           if(document.getElementById("ctl00_ContentPlaceHolder_spFileMsgSection1") != null) 
           {
             document.getElementById("ctl00_ContentPlaceHolder_spFileMsgSection1").innerHTML = "";                 
           }
           if(document.getElementById("ctl00_ContentPlaceHolder_spFileMsgSection2") != null) 
           {
             document.getElementById("ctl00_ContentPlaceHolder_spFileMsgSection2").innerHTML = "";                 
           }
           //   AAS_1698_20080320 End: Hide validation error messeges in option1 and option2 sections when option 3 submit button is clicked
    }    
