// Support Script (718)
// These date functions work for Nav 3 and above.

function getDayName(d)
{   
   var theDay = d.getDay()

   if (theDay == 0) 
            return "Sunday"
   if (theDay == 1) 
            return "Monday"
   if (theDay == 2) 
            return "Tuesday"
   if (theDay == 3) 
            return "Wednesday"
   if (theDay == 4) 
            return "Thursday"
   if (theDay == 5) 
            return "Friday"
   if (theDay == 6) 
            return "Saturday"
}

function getFullYear(d)
{
   var y = d.getYear();

   if (y < 2000) 
   {
        y += 1900
   }

   return y
}

function getMonthName(d)
{
   var theMonth = d.getMonth()
   
   if (theMonth == 0) 
            return "January"
   if (theMonth == 1) 
            return "February"
   if (theMonth == 2) 
            return "March"
   if (theMonth == 3) 
            return "April"
   if (theMonth == 4) 
            return "May"
   if (theMonth == 5) 
            return "June"
   if (theMonth == 6) 
            return "July"
   if (theMonth == 7) 
            return "August"
   if (theMonth == 8) 
            return "September"
   if (theMonth == 9) 
            return "October"
   if (theMonth == 10) 
            return "November"
   if (theMonth == 11) 
            return "December"
}

// A helper function for the other functions in this
// support script

function DateSupportReplaceAwithBinC(aa,bb,cc)
{
 var a = aa + ""
 var b = bb + ""
 var c = cc + ""
	var i = c.indexOf(a);
	var l = b.length;
	while (i != -1)	
 {
		c = c.substring(0,i) + b + c.substring(i + a.length,c.length);
  i += l
		i = c.indexOf(a,i);
	}
	return c;
}


function ReplaceTokensWithTimeDate(strIn, leadingZeroes, zoneDiff)
{
    var strOut = strIn
    var now = new Date()
    var d = new Date(now.getTime() + zoneDiff)

    var theTime = ""
    var theHours
    var theMinutes
    var theSeconds
    var ampm = "am"

    theHours = d.getHours()
    if (theHours >= 12)
    {
        ampm = "pm"
    }
    if (theHours > 12)
    {
         theHours -= 12   
    }

    theMinutes = d.getMinutes()
    if (leadingZeroes, theMinutes < 10)
    {
        theMinutes = "0" + theMinutes
    }
    
    theTime = theHours + ":" + theMinutes + ampm

    theSeconds = d.getSeconds()
    if (leadingZeroes && theSeconds < 10)
    {
        theSeconds = "0" + theSeconds
    }

    strOut = DateSupportReplaceAwithBinC("[monthname]", getMonthName(d), strOut)
    strOut = DateSupportReplaceAwithBinC("[monthnumber]", d.getMonth(d) + 1, strOut)
    strOut = DateSupportReplaceAwithBinC("[dayname]", getDayName(d), strOut)
    strOut = DateSupportReplaceAwithBinC("[daynumber]", d.getDate(), strOut)
    strOut = DateSupportReplaceAwithBinC("[year]", getFullYear(d), strOut)
    strOut = DateSupportReplaceAwithBinC("[time]", theTime, strOut)
    strOut = DateSupportReplaceAwithBinC("[hours]", theHours, strOut)
    strOut = DateSupportReplaceAwithBinC("[minutes]", theMinutes, strOut)
    strOut = DateSupportReplaceAwithBinC("[seconds]", theSeconds, strOut)
    strOut = DateSupportReplaceAwithBinC("[ampm]", ampm, strOut)

    return strOut
}


// This function takes the name of an edit box and a 
// flag that says whether or not to pad single digit 
// minutes and seconds with a zero.  It provides a 
// real time clock in an edit box.
//
function SetTimeText(strElementName, blnLeadingZeroes, zoneDiff)
{
  var theObj = eval(strElementName)

  theObj.setText(ReplaceTokensWithTimeDate(theObj.ContentString,blnLeadingZeroes, zoneDiff))
  setTimeout("SetTimeText('" + strElementName + "'," + blnLeadingZeroes + "," + zoneDiff + ")",1000)
}

