// Replace the images inside the double-quotes to your own images
// You may have any number of images
adImages = new Array("../images/ad2.jpg","../images/ad4.jpg")

// Replace the quotes to inside the double-quotes to your own quotes
// You may have any number of quotes but they must equal the number of images that rotate
quote = new Array("Airflow Booster","Universal Thermostat")

// Please remove this lineand the double-slashes at the beginning of the next line to add links to the rotating images
adURL = new Array ("www.atlantasupply.com/swscripts/NLNETUPD.OBJ?REQR_TYPE=O&REQR_ID=NEW+CUSTOMER&AUTH_ID=+&LOC_NO=001&STOCK_NO=EQ2&REQUEST_ID=CSTKDET","www.atlantasupply.com/swscripts/NLNETUPD.OBJ?REQR_TYPE=O&REQR_ID=NEW+CUSTOMER&AUTH_ID=+&LOC_NO=001&STOCK_NO=TS1F85+++++++++&REQUEST_ID=CSTKDET")
adURLNL = new Array ("&LOC_NO=001&STOCK_NO=EQ2&REQUEST_ID=CSTKDET","&LOC_NO=001&STOCK_NO=TS1F85277+++++++++&REQUEST_ID=CSTKDET")
// Please remove this line to add links to the rotating images

thisAd = 0
imgCt = adImages.length
quoteCt = quote.length

function rotate() {
  if (document.images) {
    if (document.cycle.complete) {
	  thisAd++
	  if (thisAd == imgCt && thisAd == quoteCt) {
	    thisAd = 0
	  }
	  document.cycle.src = adImages[thisAd];
      window.defaultStatus = quote[thisAd];
	}
// This sets the interval to which the images and quotes are rotated. 1000 equals 1 second
	setTimeout("rotate()", 60000)
  }
}

// Please remove this lineand the double-slashes at the beginning of the next line to add links to the rotating images
function rotateLink() {
var nlsession = getCookie('SESSION_NO');
if ((nlsession == null) || (nlsession.length < 2))
{
thelink="http://" + adURL[thisAd]
}
else
{
thelink="http://www.atlantasupply.com/swscripts/NLNETUPD.OBJ?SESSION_NO=" + nlsession + adURLNL[thisAd]
}

window.parent.location.href = thelink

}
// Please remove this line to add links to the rotating images

function formpass(theform) {
var nlsession=getCookie('SESSION_NO');
if (nlsession == null)
{
theform.submit(); 
}
else
{
theform.SESSION_NO.value=nlsession;
theform.REQR_ID.value='98';
theform.submit();
} 
}

function cjb()
{
alert ('this is a test from cjb');
}

function setCookie(name, value)
{
if (value == '')
{
var setit = 'no';
}
else
{
var setit = 'yes';
}

if (setit=='yes')
{
DelCookie('SESSION_NO');
  document.cookie = "nlbase=http://www.atlantasupply.com/swscripts/NLNETUPD.OBJ?";
  <!--document.cookie = name + "=" + escape(value) + "; domain=.atlantasupply.com; path=/";-->
  var nlsession=getCookie('SESSION_NO');
  if (nlsession == null)
   {
    expires = new Date()
    <!--expires.toLocaleString() -->
    expiresIn = 3600000
    expires.setTime(expires.getTime() + expiresIn)
    domain = ".atlantsupply.com"
    path= "/"

    document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/; domain=.atlantasupply.com";

    <!--secure = false-->
    <!--((expires == null) ? "" : "; expires=" + expires.toGMTString()) +  -->
    <!--((path == null)    ? "" : "; path=" + path) +  -->
    <!--((domain == null)  ? "" : "; domain=" + domain); -->
    <!--((secure == null)  ? "" : "; secure");-->


    <!--alert ('setting cookie value');-->
    <!--alert (document.cookie);-->
  }
  else
    {
    <!--alert ('cookie value was already set');-->
    }
}
else
{
}
}

function setNew(name,value) {
expires = new Date()
expiresIn = 3600000
document.cookie = "nlbase=http://www.atlantasupply.com/swscripts/NLNETUPD.OBJ?";
 document.cookie = name + "=" + escape(value) + 
  ((expires == 3600000) ? "" : "; expires=" + expires.toLocaleString()) +
  ((path == "/")    ? "" : "; path=" + path) +
  ((domain == ".atlantasupply.com")  ? "" : "; domain=" + domain) +
  ((secure == null)  ? "" : "; secure");
}

function sayCookie(name)
  {
  myval = getCookie(name)
  alert (myval)
  }
  
function allCookie()
  {
  myval = document.cookie
  alert (myval)
  }
