function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function FDK_Validate(FormName, stopOnFailure, AutoSubmit, ErrorHeader)
{
 var theFormName = FormName;
 var theElementName = "";
 if (theFormName.indexOf(".")>=0)  
 {
   theElementName = theFormName.substring(theFormName.indexOf(".")+1)
   theFormName = theFormName.substring(0,theFormName.indexOf("."))
 }
 var ValidationCheck = eval("document."+theFormName+".ValidateForm")
 if (ValidationCheck)  
 {
  var theNameArray = eval(theFormName+"NameArray")
  var theValidationArray = eval(theFormName+"ValidationArray")
  var theFocusArray = eval(theFormName+"FocusArray")
  var ErrorMsg = "";
  var FocusSet = false;
  var i
  var msg
    
 
        // Go through the Validate Array that may or may not exist
        // and call the Validate function for all elements that have one.
  if (String(theNameArray)!="undefined")
  {
   for (i = 0; i < theNameArray.length; i ++)
   {
    msg="";
    if (theNameArray[i].name == theElementName || theElementName == "")
    {
      msg = eval(theValidationArray[i]);
    }
    if (msg != "")
    {
     ErrorMsg += "\n"+msg;                   
     if (stopOnFailure == "1") 
     {
       if (theFocusArray[i] && !FocusSet)  
      {
       FocusSet=true;
       theNameArray[i].focus();
      }
      alert(ErrorHeader+ErrorMsg);
      document.MM_returnValue = false; 
      break;
     }
     else  
     {
      if (theFocusArray[i] && !FocusSet)  
      {
       FocusSet=true;
       theNameArray[i].focus();
      }
     }
    }
   }
  }
  if (ErrorMsg!="" && stopOnFailure != "1") 
  {
   alert(ErrorHeader+ErrorMsg);
  }
  document.MM_returnValue = (ErrorMsg==""); 
  if (document.MM_returnValue && AutoSubmit)  
  {
   eval("document."+FormName+".submit()")
  }
 }
}


function FDK_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 FDK_AddToValidateArray(FormName,FormElement,Validation,SetFocus)
{
    var TheRoot=eval("document."+FormName);
 
    if (!TheRoot.ValidateForm) 
    {
        TheRoot.ValidateForm = true;
        eval(FormName+"NameArray = new Array()")
        eval(FormName+"ValidationArray = new Array()")
        eval(FormName+"FocusArray = new Array()")
    }
    var ArrayIndex = eval(FormName+"NameArray.length");
    eval(FormName+"NameArray[ArrayIndex] = FormElement");
    eval(FormName+"ValidationArray[ArrayIndex] = Validation");
    eval(FormName+"FocusArray[ArrayIndex] = SetFocus");
 
}

function FDK_ValidateTargetEqualsSource(SourceElement,TargetElement,ClearFields,CaseSensitive,ErrorMsg)
{

	var msg = ""
	var sourceText = SourceElement.value;
	var targetText = TargetElement.value;
	var msgInvalid = ErrorMsg;
    
	if (!CaseSensitive)   {
	  sourceText = sourceText.toUpperCase();
	  targetText = targetText.toUpperCase();
	}
	
	if (sourceText != targetText)
	{
	  msg = msgInvalid
      if (ClearFields)     {
	    TargetElement.value = '';
	    SourceElement.value = '';
	  }
	}
	return msg	
}

function FDK_AddTargetEqualsSourceValidation(FormName,SourceElementName,TargetElementName,ClearFields,CaseSensitive,SetFocus,ErrorMsg)  {
  var ValString = "FDK_ValidateTargetEqualsSource("+SourceElementName+","+TargetElementName+","+ClearFields+","+CaseSensitive+","+ErrorMsg+")"
  FDK_AddToValidateArray(FormName,eval(SourceElementName),ValString,SetFocus)
}

function FDK_ValidateURL(FormElement,Required,ErrorMsg)
{
   var msg = "";
   var val = FormElement.value;
   var msgInvalid = ErrorMsg;
   var i;
   var lcase ;   
   var protocols = "ftp://,http://,javascript:,file://,gopher://,https://,mailto:,rlogin://,shttp://,snews://,telnet://,tn3270://,wais://";
   var protos = protocols.split(",");

  	var theLen = FDK_StripChars(" ",val).length;
	  if (theLen == 0)	
		  if (!Required) return "";		
		  else return msgInvalid;


   lcase = FDK_Trim(val.toLowerCase());

   msg = msgInvalid;

   for (i = 0; i < protos.length; i++)
   {
	     if (lcase.indexOf(protos[i]) == 0 )
	     {		
         msg = ""
         FormElement.value=protos[i] + FDK_Trim(val).substring(protos[i].length,val.length)
		       break;
	     }
   }

   return msg;
}

function FDK_Trim(theString)
{
 var i,firstNonWhite

 if (FDK_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)

}

function FDK_AddURLValidation(FormName,FormElementName,Required,SetFocus,ErrorMsg)  {
  var ValString = "FDK_ValidateURL("+FormElementName+","+Required+","+ErrorMsg+")"
  FDK_AddToValidateArray(FormName,eval(FormElementName),ValString,SetFocus)
}

