var xmlHttp
//CheckPopupblocker();
function custom_onload( e )
{
        load_jsfiles ();        
}

function CheckPopupblocker() {

	var popupblkmsg = document.getElementById("popupblkmsg");
	if ( null == popupblkmsg ) {
		setTimeout ( "CheckPopupblocker();", 100 );
		return
	}//endif

var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
 if(mine)   
 {
    var popUpsBlocked = false
    mine.close();
 }
 else {
    var popUpsBlocked = true
 }//endif

 if(popUpsBlocked)
 {
  //alert('We have detected that you are using popup blocking software.\nPlease remove the pop-up blocker by following instructions on the top of the screen.');
  
popupblkmsg.innerHTML = 'You are using pop-up blocker. This website needs to open a window to print shippping labels. Please <a class="Href_custom_underline" target="_blank" href="DisablePopUp.html">disable your pop-up blocker by following these steps</a>.';


 }//endif

}
function load_jsfiles()
{
	var ctlCopyRights = document.getElementById("Footerdiv");
	if ( null == ctlCopyRights ) {
		setTimeout ( "load_jsfiles();", 500 );
		return
	}//endif
	var url = document.location.pathname;
	var page = document.location.pathname.toUpperCase() ;
	if( page.indexOf('SHIPPINGADDR.ASPX') > -1 ) {
		loadlocations('txtCountry','txtState');
	}
	if( page.indexOf('CREDITCARD.ASPX') > -1 ) {
		loadccctl();
		loadlocations('txtshipfromCountry','txtshipfromstate');
        OnloadbtnSummary();
        hidebtn_cc();
        autoCreateShipment();
	alterReadonlyAddValues(true); 
	}
}
function btnautoCreateShipment () {
	var $x_response_code = document.getElementById('x_response_code');
	var $btnquote = document.getElementById('btnquote');
    if(null == $x_response_code) {
		setTimeout ( "autoCreateShipment();", 500 );
		return ;
    }//endif
    if(null == $btnquote) {
		setTimeout ( "autoCreateShipment();", 200 );
		return ;
    }//endif

    if($x_response_code.value != "1") {
            return ;
    }//endif


    if($btnquote.value == "Create Shipping Label" && $btnquote.disabled == false) {
			//do auto create shipment
            $btnquote.click();
            return ;
    }//endif
}//autoCreateShipment

function ShowAlertBox_i(){
         var $Div = $('ctl_Alterbox');  
         if( null == $Div) {
		 	 setTimeout("ShowAlertBox_i()", 100);
		 	 return false;
		 }


         var $ScreenWidth = window.innerWidth;
         var $ScreenHeight = window.innerHeight;

         if(!$ScreenWidth || !$ScreenHeight )  {
            $ScreenWidth = document.documentElement.clientWidth;
            $ScreenHeight = document.documentElement.clientHeight;
         }//endif
         $ScreenWidth = parseInt( $ScreenWidth ) /3;
         $ScreenHeight = parseInt( $ScreenHeight ) /3 ;


         var $ImgWidth = "300";
         var $ImgHeight = "300";

         $Div.innerHTML = "<div  Align='right' Valing='top'></div><div class='div_ImageShell' style='' align='center'><br><h2>Creating Shipment.....</h2><br><h6>If this page takes too much time to load <a href='javascript:btnautoCreateShipment();' class='Href_custom_underline_1'>please click here to create the shipment.</a></h6></div>";

         $Div.style.visibility = 'visible';

         var $DivOffsetTop = FindParentOffsetTop($Div);
         if(!$DivOffsetTop || $DivOffsetTop<$ScreenHeight) {
             $DivOffsetTop = $ScreenHeight ;
         }
         if(!$ScreenWidth) {
		 	$ScreenWidth = '300' ;
		 }//

         $Div.style.left = $ScreenWidth + "px";
         $Div.style.top =  "500px";   //$DivOffsetTop + 
}
function FindParentOffsetTop(oObject)
{
         var oParent = oObject.offsetParent;
         return oParent.offsetTop;
}