function setLink(nlvars1,nlvars2)
  {
  <!--nlbase="http://@VAR_FORM_ACTION_URL_@?"-->
  var baseref=getCookie('nlbase');
  var nlsession=getCookie('SESSION_NO');
  var link1=nlvars1
  var link2=nlvars2
  
    if (baseref == null)
	{
	baseref = "http://www.atlantasupply.com/swscripts/NLNETUPD.OBJ?"
	}
	
    if ((nlsession == null) || (nlsession.length < 2))
    {
    newlink = baseref + link1 + "&" + link2
    <!--alert ('session is null')-->
}
    else
    {
    <!--alert ('session is not null')-->
    newlink = baseref + "SESSION_NO=" + nlsession + "&" + link2
    }

  <!--alert (newlink); -->
  window.location=newlink;
  }

function getCookie(name)
  {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    <!--return unescape(dc.substring(begin + prefix.length, end));-->
    myval = unescape(dc.substring(begin + prefix.length, end));
    return myval;
}

function test(){

alert("If you see this message the Javascript source file is fine");

}
function DelCookie(name) 
{ 
domain = ".atlantsupply.com"
path= "/"
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/; domain=.atlantasupply.com";

}
function linkbuild() {

var thelink = new String(parent.window.location);
var baseref=getCookie('nlbase');
thelink = thelink.replace(baseref,"");
var mystart = thelink.indexOf('SESSION_NO');
var myend = thelink.indexOf('&') + 1;
var remove = thelink.substring(mystart, myend);

thelink = thelink.replace(remove,"");

mystart = thelink.indexOf('NL_ORDER_NO');
myend = thelink.indexOf('&') + 1;
remove = thelink.substring(mystart,myend);

thelink = thelink.replace(remove,"");

var nlsession = getCookie(nlsession);

if (nlsession == null)
    {
    newlink = baseref + thelink;
    }
    else
    {
    newlink = baseref + "SESSION_NO=" + nlsession + "&" + thelink;
    }
new_window = open("","displayWindow","width=600,height=200,left=10,top=10");
new_window.document.write("<html><body><table width='100%' height='100%' border='0'><tr><a href=\"javascript:pushlink('" + newlink + "')\">javascript:pushlink('" + newlink + "')</a></td></tr></table></body></html>");

}

function pushlink(thelink) {

var passlink = new String(thelink);
var baseref=getCookie('nlbase');
var nlsession=getCookie('SESSION_NO');

    if (nlsession == null)
    {
    newlink = passlink

    }
    else
    {

    newlink = passlink + "&SESSION_NO=" + nlsession
    }

parent.window.location = newlink;
}
function testapache(){

alert('this is cgi dir on apache');
}

function ssltest() {
alert('this is cgi dir ssl link');
}

function setSessionID() {
var allIDs=returnAttributes('id');
var nlsession = getCookie('SESSION_NO');
for(i=0;i<allIDs.length;i++) {
    var curID = allIDs[i].toUpperCase();
    if (curID.match("SESSION")) {
      var fld = document.getElementById(allIDs[i]);
        if (fld.value.match("_SESSION_") || fld.value.match("_session_") || !(fld.value.length>5)) {
        fld.value = nlsession; 
	}
    }
  }
}

function returnAttributes(at){
var arr=[];
var elem=document.getElementsByTagName('*'), i=0, e;
while(e=elem[i++]){
e[at]?arr[arr.length]=e[at]:null;
}
return arr;
}

function phone(event) {
/*
var chars = document.FrontPage_Form1.USER_ALPHA2.value;
var count = chars.length;
if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;

if (count == 3) {
document.FrontPage_Form1.USER_ALPHA2.value = chars + '-';
}
if (count == 7) {
document.FrontPage_Form1.USER_ALPHA2.value = chars + '-';
}
*/
}

function phonecheck() {
var chars = document.FrontPage_Form1.USER_ALPHA2.value;
if (chars.charAt(0) == '1') {
alert ('Please enter a 10 digit phone number without the 1');
document.FrontPage_Form1.USER_ALPHA2.value='';
document.FrontPage_Form1.USER_ALPHA2.focus();
}
}

function caps() {
document.FrontPage_Form1.USER_ALPHA1.value = document.FrontPage_Form1.USER_ALPHA1.value.toUpperCase();
}

function writeDate (form) {
	form.test.value = form.month.value + form.year.value
	form.CARD_EXPIRE.value = form.month.value + form.year.value
	testVar = form.CARD_EXPIRE.value;
}
var SHIPNAME = "";
var SHIPADD1 = "";
var SHIPADD2 = "";
var SHIPADD3 = "";
var SHIPCITY = "";
var SHIPSTATE = "";
var SHIPZIP = "";
var SHIPCHECK = 0;

