function formatCurrency(num)
 {
   var customerCurrencySymbol = "$"
   num = num.toString().replace(/\$|\,/g,'');
   
   if(isNaN(num))
     num = "0";
	 sign = (num == (num = Math.abs(num)));

	 num = Math.floor(num*100+0.00000000001);
	 cents = num%100;
	 num = Math.floor(num/100).toString();
	 if(cents<10)
	   cents = "0" + cents;

	   for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	     num = num.substring(0,num.length-(4*i+3))+','+
		 num.substring(num.length-(4*i+3));
		 return (((sign)?'':'-') + customerCurrencySymbol  + num + '.' + cents);
}

function CalcPrice()
{
  var total_price = 0;
  var NumOptions = 0;
  var blnEmbroidery = false;
  var blnLogo = false;
    
  var ie4=document.all
  var ns6=document.getElementById&&document.all
  var ns4=document.layers
  var ns7=document.getElementById&&document.all
 
  if (frmSubmitOrder.chkProduct.length == undefined)
  {
     if (frmSubmitOrder.chkProduct.checked)
	 {
     total_price += parseFloat(frmSubmitOrder.price.value)
	 }
  }else{

     for (i = 0; i < frmSubmitOrder.chkProduct.length; i++)
     {
       if (frmSubmitOrder.chkProduct[i].checked)
	   {
	     total_price += parseFloat(frmSubmitOrder.price[i].value);
	   }
     }
  }


   /*Add in the cost for embroidery*/ 
  if (frmSubmitOrder.chkEmb_Placement.length == undefined)
  {
     if (frmSubmitOrder.chkEmb_Placement.checked)
	 {
     total_price += parseFloat(frmSubmitOrder.Emb_Price.value)
	 blnEmbroidery = true;
	 }
  }else{

     for (i = 0; i < frmSubmitOrder.chkEmb_Placement.length; i++)
     {
       if (frmSubmitOrder.chkEmb_Placement[i].checked)
	   {
	     total_price += parseFloat(frmSubmitOrder.Emb_Price[i].value);
		 blnEmbroidery = true;
	   }
     }
  }
  
  /* Add in cost of logo or applique embroidery  */
 /* if (document.frmSubmitOrder.selLogo.options[document.frmSubmitOrder.selLogo.selectedIndex].value != '')
  {  
     total_price += parseFloat(document.frmSubmitOrder.Logo_Price.value);
  }
*/

  /* Add in cost of logo or applique embroidery  */
  if (frmSubmitOrder.chkLogo_Placement.length == undefined)
  {
     if (frmSubmitOrder.chkLogo_Placement.checked)
	 {
     total_price += parseFloat(frmSubmitOrder.Logo_Price.value)
	 blnLogo = true;
	 }
  }else{

     for (i = 0; i < frmSubmitOrder.chkLogo_Placement.length; i++)
     {
       if (frmSubmitOrder.chkLogo_Placement[i].checked)
	   {
	     total_price += parseFloat(frmSubmitOrder.Logo_Price.value);
	 	 blnLogo = true;
	   }
     }
  }
  
  if (blnEmbroidery == true && blnLogo == true) 
  {
     toggleLayer('Logo_Emb_Placement', 'block');
	 document.getElementById('chkLogoAbove').checked = true;
	 document.frmSubmitOrder.blnLogoAndEmb.value = true;
  }else{
     toggleLayer('Logo_Emb_Placement', 'none');
	 document.getElementById('chkLogoAbove').checked = false;	 
	 document.frmSubmitOrder.blnLogoAndEmb.value = false;
  }
  
  frmSubmitOrder.Total.value = formatCurrency(total_price);  
  frmSubmitOrder.Total2.value = formatCurrency(total_price);    
}

function Color_Click(intIndex, strPath)
{
  document.frmSubmitOrder.selColor.selectedIndex = intIndex-1;
 /* document.frmSubmitOrder.imgColor.src = '/images/autofloormatimages/ultimats/colors/' + document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].value + '-' + document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].innerHTML + '.jpg';*/
  document.frmSubmitOrder.imgColor.src = strPath + document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].innerHTML + '.jpg';
  document.getElementById("ColorDesc").innerHTML = document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].innerHTML;
}

function ColorChange(strPath)
{
  document.frmSubmitOrder.imgColor.src = strPath + document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].innerHTML + '.jpg';
  document.getElementById("ColorDesc").innerHTML = document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].innerHTML;
}