function HideFullSizeImage_ctl_ShowAlertbox() {
         var $Div = $('ctl_ShowAlertbox');
         $Div.style.visibility = 'hidden';
}
function HideFullSizeImage_ctl_ShowFullSizeImage() {
         var $Div = $('ctl_Alterbox');
         $Div.style.visibility = 'hidden';
}

function autoCreateShipment () {
	var $x_response_code = document.getElementById('x_response_code');
	var $btnquote = document.getElementById('btnquote');
    if(null == $x_response_code) {
		setTimeout ( "autoCreateShipment();", 500 );
		return false;
    }//endif
    if(null == $btnquote) {
		setTimeout ( "autoCreateShipment();", 200 );
		return false;
    }//endif

    if($btnquote.value == "Create Shipping Label" && $btnquote.disabled == false)
	{
			ShowAlertBox_i();

            if($x_response_code.value != "1") {
               return false;
            }//endif
			//do auto create shipment
            $btnquote.click();
            return ;
    }//endif
}//autoCreateShipment

function hidebtn_cc () {
	var $btnprintlabel = document.getElementById('btnprintlabel');
    if(null == $btnprintlabel) {
		setTimeout ( "hidebtn_cc();", 200 );
		return false;
    }//endif
    $btnprintlabel.style.visibility= 'hidden';

}//hidebtn_cc

function OnloadbtnSummary() {
    var $btnSummary = document.getElementById('btnSummary');
    var $btnprintlabel = document.getElementById('btnprintlabel');
    if((null == $btnSummary) || (null == $btnprintlabel)) {
		setTimeout ( "OnloadbtnSummary();", 200 );
		return false;
    }//endif

    var OldOnclick = $btnprintlabel.onclick;
    var NewOnclick = function(IN_oClickEvent)
    {  javascript:window.open('/watertech/rmapb/BarCodeImage.aspx');$btnSummary.click();return false;    };

    $btnprintlabel.onclick =  NewOnclick;
    //$btnSummary.style.display = "none" ;

}//End OnloadbtnSummary

function ValidateAddress() {
    var $btnsaveadd = document.getElementById('btnsaveadd');
    var $DropDownList1 = document.getElementById('DropDownList1');

    if (( null == $btnsaveadd ) || ( null == $DropDownList1 )) {
		setTimeout ( "ValidateAddress();", 200 );
		return false;
	}//endif
	
	if($DropDownList1.disabled == false ) {	
	       if($btnsaveadd.disabled == false ) {	
	            alert("Please save the 'Ship From' changes by clicking 'Save' button on the top");
	            return false;
	       }//endif
	}//endif
	
	return true;	
}
function SkipShipping()
{	return ipalrertbox("Are you sure to cancel UPS Shipping option?");
}
function ipalrertbox(msg)
{
var getresp = confirm (msg)
if (getresp)
	return true;
else
	return false;
return false;
}
	
function loadccctl() {

	var $RadioPayuCC_false = document.getElementById('RadioPayuCC_false');
	var $RadioPayuCC_true = document.getElementById('RadioPayuCC_true');
	var $txtType = document.getElementById('txtType');
	var $DropDownList1 = document.getElementById('DropDownList1');
	
	if (( null == $DropDownList1 ) ||( null == $RadioPayuCC_true ) || ( null == $RadioPayuCC_false ) || ( null == $txtType )) {
		setTimeout ( "loadccpage();", 200 );
		return;
	}//endif
		
	if($txtType.disabled == true) {
		$RadioPayuCC_false.checked = false;
		$RadioPayuCC_true.checked = true;
		enableDisableCC(true);	
	}else {
		$RadioPayuCC_false.checked = true;
		$RadioPayuCC_true.checked = false;	
		enableDisableCC(false);
	}//endif
	
	var $btnprintlabel = document.getElementById('btnprintlabel');

	if($DropDownList1.disabled == true ) {
          $RadioPayuCC_true.disabled = true;
	  if(!$btnprintlabel)	 {
		$RadioPayuCC_false.disabled = false;
		$RadioPayuCC_false.checked = true;
		enableDisableCC(false);
	  } else {
            if($btnprintlabel.disabled==false) {
		$RadioPayuCC_false.disabled = true;
		enableDisableCC(true);
            }//endif
	  }//endif
	}
	else {
		$RadioPayuCC_false.disabled = false;
		$RadioPayuCC_true.disabled = false;			
	}//endif	
	
	
}//end loadccpage

