﻿// JScript File
var bCheckout =false;
var bRegistration = false
var prefix = "ctl00_ContentPageBody_";
//alert(location.href.toLowerCase().indexOf('/checkout.aspx') );
if(location.href.toLowerCase().indexOf('/checkout.aspx') != -1 || location.href.toLowerCase().indexOf('/checkoutguest.aspx') != -1)
{
bCheckout=true;
}
if(bCheckout)
{
//  Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest
//  (
//    function () 
//    {
//        if (document.getElementById) 
//        {
//            var progress = document.getElementById("progress");
//            var blur = document.getElementById("blur");
//            
//            progress.style.width = '100%';
//            progress.style.height = '100%';
//            
////            blur.style.height = document.documentElement.clientHeight+600+'px';
////            progress.style.top=100+'px';
////            progress.style.left=470+'px';
//            progress.style.top = document.documentElement.clientHeight/3 - progress.style.height.replace('px','')/2 + 'px';
//            progress.style.left = document.body.offsetWidth/2 - progress.style.width.replace('px','')/2 + 'px';
//        }
//    }
//  );
}
  

function SetSelected(control, controlValue) 
{
	var hSelected = document.all ? document.all[control] : document.getElementById(control);
	hSelected.value = controlValue;
}

function ValidateBlank(source, arguments) {
	try {
		var bValidate = true;
		if (bValidate) {
			if (arguments.Value.trim().length == 0)
			arguments.IsValid = false;
	}
	else
		arguments.IsValid = true;
	}
	catch(e){
		arguments.IsValid = true;
	}
}
  
function ValidateCreditCard(source, arguments) 
{
	var cardNumber = document.all ? document.all[prefix +"txtCreditCard"] : document.getElementById(prefix+"txtCreditCard");
	var cardType = document.all ? document.all[prefix+"ddlCardType"] : document.getElementById(prefix+"ddlCardType");
	if (cardType.selectedIndex > 0 && cardNumber.value.trim().length > 0) {
		arguments.IsValid = checkCreditCard (cardNumber.value.trim(),cardType.options[cardType.selectedIndex].text);
		return;
	}
	arguments.IsValid = true;
}
 
 /*Billing information validation*/
function ValidateBState(source, arguments)
{

   var iCountry = document.getElementById(prefix+"ddlBCountry").value;
   var ddlSState = document.getElementById(prefix+"ddlBState");
     if(iCountry == "226" && ddlSState.value =='-1' )
        arguments.IsValid =false;
      else
        arguments.IsValid =true;
      
}

function ValidateBAState(source, arguments)
{

   var iCountry = document.getElementById("ddlBCountry").value;
   var ddlSState = document.getElementById("ddlBState");
     if(iCountry == "226" && ddlSState.value =='-1' )
        arguments.IsValid =false;
      else
        arguments.IsValid =true;
      
}

function ValidateEBState(source, arguments)
{

   var iCountry = document.getElementById(prefix+"ddlEBCountry").value;
   var ddlSState = document.getElementById(prefix+"ddlEBState");
     if(iCountry == "226" && ddlSState.value =='-1' )
        arguments.IsValid =false;
      else
        arguments.IsValid =true;
      
}

function ValidateEmptyBPhoneNumber(source,arguments)
{
    var phone1  = (document.getElementById(prefix+"txtBPhoneNumber").value).trim();
    if(phone1 == "")
        arguments.IsValid =false;
    else
     arguments.IsValid =true;

}


function ValidateBPhoneNumber(source,arguments)
{

    var phone1  = (document.getElementById(prefix+"txtBPhone1").value).trim();
    var phone2  = (document.getElementById(prefix+"txtBPhone2").value).trim();
    var phone3  = (document.getElementById(prefix+"txtBPhone3").value).trim();
    

    if( (phone1 == "" || phone2 =="" || phone3=="") || (isNaN(phone1) || isNaN(phone2) || isNaN(phone3)))
    {
        arguments.IsValid =false;

    }
    else if(phone1.length < 3 ||phone2.length<3 || phone3.length <4)
    {
         arguments.IsValid =false;
    }
    else
    {
        var phonenumber =phone1 +"."+phone2+"."+phone3
        document.getElementById(prefix+"txtBPhoneNumber").value = phone1 +"."+phone2+"."+phone3;
        arguments.IsValid =true;
    }
}


