﻿function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function tmt_findObj(n){
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	}else{x=document.getElementById(n)}return x;
}
function MM_showHideLayers() { //v3.0A Modified by Al Sparber and Massimo Foti for NN6 Compatibility
  var i,p,v,obj,args=MM_showHideLayers.arguments;if(document.getElementById){
   for (i=0; i<(args.length-2); i+=3){ obj=tmt_findObj(args[i]);v=args[i+2];
   v=(v=='show')?'visible':(v='hide')?'hidden':v;
   if(obj)obj.style.visibility=v;}} else{
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function SetPreviewColor(id, index){
    if (document.getElementById('BlindColor'))
    {
        var colors = id.split('|');
	    var colorID = colors[0];
	    var eleColorImage = document.getElementById('BlindColor');
    	
	    eleColorImage.src = "../images/colors/large/" + colorID + ".jpg";
	    
	    for(var x=0; x<document.getElementById('colorid').options.length; x++)
	    {
	        if (document.getElementById('colorid').options[x].value == id)
	        {
	            document.getElementById('colorid').selectedIndex = x;
	        }
	    }
	}
	if (document.getElementById('FoamTileColor'))
	{
	    var colors = id.split('|');
	    var colorID = colors[0];
	    var eleColorImage = document.getElementById('FoamTileColor');
    	
	    eleColorImage.src = "../../images/colors/large/" + colorID + ".jpg";
	    
	    for(var x=0; x<document.getElementById('colorid').options.length; x++)
	    {
	        if (document.getElementById('colorid').options[x].value == id)
	        {
	            document.getElementById('colorid').selectedIndex = x;
	        }
	    }
	}
}
function CalculateTiles()
{
    var width = 0;
    if (document.getElementById('width')) width = document.getElementById('width').value;
    var height = 0;
    if (document.getElementById('height')) height = document.getElementById('height').value;
    
    var totalArea = width * height;
    var calculatedTotal = totalArea / 7.5;
    var totalTiles = Math.round(calculatedTotal);
    
    if (totalTiles < calculatedTotal) totalTiles = totalTiles + 1;
    
    document.getElementById('tblDrawing').style.width = width * 10;
    document.getElementById('tblDrawing').style.height = height * 10;
    document.getElementById('totalCount').innerHTML = totalTiles;
    document.getElementById('calculatedInfo').style.display = 'block';
}
function testLength(maxLength,curLength,Element){
	var charLeft = eval(maxLength) - eval(curLength);
	document.getElementById(Element).innerHTML = "(" + charLeft + " characters left)";
	if(charLeft <= 0) document.ContactForm.Comments.value = document.ContactForm.Comments.value.substring(0,maxLength);
}
function validateContact(frmEle){
    if (frmEle.ContactReason.selectedIndex < 1)
    {
        alert("You must select a Reason For Contact!");
        frmEle.ContactReason.focus();
        return false;
    }
	if(frmEle.FirstName.value == ""){
		alert("You must enter your name!");
		frmEle.FirstName.focus();
		return false;
	}
	if(frmEle.Email.value == ""){
		alert("You must enter your email!");
		frmEle.Email.focus();
		return false;
	}
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	
	var emailad = frmEle.Email.value;
	
	 if(((emailad.search(exclude) != -1)||(emailad.search(check))
	== -1)||(emailad.search(checkend) == -1)){
	  	  alert("Incorrect email address!  Please ammend.");
		  frmEle.Email.focus();
		  return false;
	 }
	 
	 var reason = frmEle.ContactReason.value;
	 if (reason == "-1")
	 {
		alert('Please select a reason for contact.');
		return false;
	 }
	 
//	 var orderNum = frmEle.OrderNumber.value;
//	 if (orderNum != "")
//	 {
//	    if (orderNum.search(/[^a-zA-Z#!@$%&*()]/))
//		{
//			alert('Incorrect order number! Please enter the order number only or leave blank.');
//			return false;
//		}
//	 }
}
function ReviewCategory_Change()
{
    if (document.getElementById('Category').selectedIndex > 0)
    {
        document.getElementById('productreview').submit();
    }
}
function ProductReview_Preview()
{
    if (document.getElementById('Product'))
    {
        if (document.getElementById('Product').selectedIndex < 1)
        {
            alert('Please pick a product to review.');
            return false;
        }
    }
    else
    {
        if (document.getElementById('pid').value == "")
        {
            alert('Please pick a product to review.');
            return false;
        }
    }
    if (document.getElementById('rating').value == "")
    {
        alert('Please rate this product by clicking on the stars.');
        return false;
    }
    if (document.getElementById('title').value == "")
    {
        alert('Please enter a title for your review.');
        return false;
    }
    if (document.getElementById('review').value == "")
    {
        alert('Please enter your review.');
        return false;
    }
    if (document.getElementById('location').value == "")
    {
        alert('Please enter your location.');
        return false;
    }
    document.getElementById('preview').value = "y";
}
function ProductReview_Edit()
{
    document.getElementById('editform').value = 'y';
    document.getElementById('productreview').submit();
}
function ProductReview_Submit()
{
    document.getElementById('submitform').value = 'y';
    document.getElementById('productreview').submit();
}
var reviewStarsSet = false;
function starhighlight(x, img)
{
if (reviewStarsSet==false)
	{
	y=x*1+1
	switch(x)
		{
		case "1": document.getElementById('productreviewstar_' + x).src= img;
		break;
		case "2":for (i=1;i<y;i++)
		{
		    document.getElementById('productreviewstar_' + i).src= img;
		}
		break;
		case "3":for (i=1;i<y;i++)
		{
		    document.getElementById('productreviewstar_' + i).src= img;
		}
		break;
		case "4":for (i=1;i<y;i++)
		{
		    document.getElementById('productreviewstar_' + i).src= img;
		}
		break;
		case "5":for (i=1;i<y;i++)
		{
		    document.getElementById('productreviewstar_' + i).src= img;
		}
		break;
		}
	}
}
function starlosehighlight(x, img)
{
if (reviewStarsSet==false)
	{
	for (i=1;i<6;i++)
		{
		document.getElementById('productreviewstar_' + i).src=img;
		}
	}
}
function setStar(x)
{
if (reviewStarsSet==false) 
{
    document.getElementById('rating').value = x;
    reviewStarsSet=true;
}
else
{ 
    reviewStarsSet=false;
}
}