function Embroidery_Color_Click(intIndex, strPath)
{
  document.frmSubmitOrder.selEmbroideryColor.selectedIndex = intIndex-1;
 /* document.frmSubmitOrder.imgColor.src = '/images/autofloormatimages/ultimats/colors/' + document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].value + '-' + document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].innerHTML + '.jpg';*/
  document.frmSubmitOrder.imgEmbroideryColor.src = strPath + document.frmSubmitOrder.selEmbroideryColor.options[document.frmSubmitOrder.selEmbroideryColor.selectedIndex].innerHTML + '.jpg';
  document.getElementById("EmbroideryColorDesc").innerHTML = document.frmSubmitOrder.selEmbroideryColor.options[document.frmSubmitOrder.selEmbroideryColor.selectedIndex].innerHTML;
}

function Embroidery_ColorChange(strPath)
{
  document.frmSubmitOrder.imgEmbroideryColor.src = strPath + document.frmSubmitOrder.selEmbroideryColor.options[document.frmSubmitOrder.selEmbroideryColor.selectedIndex].innerHTML + '.jpg';
  document.getElementById("EmbroideryColorDesc").innerHTML = document.frmSubmitOrder.selEmbroideryColor.options[document.frmSubmitOrder.selEmbroideryColor.selectedIndex].innerHTML;
}
  
function LogoEmbroidery_Color_Click(intIndex, strPath)
{
  document.frmSubmitOrder.selLogoEmbroideryColor.selectedIndex = intIndex-1;
 /* document.frmSubmitOrder.imgColor.src = '/images/autofloormatimages/ultimats/colors/' + document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].value + '-' + document.frmSubmitOrder.selColor.options[document.frmSubmitOrder.selColor.selectedIndex].innerHTML + '.jpg';*/
  document.frmSubmitOrder.imgLogoEmboideryColor.src = strPath + document.frmSubmitOrder.selLogoEmbroideryColor.options[document.frmSubmitOrder.selLogoEmbroideryColor.selectedIndex].innerHTML + '.jpg';
  document.getElementById("LogoEmbroideryColorDesc").innerHTML = document.frmSubmitOrder.selLogoEmbroideryColor.options[document.frmSubmitOrder.selLogoEmbroideryColor.selectedIndex].innerHTML;
}

function LogoEmbroidery_ColorChange(strPath)
{
  document.frmSubmitOrder.imgLogoEmboideryColor.src = strPath + document.frmSubmitOrder.selLogoEmbroideryColor.options[document.frmSubmitOrder.selLogoEmbroideryColor.selectedIndex].innerHTML + '.jpg';
  document.getElementById("LogoEmbroideryColorDesc").innerHTML = document.frmSubmitOrder.selLogoEmbroideryColor.options[document.frmSubmitOrder.selLogoEmbroideryColor.selectedIndex].innerHTML;
}  
  
function Font_Change(strPath)
{
  if (document.frmSubmitOrder.selFont.options[document.frmSubmitOrder.selFont.selectedIndex].value == '')
  {
     document.frmSubmitOrder.imgFont.style.display = 'none';
  }
  else
  {
     document.frmSubmitOrder.imgFont.style.display = '';
  }
  
  document.frmSubmitOrder.imgFont.src = strPath + document.frmSubmitOrder.selFont.options[document.frmSubmitOrder.selFont.selectedIndex].value + '.jpg';
  document.getElementById("EmbDesc").innerHTML = document.frmSubmitOrder.selFont.options[document.frmSubmitOrder.selFont.selectedIndex].value;
}