function FDK_ValidateAlphaNum(FormElement,Required,ErrorMsg)
{
	var msg = "";
	var i, m, s, firstNonWhite
	var theString = FormElement.value;
 	var msgInvalid = ErrorMsg;

	if (FDK_StripChars(" ",theString).length == 0)	     {
		if (!Required)       {
          return "";		
        }
		else       {
          return msgInvalid;
        }
    }
	//Strip spaces off of the sides of the string
 	theString = FDK_Trim(theString);

    for (var n=0; n<theString.length; n++)     {
      theChar = theString.substring(n,n+1);
      if (!FDK_AllInRange("0","9",theChar) && !FDK_AllInRange("A","Z",theChar.toUpperCase()) && !(theChar == " "))     {
        return msgInvalid;
      }
    }

    return "";
}

function FDK_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 FDK_AddAlphaNumericValidation(FormName,FormElementName,Required,SetFocus,ErrorMsg)  {
  var ValString = "FDK_ValidateAlphaNum("+FormElementName+","+Required+","+ErrorMsg+")"
  FDK_AddToValidateArray(FormName,eval(FormElementName),ValString,SetFocus)
}


var ShipFirst = "";
var ShipLast = "";
var ShipAddress1 = "";
var ShipAddress2 = "";
var ShipPhone = "";
var ShipCity = "";
var ShipState = "";
var ShipStateIndex = 0;
var ShipZip = "";


function InitSaveVariables(form) {
    ShipFirst = form.ctl00$ContentPlaceHolder1$ShipFirst.value;
    ShipLast = form.ctl00$ContentPlaceHolder1$ShipLast.value;
    ShipAddress1 = form.ctl00$ContentPlaceHolder1$ShipAddress1.value;
    ShipAddress2 = form.ctl00$ContentPlaceHolder1$ShipAddress2.value;
    ShipPhone = form.ctl00$ContentPlaceHolder1$ShipPhone.value;
    ShipCity = form.ctl00$ContentPlaceHolder1$ShipCity.value;
    ShipZip = form.ctl00$ContentPlaceHolder1$ShipZip.value;
    ShipStateIndex = form.ctl00$ContentPlaceHolder1$ShipState.selectedIndex;
    ShipState = form.ctl00$ContentPlaceHolder1$ShipState[ShipStateIndex].value;

}

function ShipToBillPerson(form) {
if (form.copy.checked) {
InitSaveVariables(form);
form.ctl00$ContentPlaceHolder1$ShipFirst.value = form.ctl00$ContentPlaceHolder1$BillFirst.value;
form.ctl00$ContentPlaceHolder1$ShipLast.value = form.ctl00$ContentPlaceHolder1$BillLast.value;
form.ctl00$ContentPlaceHolder1$ShipAddress1.value = form.ctl00$ContentPlaceHolder1$BillAddress1.value;
form.ctl00$ContentPlaceHolder1$ShipAddress2.value = form.ctl00$ContentPlaceHolder1$BillAddress2.value;
form.ctl00$ContentPlaceHolder1$ShipPhone.value = form.ctl00$ContentPlaceHolder1$BillPhone.value;
form.ctl00$ContentPlaceHolder1$ShipCity.value = form.ctl00$ContentPlaceHolder1$BillCity.value;
form.ctl00$ContentPlaceHolder1$ShipZip.value = form.ctl00$ContentPlaceHolder1$BillZip.value;
form.ctl00$ContentPlaceHolder1$ShipState.selectedIndex = form.ctl00$ContentPlaceHolder1$BillState.selectedIndex;

}
else {
    form.ctl00$ContentPlaceHolder1$ShipFirst.value = ShipFirst;
    form.ctl00$ContentPlaceHolder1$ShipLast.value = ShipLast;
    form.ctl00$ContentPlaceHolder1$ShipAddress1.value = ShipAddress1;
    form.ctl00$ContentPlaceHolder1$ShipAddress2.value = ShipAddress2;
    form.ctl00$ContentPlaceHolder1$ShipPhone.value = ShipPhone;
    form.ctl00$ContentPlaceHolder1$ShipCity.value = ShipCity;
    form.ctl00$ContentPlaceHolder1$ShipZip.value = ShipZip;
    form.ctl00$ContentPlaceHolder1$ShipState.selectedIndex = ShipStateIndex;

   }
}
//  End -->

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}


function changeTotal(chainAmount, chainType) { //v6.0
    var objTotal = document.getElementById('ctl00_ContentPlaceHolder1_lblTotal');
    var objChain = document.getElementById('ctl00_ContentPlaceHolder1_lblChain');
    var objPrice = document.getElementById('ctl00_ContentPlaceHolder1_lblPrice');

    //var totalValue = objTotal.innerHTML * 1
    //var chainValue = objChain.innerHTML * 1
    var priceValue = objPrice.innerHTML * 1
    
    //alert(priceValue);

    if (chainAmount == 0) {
        objChain.innerHTML = ''
        objTotal.innerHTML = (priceValue + 7.95).toFixed(2);
        
        
    } else {
    //alert("else");
        objTotal.innerHTML = (priceValue + chainAmount + 7.95).toFixed(2);
        objChain.innerHTML = '<br /><br />' + chainType + ' $' + chainAmount;
    }
    
    
        
    
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