// Returns a JavaScript Date object
// Expected format of date is 8/17/1998
// Expected format of time is 12:02am or 1:09pm
// Gives an error message if format is wrong.
//
function MakeDate(strDate, strTime)
{

 var tempDate = new Date(strDate)
 var strFormatted = getMonthName(tempDate) + " " + tempDate.getDate() + ", " + getFullYear(tempDate)

	var colonPos = strTime.indexOf(":")
	var ampmPos = strTime.indexOf("am")
	if (ampmPos == -1)
		ampmPos = strTime.indexOf("AM")
    if (ampmPos == -1)
		ampmPos = strTime.indexOf("pm")
	if (ampmPos == -1)
		ampmPos = strTime.indexOf("PM")

	// assume format of time is okay
	var theHours = strTime.substring(0,colonPos)
	var theMinutes = strTime.substring(colonPos + 1, ampmPos)
	var ampm = strTime.substring(ampmPos, strTime.length)
	ampm = ampm.toUpperCase()

	if (ampm == "PM")
	{
		if (theHours != "12")
		{
			theHours += 12
		}
	}
	else
	{
		if (theHours == "12")
		{
			theHours = "0"
		}
	}

	var outDate = new Date(strFormatted + " " + theHours + ":" + theMinutes)
	return outDate
}

// Support Script (712)
function AddToValidateArray(strElementName)
{
    var strName = strElementName

    if (!document.ValidateArray) 
    {
        document.ValidateArray = new Array
    }

    document.ValidateArray[document.ValidateArray.length] = strName
}

// Support Script (582)
function ValidateNonBlank()
{
  var msg = "";
  var val = this.getText();  

  if (StripChars(" \n\t\r",val).length == 0)
  {
    if (Trim(this.ErrorMsg) != "")
      msg = "Required field. " + this.ErrorMsg
    else
      msg = "Required field. Please enter an appropriate value."
  }

  return msg;
}

// Support Script (737)
function StripChars(theFilter,theString)
{
	var strOut,i,curChar

	strOut = ""
	for (i=0;i < theString.length; i++)
	{		
		curChar = theString.charAt(i)
		if (theFilter.indexOf(curChar) < 0)	// if it's not in the filter, send it thru
			strOut += curChar		
	}	
	return strOut
}

function AllInRange(x,y,theString)
{
	var i, curChar
	
	for (i=0; i < theString.length; i++)
	{
		curChar = theString.charAt(i)
		if (curChar < x || curChar > y) //the char is not in range
			return false
	}
	return true
}