function Logo_Change(strPath)
{
  if (document.frmSubmitOrder.selLogo.options[document.frmSubmitOrder.selLogo.selectedIndex].value == '')
  {
     document.frmSubmitOrder.imgLogo.style.display = 'none';
	 
	 /*document.frmSubmitOrder.Logo_ID.value = '';*/
	 var strLogo = document.frmSubmitOrder.selLogo.options[document.frmSubmitOrder.selLogo.selectedIndex].value;
	 var intPos=strLogo.indexOf('-');
	 var intPos2=strLogo.indexOf('(');
	 var intPos3=strLogo.indexOf(')');
	 var strLogoImage;
	 var intProdID;	 
	 var strAvailableColors;	 
	 strLogoImage = strLogo.substr (0, intPos2-1);	 
	 intProdID = strLogo.substr(intPos+1, strLogo.length-intPos);
	 strAvailableColors = strLogo.substr(intPos2+1,(intPos3-intPos2)-1)

  }
  else
  {
  
     document.frmSubmitOrder.imgLogo.style.display = '';
	 var strLogo = document.frmSubmitOrder.selLogo.options[document.frmSubmitOrder.selLogo.selectedIndex].value;
	 var intPos=strLogo.indexOf('-');
	 var intPos2=strLogo.indexOf('(');
	 var intPos3=strLogo.indexOf(')');
	 var strLogoImage;
	 var intProdID;	 
	 var strAvailableColors;
	 strLogoImage = strLogo.substr (0, intPos2);	 
	 intProdID = strLogo.substr(intPos+1, strLogo.length-intPos);
	 strAvailableColors = strLogo.substr(intPos2+1,(intPos3-intPos2)-1)	 
  }
  
  document.frmSubmitOrder.Logo_ID.value = intProdID;
  document.frmSubmitOrder.imgLogo.src = strPath + strLogoImage + '.jpg';
  document.getElementById("LogoDesc").innerHTML = strLogoImage;
  
  if (strAvailableColors != 'ANY')
  {
    document.frmSubmitOrder.selLogoEmbroideryColor.selectedIndex = 0;
    document.frmSubmitOrder.selLogoEmbroideryColor.disabled=true;
	toggleLayer('Logo_Color', 'none');
	toggleLayer('Logo_Color2', 'none');
	toggleLayer('Logo_Color3', 'none');
	toggleLayer('Logo_Color4', 'none');
	toggleLayer('LogoEmbroideryColorDesc', 'none');

	
  }else{
    document.frmSubmitOrder.selLogoEmbroideryColor.disabled=false;     
	toggleLayer('Logo_Color', 'block');
	toggleLayer('Logo_Color2', 'block');
	toggleLayer('Logo_Color3', 'block');
	toggleLayer('Logo_Color4', 'block');
	toggleLayer('LogoEmbroideryColorDesc', 'block');
	
  }
  
}


function Validate()
{
   if (Validate_Product_Selection() == true && Validate_Embroidery_Selection() == true && 
       Validate_Logo_Selection() == true)
      {
	    return true;
	  }else{
	    return false;
	  }
 
}


function Validate_Product_Selection()
{   
     
   if (frmSubmitOrder.chkProduct.length != undefined)
    {
	
      for (i = 0; i < frmSubmitOrder.chkProduct.length; i++)
      {
        if (frmSubmitOrder.chkProduct[i].checked)
	    {
	      return true;
	    }
      }

	}else{
	  if (frmSubmitOrder.chkProduct.checked)
	   {
	     return true;
	   } 
	}
	 
	 alert('You must select a product!');
	 return false;
	 
}  


function Validate_Embroidery_Selection()
{   
   var Emb_Text;
   var blnSelected = false;
   
   if (frmSubmitOrder.chkEmb_Placement.length > 0)
     {
	    for (i = 0; i < frmSubmitOrder.chkEmb_Placement.length; i++)
		  {
             Emb_Text = 'frmSubmitOrder.txtSeat_Text_' + frmSubmitOrder.chkEmb_Placement[i].value + '.value';
             if (frmSubmitOrder.chkEmb_Placement[i].checked && eval(Emb_Text).length == 0)
	         {
                alert('You must enter your personalized text since you have indicated that you want your mats embroidered!');
				return false;
	         } 
			 
			 if (frmSubmitOrder.chkEmb_Placement[i].checked)
			   {
			      blnSelected = true;
			   }
			 
		  }
		
       if (document.frmSubmitOrder.selFont.options[document.frmSubmitOrder.selFont.selectedIndex].value == '' && blnSelected == true)
	     {
		    alert('You must select a font style for your embroidery!');
			return false;
		 }
		  
	 } 

   return true;

} 

function Validate_Logo_Selection()
{   
   var Emb_Text;
   var blnResult = false;
   
     for (i = 0; i < frmSubmitOrder.chkLogo_Placement.length; i++)
     {
       if (frmSubmitOrder.chkLogo_Placement[i].checked)
	   {
	      var blnResult = true;
       }
     }
	 
	 if (blnResult && document.frmSubmitOrder.selLogo.options[document.frmSubmitOrder.selLogo.selectedIndex].value == '')
	 {
	    alert('You must select a logo!');
		return false;
	 }

   return true;

} 


function toggleLayer(whichLayer,blnDisplay)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
style2.display = blnDisplay;
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = blnDisplay;
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = blnDisplay;
}
}