function ValidateEmptyEBPhoneNumber(source,arguments)
{

    var phone1  = (document.getElementById(prefix+"txtEBPhoneNumber").value).trim();
    if(phone1 == "")
        arguments.IsValid =false;
    else
     arguments.IsValid =true;

}


function ValidateEBPhoneNumber(source,arguments)
{

    var phone1  = (document.getElementById(prefix+"txtEBPhone1").value).trim();
    var phone2  = (document.getElementById(prefix+"txtEBPhone2").value).trim();
    var phone3  = (document.getElementById(prefix+"txtEBPhone3").value).trim();
    

    if( (phone1 == "" || phone2 =="" || phone3=="") || (isNaN(phone1) || isNaN(phone2) || isNaN(phone3)))
    {
        arguments.IsValid =false;

    }
    else if(phone1.length < 3 ||phone2.length<3 || phone3.length <4)
    {
         arguments.IsValid =false;
    }
    else
    {
        var phonenumber =phone1 +"."+phone2+"."+phone3
        document.getElementById(prefix+"txtEBPhoneNumber").value = phone1 +"."+phone2+"."+phone3;
        arguments.IsValid =true;
    }
}

/*Shipping Validation */
function ValidateSState(source, arguments)
   {
   
       var iCountry = document.getElementById(prefix+"ddlSCountry").value;
       var ddlSState = document.getElementById(prefix+"ddlSState");
         if(iCountry == "226" && ddlSState.value =='-1' )
            arguments.IsValid =false;
          else
            arguments.IsValid =true;
          
    }
    
 function ValidateShState(source, arguments)
   {
   
       var iCountry = document.getElementById("ddlSCountry").value;
       var ddlSState = document.getElementById("ddlSState");
         if(iCountry == "226" && ddlSState.value =='-1' )
            arguments.IsValid =false;
          else
            arguments.IsValid =true;
          
    }   
 
 function ValidateESState(source, arguments)
   {
   
       var iCountry = document.getElementById(prefix+"ddlESCountry").value;
       var ddlSState = document.getElementById(prefix+"ddlESState");
         if(iCountry == "226" && ddlSState.value =='-1' )
            arguments.IsValid =false;
          else
            arguments.IsValid =true;
          
    }
       
 function ValidateEmptySPhoneNumber(source,arguments)
   {
        var phone1  = (document.getElementById(prefix+"txtSPhoneNumber").value).trim();
        if(phone1 == "")
            arguments.IsValid =false;
        else
         arguments.IsValid =true;
    }
    
   function ValidateSPhoneNumber(source,arguments)
   {
        var phone1  = (document.getElementById(prefix+"txtSPhone1").value).trim();
        var phone2  = (document.getElementById(prefix+"txtSPhone2").value).trim();
        var phone3  = (document.getElementById(prefix+"txtSPhone3").value).trim();
        
    
        if( (phone1 == "" || phone2 =="" || phone3=="") || (isNaN(phone1) || isNaN(phone2) || isNaN(phone3)))
        {
            arguments.IsValid =false;

        }
        else if(phone1.length < 3 ||phone2.length<3 || phone3.length <4)
        {
             arguments.IsValid =false;
        }
        else
        {
            var phonenumber =phone1 +"."+phone2+"."+phone3
            document.getElementById(prefix+"txtSPhoneNumber").value = phone1 +"."+phone2+"."+phone3;
            arguments.IsValid =true;
        }
   }
   
   
   function ValidateEmptyESPhoneNumber(source,arguments)
   {
        var phone1  = (document.getElementById(prefix+"txtESPhoneNumber").value).trim();
      
        if(phone1 == "")
            arguments.IsValid =false;
        else
         arguments.IsValid =true;
    }
    
   function ValidateESPhoneNumber(source,arguments)
   {
        var phone1  = (document.getElementById(prefix+"txtESPhone1").value).trim();
        var phone2  = (document.getElementById(prefix+"txtESPhone2").value).trim();
        var phone3  = (document.getElementById(prefix+"txtESPhone3").value).trim();
        
    
        if( (phone1 == "" || phone2 =="" || phone3=="") || (isNaN(phone1) || isNaN(phone2) || isNaN(phone3)))
        {
            arguments.IsValid =false;

        }
        else if(phone1.length < 3 ||phone2.length<3 || phone3.length <4)
        {
             arguments.IsValid =false;
        }
        else
        {
            var phonenumber =phone1 +"."+phone2+"."+phone3
            document.getElementById(prefix+"txtESPhoneNumber").value = phone1 +"."+phone2+"."+phone3;
            arguments.IsValid =true;
        }
   }
  
  function EnableDisableValidator(obj,bval)
    {
    //alert(obj + " / " + document.getElementById(prefix+"pnlNewShippingAddress") + " / " + bval);
//      if(obj =="shipping" && document.getElementById(prefix+"pnlNewShippingAddress")!=null)
//      {
//          ValidatorEnable(document.getElementById(prefix+"custSName"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custSAddress1"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custSCity"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custSState"), bval);
//          if(document.getElementById(prefix+"cvSState")!= null)
//          ValidatorEnable(document.getElementById(prefix+"cvSState"), bval);
//          
//          ValidatorEnable(document.getElementById(prefix+"custSZipCode"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custSPhone"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custSPhone1"), bval);
//      }
//      if(obj=="billing" && document.getElementById(prefix+"pnlNewBillingAddress")!=null)
//      {
//          ValidatorEnable(document.getElementById(prefix+"custBName"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custBAddress1"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custBCity"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custBState"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custBState1"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custBZipCode"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custBPhone"), bval);
//          ValidatorEnable(document.getElementById(prefix+"custBPhone1"), bval);
//      }
    }
  