function EnableSaveBtn() {
   
    var btn = document.getElementById('btnsaveadd');
	if ( null == btn ) {
		setTimeout ( "EnableSaveBtn();", 200 );
		return
	}//endif
  
    btn.disabled = false;  
}
function loadlocations(CountryId,StateId) 
{
  replacecountrycode(CountryId);
  replacestatecode(StateId) ;
}

function replacecountrycode(id) {
	var id   ;

	var newid = 'newCountry' ;
	var oldtb = $(id) ;
	var p = $(id).parentNode ;
	var newselect = document.createElement("SELECT");
	

	if (oldtb.value == '') {
		oldtb.value = "US" ;	
	}

	var curval = oldtb.value ;
	var selectindex = 0 ;
    //rembyid("txtText") ;
    newselect.id = newid   ; 
    newselect.name = newid ; 
    newselect.className = oldtb.className ;
    
    if(oldtb.readOnly) {
		newselect.disabled = true;
    } else {
		newselect.disabled = false;
	}
	newselect.onchange = function () {
		$(id).value = $('newCountry').value;
	}
    
    AddDropDownItem( newselect , "USA", "US" );
    AddDropDownItem( newselect , "Canada", "CA" );
	
    if( curval == "CA") {
	    selectindex = 1 ;
    }
	    
    newselect.selectedIndex=selectindex ;
    
	oldtb.style.display = "none" ;	
	p.appendChild(newselect);
        $(id).value = $('newCountry').value;	
	//updatetb2();
	//$("ctlAgent_ddlItems").onchange = updateagent ;
}