function usebillingdata(form) {
if (form.usebilling.checked==false) {
<!--SaveShipData(form);-->
<!--form.SHIPNAME.value = form.BILLNAME.value;-->
<!--form.SHIPADD1.value = form.BILLADD1.value;-->
<!--form.SHIPADD2.value = form.BILLADD2.value;-->
<!--form.SHIPADD3.value = form.BILLADD3.value;-->
<!--form.SHIPCITY.value = form.BILLCITY.value;-->
<!--form.SHIPSTATE.selectedIndex = form.BILLSTATE.selectedIndex;-->
<!--form.SHIPZIP.value = form.BILLZIP.value;--> 
}
else {
form.SHIPNAME.value = form.BILLNAME.value;
form.SHIPADD1.value = form.BILLADD1.value;
form.SHIPADD2.value = form.BILLADD2.value;
form.SHIPADD3.value = form.BILLADD3.value;
form.SHIPCITY.value = form.BILLCITY.value;
form.SHIPSTATE.selectedIndex = form.BILLSTATE.selectedIndex;
form.SHIPZIP.value = form.BILLZIP.value;
	}
}

function setMiscCharges(shipvia) {

var misccode2 = '';
var misamt2 = '';

switch(shipvia)
{
case 'FG':
misccode2='';
miscamt2='0.00';
break
case 'FSO':
misccode2 = 'FT';
miscamt2 = '7.990';
break
case 'FTD':
misccode2 = 'FT';
miscamt2 = '5.99';
break
default:
misccode2 = '';
miscamt2 = '';
break
}
document.forms['FrontPage_Form1'].MISC_CODE2.value = misccode2;
document.forms['FrontPage_Form1'].MISC_AMT2.value = miscamt2;
/*
alert(document.forms['FrontPage_Form1'].MISC_CODE2.value);
alert(document.forms['FrontPage_Form1'].MISC_AMT2.value);
*/
}

function SaveShipData(form) {

SHIPNAME = form.SHIPNAME.value;
SHIPADD1 = form.SHIPADD1.value;
SHIPADD2 = form.SHIPADD2.value;
SHIPADD3 = form.SHIPADD3.value;
SHIPCITY = form.SHIPCITY.value;
SHIPSTATE = form.SHIPSTATE.selectedIndex;
SHIPZIP = form.SHIPZIP.value;
}
function scriptLoc() {

alert("this is \\nlhtml\\scripts\\script.js");

}

function divValue(id) {
var divObj = document.getElementById(id);
if (divObj) {
	alert(":" + divObj.value + ":");
}
	else
{
	alert("div id: " + id + " not found on page.");
}
}

function setNLVariables() {
setSessionID();
var validated = validNLSession();
if (validated == false) {
	setPageID("REQR_ID","NEW CUSTOMER");
	setPageID("AUTH_ID","");
	}
	else
	{
	clearDiv("nologin");
	}
}

function setPageID(idString,newValue) {
var allIDs = returnAttributes('id');
for(i=0;i<allIDs.length;i++) {
	var curID = allIDs[i].toUpperCase();
	if (curID.match(idString)) {
		var fld = document.getElementById(allIDs[i]);
		fld.value=newValue;
	}
}
}

function validNLSession() {
var curNLSession=getCookie("SESSION_NO");
	if (curNLSession == null) return false;
	if (curNLSession.length<2) return false;
	if (curNLSession.match("@VAR")) return false;
return true;
}

function clearDiv(id) {
if (document.getElementById(id)) {
  var divID = document.getElementById(id);
  divID.innerHTML = "";
  divID.parentNode.removeChild(divID);
}
}
 function alertDivContents(id) {
 if (document.getElementById(id)) {
  alert(document.getElementById(id).innerHTML);
 }
 else
 {
  alert('div not found');
 }
 }
 
 function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function updateGroupMaxValue(sMatch) {

if(!(sMatch)) return false;

var els = returnAttributes("id");

var iTotal = 0;

for(var i=0;i<els.length;i++) {
  var curEl = document.getElementById(els[i]);
  var curID = curEl.id;
  if(curID.match(sMatch) && curID != sMatch) {
    var curVal = parseFloat(curEl.value);
    if(!(isNaN(curVal)) && (curVal > iTotal)) {
      iTotal = curVal;
    }
  }
}

document.getElementById(sMatch).value = iTotal.toFixed(2);
document.getElementById(sMatch+"SUM").innerHTML = iTotal.toFixed(2);

if(document.getElementById(sMatch+"SPAN")) {

	if(iTotal>0) {
	 document.getElementById(sMatch+"SPAN").className="showdiv";
	 document.getElementById(sMatch+"SUM").className="showdiv";
  }
  else
  {
	
	 document.getElementById(sMatch+"SPAN").className="hidediv";
	 document.getElementById(sMatch+"SUM").className="hidediv";

  }

 }
}