function ShowAddressTips() {
    popUp('/App_UI/Site/pHion/Secure/PopUps/GeneralAddressTips.htm', 820, 700, 'phion', true, true);
}

function ShowFPOAddressTips() {
    popUp('/App_UI/Site/pHion/Secure/PopUps/APOAddressTips.htm', 820, 700, 'phion', true, true);
}
function ShowCCVDetail() 
{
    popUp('/App_UI/Site/pHion/Secure/PopUps/ccvDetail.htm', 820, 700, 'phion', true, true);
}

function adjustDivs()
{

        var df=document.getElementById('progTemplate');
        var foreItem=document.getElementById('progDisplay');
        var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        var scrollTop  = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        scrollTop =scrollTop -50;
        var clientWidth;
        if (window.innerWidth) {
                clientWidth = (window.__safari ? window.innerWidth : Math.min(window.innerWidth, document.documentElement.clientWidth));
            } else {
                clientWidth = document.documentElement.clientWidth;
            }
        var clientHeight;
        if (window.innerHeight) {
            clientHeight = (window.__safari ? window.innerHeight : Math.min(window.innerHeight, document.documentElement.clientHeight));
        } else {
            clientHeight = document.documentElement.clientHeight;
        }
       if(df!=null)
       {
            df.style.position='absolute';
            df.style.left = scrollLeft + 'px';
            df.style.top = scrollTop+50+'px';
            df.style.width = clientWidth+'px';
            df.style.height = clientHeight+'px';
        }
            
        if(foreItem!=null)
        {
            foreItem.style.position='absolute';
            foreItem.style.left = scrollLeft+((clientWidth-foreItem.offsetWidth)/2)+'px';
            foreItem.style.top = scrollTop+((clientHeight-foreItem.offsetHeight)/2)+'px';
        }
       
}

if(bCheckout)
{
    window.onload=adjustDivs;
    window.onresize=adjustDivs;
    window.onscroll=adjustDivs;
}