function reformat (s)
{
    var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) 
           resultString += arg;
       else 
       {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function Trim(theString)
{
 var i,firstNonWhite

 if (StripChars(" \n\r\t",theString).length == 0 ) return ""

	i = -1
	while (1)
	{
		i++
		if (theString.charAt(i) != " ")
			break	
	}
	firstNonWhite = i
	//Count the spaces at the end
	i = theString.length
	while (1)
	{
		i--
		if (theString.charAt(i) != " ")
			break	
	}	

	return theString.substring(firstNonWhite,i + 1)

}
// Support Script (747)
function subAwithBinC(a,b,c)
{

	var i = c.indexOf(a);
	var l = b.length;

	while (i != -1)	{
		c = c.substring(0,i) + b + c.substring(i + a.length,c.length);
		i = c.indexOf(a,i);
	}
	return c;

}
// Support Script (688)
function Validate(stopOnFailure)
{
	var ErrorMsg = "";
	var i
	var msg
	var tofocus = true;
	var ErrorMsg = "";
	
	// Go through the Validate Array that may or may not exist
	// and call the Validate function for all elements that have one.
	if (document.ValidateArray)
	{
		for (i = 0; i < document.ValidateArray.length; i ++)
		{
			msg = eval( document.ValidateArray[i] + ".Validate()")
			if (msg != "")
			{
				ErrorMsg += "\n\n" + document.ValidateArray[i] + ":  " + msg;
				if (tofocus) 
				{
					eval(document.ValidateArray[i] + ".focus()")
					tofocus = false;
				}
				
				if (stopOnFailure == "1") return ErrorMsg;
			}
  	}
  }
	return ErrorMsg;
}

function document_onLoad() {
Recordset49_firstname.Validate=ValidateNonBlank;
Recordset49_firstname.ErrorMsg = "First Name Required"
AddToValidateArray("Recordset49_firstname")
Recordset49_lastname.Validate=ValidateNonBlank;
Recordset49_lastname.ErrorMsg = "Last Name Required"
AddToValidateArray("Recordset49_lastname")
Recordset49_emailaddress.Validate=ValidateNonBlank;
Recordset49_emailaddress.ErrorMsg = "Email Address Required"
AddToValidateArray("Recordset49_emailaddress")
Recordset49_subject.Validate=ValidateNonBlank;
Recordset49_subject.ErrorMsg = "Subject required"
AddToValidateArray("Recordset49_subject")
Recordset49_message.Validate=ValidateNonBlank;
Recordset49_message.ErrorMsg = "Message required"
AddToValidateArray("Recordset49_message")
 }
function document_onUnLoad() {
if (ChildWindow["1"] != null) {
ChildWindow["1"].close();
}
if (ChildWindow["2"] != null) {
ChildWindow["2"].close();
}
if (ChildWindow["3"] != null) {
ChildWindow["3"].close();
}
if (ChildWindow["4"] != null) {
ChildWindow["4"].close();
}
 }
function Text4_Inline(html) {
document.write(ReplaceTokensWithTimeDate(html,parseInt("1"),0))
 }
function _Text4_Inline(html) { if (Text4) return Text4.Inline(html); }
function Text23_Inline(html) {
document.write(ReplaceTokensWithTimeDate(html,parseInt("1"),0))
 }
function _Text23_Inline(html) { if (Text23) return Text23.Inline(html); }
function Recordset49_Insert__onClick() {
var addChar = "?" 
var j
var okToSubmit = false;

if ("".length > 1)
{
    Form1T0.setAction(subAwithBinC(" ", "%20", ""));
}

// execute the onSubmit() event handler and try to 
// determine if it already validated the form
Result = Form1T0.onSubmit();

//   If there is no onSubmithander the return value is null
//   If there is a validation handler it returns true to submit
//   or false to not submit
if (Result==null)  // there is no validation already defined
{
    if ("1" == "1")
    {
        Result = Validate("0"); // don't stop on first error
        if (Result == "") okToSubmit = true;
        else alert("The form could not be submitted:" + Result);
    }
    else okToSubmit = true;
}
else // there is a validation already defined
{
    if (Result==true)
        okToSubmit = true;
}

if (okToSubmit) 
{
    // We have to
    // put the source in the query string so the generic database contracts
    // still work.

    // NOTE: this only works if the method of the form is POST


    act = Form1T0.getAction();
    if (act.indexOf("?") != -1)
    {    
        addChar = "&"
    }

    act += addChar + "Recordset49_Insert=1"
    Form1T0.setAction(act);


    Form1T0.submit();
}
 }
function _Recordset49_Insert__onClick() { if (Recordset49_Insert) return Recordset49_Insert.onClick(); }
function Image13_onClick() {
var options="";
options+="status="+(("0"=="1")?"yes":"no")
options+=",directories="+(("0"=="1")?"yes":"no")
options+=",location="+(("0"=="1")?"yes":"no")
options+=",toolbar="+(("1"=="1")?"yes":"no")
options+=",menubar="+(("1"=="1")?"yes":"no")
options+=",scrollbars="+(("1"=="1")?"yes":"no")
options+=",resizable="+(("0"=="1")?"yes":"no")

if (parseInt("800")  > 0) options+=",width="+"800"
if (parseInt("500") > 0) options+=",height="+"500"

if (parseInt("100") >= 0)
{
	options+=",top="+"100"
	options+=",screenY="+"100"
}
if (parseInt("100") >= 0)
{
	options+=",left="+"100"
	options+=",screenX="+"100"
}



ChildWindow["1"] = window.open("http://www.kingbottling.com/marketplace.asp","NewWindow",options);
ChildWindow["1"].focus();
 }
function _Image13_onClick() { if (Image13) return Image13.onClick(); }
function Image14_onClick() {
var options="";
options+="status="+(("0"=="1")?"yes":"no")
options+=",directories="+(("0"=="1")?"yes":"no")
options+=",location="+(("0"=="1")?"yes":"no")
options+=",toolbar="+(("1"=="1")?"yes":"no")
options+=",menubar="+(("1"=="1")?"yes":"no")
options+=",scrollbars="+(("1"=="1")?"yes":"no")
options+=",resizable="+(("0"=="1")?"yes":"no")

if (parseInt("800")  > 0) options+=",width="+"800"
if (parseInt("500") > 0) options+=",height="+"500"

if (parseInt("100") >= 0)
{
	options+=",top="+"100"
	options+=",screenY="+"100"
}
if (parseInt("100") >= 0)
{
	options+=",left="+"100"
	options+=",screenX="+"100"
}



ChildWindow["2"] = window.open("http://www.kingbottling.com/homeoffice.asp","NewWindow",options);
ChildWindow["2"].focus();
 }
function _Image14_onClick() { if (Image14) return Image14.onClick(); }
function Image15_onClick() {
var options="";
options+="status="+(("0"=="1")?"yes":"no")
options+=",directories="+(("0"=="1")?"yes":"no")
options+=",location="+(("0"=="1")?"yes":"no")
options+=",toolbar="+(("1"=="1")?"yes":"no")
options+=",menubar="+(("1"=="1")?"yes":"no")
options+=",scrollbars="+(("1"=="1")?"yes":"no")
options+=",resizable="+(("0"=="1")?"yes":"no")

if (parseInt("800")  > 0) options+=",width="+"800"
if (parseInt("500") > 0) options+=",height="+"500"

if (parseInt("100") >= 0)
{
	options+=",top="+"100"
	options+=",screenY="+"100"
}
if (parseInt("100") >= 0)
{
	options+=",left="+"100"
	options+=",screenX="+"100"
}



ChildWindow["3"] = window.open("http://www.kingbottling.com/privatelabel.asp","NewWindow",options);
ChildWindow["3"].focus();
 }
function _Image15_onClick() { if (Image15) return Image15.onClick(); }
function Image16_onClick() {
var options="";
options+="status="+(("0"=="1")?"yes":"no")
options+=",directories="+(("0"=="1")?"yes":"no")
options+=",location="+(("0"=="1")?"yes":"no")
options+=",toolbar="+(("1"=="1")?"yes":"no")
options+=",menubar="+(("1"=="1")?"yes":"no")
options+=",scrollbars="+(("1"=="1")?"yes":"no")
options+=",resizable="+(("0"=="1")?"yes":"no")

if (parseInt("800")  > 0) options+=",width="+"800"
if (parseInt("500") > 0) options+=",height="+"500"

if (parseInt("100") >= 0)
{
	options+=",top="+"100"
	options+=",screenY="+"100"
}
if (parseInt("100") >= 0)
{
	options+=",left="+"100"
	options+=",screenX="+"100"
}



ChildWindow["4"] = window.open("http://www.kingbottling.com/distributors.asp","NewWindow",options);
ChildWindow["4"].focus();
 }
function _Image16_onClick() { if (Image16) return Image16.onClick(); }