function updateSumField(sMatch) {

if(!(sMatch)) return false;

var els = returnAttributes("id");

var iTotal = 0;

for(var i=0;i<els.length;i++) {
  var curEl = document.getElementById(els[i]);
  var curID = curEl.id;
  if(curID.match(sMatch) && curID != sMatch) {
    var curVal = parseFloat(curEl.value);
    if(!(isNaN(curVal))) {
      iTotal = iTotal + curVal;
    }
  }
}

document.getElementById(sMatch).value = iTotal.toFixed(2);
document.getElementById(sMatch+"SUM").innerHTML = iTotal.toFixed(2);

if(document.getElementById(sMatch+"SPAN")) {

	if(iTotal>0) {
	 document.getElementById(sMatch+"SPAN").className="showdiv";
	 document.getElementById(sMatch+"SUM").className="showdiv";
  }
  else
  {
	
	 document.getElementById(sMatch+"SPAN").className="hidediv";
	 document.getElementById(sMatch+"SUM").className="hidediv";

  }

 }
}

function removeTableRow(rowID) {
if (document.getElementById(rowID)) {
  var oldDiv = document.getElementById(rowID);
  oldDiv.parentNode.removeChild(oldDiv);
  }
}

function hideDiv(id) {
 if (document.getElementById(id)) {
    document.getElementById(id).className = "hidediv";

 }
}

function hideWithZero() {

var els = returnAttributes("id");
var subEls = els;
for(var i=0;i<els.length;i++) {
  if(document.getElementById(els[i])) {
    var curEl = document.getElementById(els[i]);
    var curID = curEl.id;
    var curVal = parseFloat(curEl.value);
    if(curEl.getAttribute("hidewithzero") != null)  {
      if((isNaN(curVal)) || (curVal <= 0)) {
        for(var sub=0;sub<subEls.length;sub++){
          if(document.getElementById(subEls[sub]))  {
            var subEl = document.getElementById(subEls[sub]);
            if(subEl.id.match(curID)) {
              hideDiv(subEl.id);
              removeTableRow(curID + "_ROW");
            }
          }
        }
      }
    }
  }
}
}

function showDiv(id) {
  if (document.getElementById(id)) {
    document.getElementById(id).className = "showdiv";
  }
}

function hideDiv(id) {
  if (document.getElementById(id)) {
    document.getElementById(id).className = "hidediv";
  }
}

function setRequired(id) {

  if (document.getElementById(id)) {
    document.getElementById(id).setAttribute("required", "true");
  }
}

function notRequired(id) {
  if (document.getElementById(id)) {
    document.getElementById(id).removeAttribute("required");
  }

}

function validateFormData(objName) {
var i = 0;
var sErrors = "";
for (i=0;i<objName.elements.length;i++) {
  var el = objName.elements[i].id;
  if (!el) {
    el = objName.elements[i].name;
    objName.elements[i].id = objName.elements[i].name;
    el = objName.elements[i].id;
  }
  var elType = document.getElementById(el).type;

  if (elType=="text" || elType=="password" || elType=="textarea" || elType=="select-one" || elType=="checkbox" || elType=="radio") {
      sResponse = validateData(el);
       if (sResponse != true) {
        document.getElementById(el).setAttribute("invalid","true");
        sErrors = sErrors + "\r\n" + sResponse;
      }
      else
      {
        document.getElementById(el).removeAttribute("invalid");
      }
      setBlurStyle(el);
    }
  }
if (sErrors.length > 0) {
  alert(sErrors);
  return false;
}
//form validated - add cookie for email
setOrderEmailCookie();
return true;
}