function replacestatecode(id) {
	var id  ;
	var newid = 'newState' ;
	var oldtb = $(id) ;
	var p = $(id).parentNode ;
	var newselect = document.createElement("SELECT");
	var curval = oldtb.value ;
	var selectindex = 0 ;	
    //rembyid("txtText") ;
    newselect.id = newid   ; 
    newselect.name = newid ; 
    newselect.className = oldtb.className ;
    if(oldtb.readOnly) {
		newselect.disabled = true;
    } else {
		newselect.disabled = false;
	}
    
    //newselect.style.width = "180px";
	newselect.onchange = function () {
		$(id).value = $('newState').value;
	}
    var count = 0 ;
	//AddDropDownItem( newselect ,  "Select State" , ""  );
        //count++ ;

	var data = [["AL","Alabama"],["AK","Alaska"],["AB","Alberta"],["AZ","Arizona"],["AR","Arkansas"],["BC","British Columbia"],["CA","California"],["CO","Colorado"],["CT","Connecticut"],["DE","Delaware"],["DC","District of Columbia"],["FL","Florida"],["GA","Georgia"],["HI","Hawaii"],["ID","Idaho"],["IL","Illinois"],["IN","Indiana"],["IA","Iowa"],["KS","Kansas"],["KY","Kentucky"],["LA","Louisiana"],["ME","Maine"],["MB","Manitoba"],["MD","Maryland"],["MA","Massachusetts"],["MI","Michigan"],["MN","Minnesota"],["MS","Mississippi"],["MO","Missouri"],["MT","Montana"],["NE","Nebraska"],["NV","Nevada"],["NB","New Brunswick"],["NH","New Hampshire"],["NJ","New Jersey"],["NM","New Mexico"],["NY","New York"],["NF","Newfoundland"],["NC","North Carolina"],["ND","North Dakota"],["NT","Northwest Territories"],["NS","Nova Scotia"],["OH","Ohio"],["OK","Oklahoma"],["ON","Ontario"],["OR","Oregon"],["PA","Pennsylvania"],["PE","Prince Edward Island"],["PQ","Quebec"],["RI","Rhode Island"],["SK","Saskatchewan"],["SC","South Carolina"],["SD","South Dakota"],["TN","Tennessee"],["TX","Texas"],["UT","Utah"],["VT","Vermont"],["VA","Virginia"],["WA","Washington"],["WV","West Virginia"],["WI","Wisconsin"],["WY","Wyoming"],["YT","Yukon"]] ;
	
	for (i=0;i<data.length ;i=i+1) { 
	
		if( curval == data[i][0]) {
			selectindex = count ;
		}
		
		AddDropDownItem( newselect ,  data[i][1], data[i][0] );	
		count++ ;
	}
	    
        newselect.selectedIndex=selectindex ;
    
	oldtb.style.display = "none" ;	
	p.appendChild(newselect);
       	$(id).value = $('newState').value;
	//updatetb2();
	//$("ctlAgent_ddlItems").onchange = updateagent ;
} 
function enableDisableCC (myBoolean)
{
	
	var $txtType = document.getElementById('txtType');
	var $txtName = document.getElementById('txtName');
	var $txtNumber = document.getElementById('txtNumber');
	var $ddltxtExpiry_m = document.getElementById('txtExpiry_month');
	var $ddltxtExpiry_y = document.getElementById('txtExpiry_year');
 
	var $txtSecCode = document.getElementById('txtSecCode');
	
	$txtType.disabled  = myBoolean;	
	$txtName.disabled = myBoolean;	
	$txtNumber.disabled = myBoolean;	
	$ddltxtExpiry_m.disabled = myBoolean;	
	$ddltxtExpiry_y.disabled = myBoolean;	
	$txtSecCode.disabled = myBoolean;	

	if(myBoolean) {
		$txtType.className = "Dropdown_ups_disabled";
		$ddltxtExpiry_m.className = "Dropdown_ups_disabled_expdate";
		$ddltxtExpiry_y.className = "Dropdown_ups_disabled_expdate";
		
		$txtName.className = "TextBox_disabled";
		$txtNumber.className = "TextBox_disabled";		
		$txtSecCode.className = "TextBox_disabled";		
	} else {
		$txtType.className = "Dropdown_ups";
		$ddltxtExpiry_m.className = "Dropdown_ups_expdate";
		$ddltxtExpiry_y.className = "Dropdown_ups_expdate";
		
		$txtName.className = "TextBox";
		$txtNumber.className = "TextBox";
		$txtSecCode.className = "TextBox";
	}
	
}
/*function redirectToSummaryPage() {
//<input type="button" id="btnskip"  onclick="redirectToSummaryPage();" class="WebControl" value="Skip Shipping" />
	var page = document.location.pathname ;
	location.href= page.replace(/CreditCard/i,"Summary");	
}*/
function funEdit()
{	
	alterReadonlyAddValues(false);
	EnableSaveBtn();
}//end funEdit
function alterReadonlyAddValues(myBoolean){
	
	
	//var $txtshipfromCompanyName = document.getElementById('txtshipfromCompanyName');
	var $txtshipfromName = document.getElementById('txtshipfromName');
	var $txtshipfromadd1 = document.getElementById('txtshipfromadd1');
	var $txtshipfromadd2 = document.getElementById('txtshipfromadd2');
	var $txtshipfromcity = document.getElementById('txtshipfromcity');
	var $txtshipfromstate = document.getElementById('txtshipfromstate');
	var $txtshipfromzip = document.getElementById('txtshipfromzip');
	var $txtshipfromCountry = document.getElementById('txtshipfromCountry');
	var $txtshipfromEmail = document.getElementById('txtshipfromEmail');
	var $txtshipfromPhone = document.getElementById('txtshipfromPhone');
	var $txtshipfromFax = document.getElementById('txtshipfromFax');
	var $newCountry = document.getElementById('newCountry');
	var $newState = document.getElementById('newState');
	

	//$txtshipfromCompanyName.readOnly = myBoolean;	
	$txtshipfromName.readOnly = myBoolean;
	$txtshipfromadd1.readOnly = myBoolean;
	$txtshipfromadd2.readOnly = myBoolean;
	$txtshipfromcity.readOnly = myBoolean;
	$txtshipfromstate.readOnly = myBoolean;
	$txtshipfromzip.readOnly = myBoolean;
	$txtshipfromCountry.readOnly = myBoolean;
	$txtshipfromEmail.readOnly = myBoolean;
	$txtshipfromPhone.readOnly = myBoolean;
	$txtshipfromFax.readOnly = myBoolean;
	$newCountry.disabled = myBoolean;	
	$newState.disabled = myBoolean;	
	
	if(myBoolean) {
		//$txtshipfromCompanyName.className = "AddressTextBox"
		$txtshipfromName.className = "AddressTextBox";
		$txtshipfromadd1.className = "AddressTextBox";
		$txtshipfromadd2.className = "AddressTextBox";
		$txtshipfromcity.className = "AddressTextBox";
		$txtshipfromstate.className = "AddressTextBox";
		$txtshipfromzip.className = "AddressTextBox";
		$txtshipfromCountry.className = "AddressTextBox";
		$txtshipfromEmail.className = "AddressTextBox";
		$txtshipfromPhone.className = "AddressTextBox";
		$txtshipfromFax.className = "AddressTextBox";			
		$txtshipfromName.className = "AddressTextBox"
		$newCountry.className= "AddressTextBox"
		$newState.className= "AddressTextBox"
	} else {	
		//$txtshipfromCompanyName.className = "AddressTextBox_Edited"
		$txtshipfromName.className = "AddressTextBox_Edited";
		$txtshipfromadd1.className = "AddressTextBox_Edited";
		$txtshipfromadd2.className = "AddressTextBox_Edited";
		$txtshipfromcity.className = "AddressTextBox_Edited";
		$txtshipfromstate.className = "AddressTextBox_Edited";
		$txtshipfromzip.className = "AddressTextBox_Edited";
		$txtshipfromCountry.className = "AddressTextBox_Edited";
		$txtshipfromEmail.className = "AddressTextBox_Edited";
		$txtshipfromPhone.className = "AddressTextBox_Edited";
		$txtshipfromFax.className = "AddressTextBox_Edited";			
		$txtshipfromName.className = "AddressTextBox_Edited"
		$newCountry.className= "AddressTextBox_Edited"
		$newState.className= "AddressTextBox_Edited"
	}//endif	
}//end function
function $(i){return document.getElementById(i)}
function AddDropDownItem( ddl, text, value ) {
        if (null == ddl) {
            //setTimeout ( "AddDropDownItem("+ddl+",'"+text+"','"+value+"');", 200 );
            return;
       	}

    try {
	var option = document.createElement( 'OPTION' );
	option.text = text;
	option.value = value;
	ddl.options[ddl.options.length] = option;
    } catch (ex) {  }
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



var JSON=function(){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},s={'boolean':function(x){return String(x);},number:function(x){return isFinite(x)?String(x):'null';},string:function(x){if(/["\\\x00-\x1f]/.test(x)){x=x.replace(/([\x00-\x1f\\"])/g,function(a,b){var c=m[b];if(c){return c;}
c=b.charCodeAt();return'\\u00'+
Math.floor(c/16).toString(16)+
(c%16).toString(16);});}
return'"'+x+'"';},object:function(x){if(x){var a=[],b,f,i,l,v;if(x instanceof Array){a[0]='[';l=x.length;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a[a.length]=v;b=true;}}}
a[a.length]=']';}else if(x instanceof Object){a[0]='{';for(i in x){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a.push(s.string(i),':',v);b=true;}}}
a[a.length]='}';}else{return;}
return a.join('');}
return'null';}};return{copyright:'(c)2005 JSON.org',license:'http://www.JSON.org/license.html',stringify:function(v){var f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){return v;}}
return null;},parse:function(text){try{return!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g,'')))&&eval('('+text+')');}catch(e){return false;}}};}();