function validateInput(objName) {
var sValidated = validateData(objName.id);

if(sValidated != true) {
	alert(sValidated);
	return false;
}
}
function validateData(objName) {

//init vars for valiation properties
var sField = document.getElementById(objName);
var sValue = sField.value;
var sRequired = sField.getAttribute("required");
var iMinQty = sField.getAttribute("minqty");
var iMaxQty = sField.getAttribute("maxqty");
var sValidation = sField.getAttribute("vdate");
var sRefName = sField.getAttribute("RefName");
var iMinLen = sField.getAttribute("minlen");
var iMaxLen = sField.getAttribute("maxlen");
var sMatches = sField.getAttribute("matches");
var sValidated;

//alert(sField + " required:" + sRequired);
if (!(sRefName)) {
  sRefName = objName;
}

//required
if ((sRequired != null) && (sValue.length == "0")) {
  return sRefName + " is required.";
}

//validation method
if (sValidation == "phone" && sValue.length>0) {
  sValidated = checkInternationalPhone(sValue);
  if (!(sValidated)) return "Invalid Phone Number";
}

if (sValidation == "email" && sValue.length>0) {
  sValidated = validateEmail(sField);
  if (!(sValidated)) return "Invalid Email Address";
}
//minlen

if (iMinLen && parseFloat(sValue.length) < parseFloat(iMinLen)) {
  return sRefName + " must be at least " + iMinLen + " characters.";
}

//matches other field
if (sMatches && sValue != document.getElementById(sMatches).value) {
  return "The passwords do not match."
}

if (sValidation == "alphanumeric" && sValue.length>0) {
  sValidated = isAlphanumeric(sField);
  if (!(sValidated)) return sRefName + " must only contain letters (A-Z, a-z) and numbers (0-9).";
}

if (sValidation == "integer" && sValue.length>0) {
  sValidated = isInteger(sValue);
  if (!(sValidated)) {
	//sField.value = 0;
	sField.setAttribute("invalid","true");
	setBlurStyle(objName);
 	document.getElementById(objName).focus();
	return sRefName + " must be an integer.";
	}
	else
	{
	sField.removeAttribute("invalid");
	setBlurStyle(objName);
}
}
return true;
}

function setBlurStyle(id) {

var objName = document.getElementById(id);
var curClass = objName.className;
var newClass = curClass;

if(objName.getAttribute("loadvalue") == null) {
      newClass = curClass.substring(0,curClass.indexOf("_"));
}

if((objName.getAttribute("loadvalue") != objName.value) && (objName.getAttribute("loadvalue") != null)) {

  if(curClass.substring(0,curClass.indexOf("_")) == -1) {
    newClass = curClass + "_edited";
  }
  else
  {
  for(iCharCount=0;newClass.indexOf("_")!=-1;iCharCount++) {
    newClass = curClass.substring(0,curClass.indexOf("_"));
  }
  newClass = newClass + "_edited";
}
}
if(objName.getAttribute("loadvalue") == objName.value) {
  if(curClass.indexOf("_") == -1) {
  newClass = curClass;
  }
  else
  {
  newClass = curClass.substring(0,curClass.indexOf("_"));
  }
}

if(objName.getAttribute("invalid") == "true") {

  if(curClass.indexOf("_invalid") == -1) {
    newClass = curClass + "_invalid";
  }
  else
  {
    newClass = curClass;
  }
}

objName.className = newClass;
}

function setOrderEmailCookie() {

//Validate Email field
if(!(divExists("EMAIL_ADDR"))) {
	var el = document.getElementsByName("EMAIL_ADDR");
	el.id = "EMAIL_ADDR";
}

if(divExists("EMAIL_ADDR")) setCookie("EMAIL_ADDR", document.getElementById("EMAIL_ADDR").value);
}

function validateEmail(objName) {

var value = objName.value;
if(!(value) || value.length == 0 || value == null) return false;
    var sInvalid
		var at="@"
		var dot="."
		var lat=value.indexOf(at)
		var lstr=value.length
		var ldot=value.indexOf(dot)
		if (value.indexOf(at)==-1){
     var sInvalid = "true"
		}

		if (value.indexOf(at)==-1 || value.indexOf(at)==0 || value.indexOf(at)==lstr){
     var sInvalid = "true"
		}

		if (value.indexOf(dot)==-1 || value.indexOf(dot)==0 || value.indexOf(dot)==lstr){
      var sInvalid = "true"
		}

		 if (value.indexOf(at,(lat+1))!=-1){
      var sInvalid = "true"
		 }

		 if (value.substring(lat-1,lat)==dot || value.substring(lat+1,lat+2)==dot){
      var sInvalid = "true"
		 }

		 if (value.indexOf(dot,(lat+2))==-1){
      var sInvalid = "true"
		 }

		 if (value.indexOf(" ")!=-1){
      var sInvalid = "true"
		 }
     if (sInvalid) {
      if(objName.type != "hidden") {
      objName.blur();
      objName.focus();
      }
      return false
    }
  return true
}

function divExists(id) {
var divObj = document.getElementById(id);
  if (!(divObj)) return false;
  return true;
}