﻿function productforms(currentAction) {
    var elementsInputs;
    var currentfile;
    var qtys = "";
    var Isdownload = false;
    var openform=new Array();
    var elem;
    elementsInputs = document.getElementsByTagName("select");
    for (var intCounter = 0; intCounter < elementsInputs.length; intCounter++)
    {
         if (currentAction == "downloads")
         {
             for(var i = 1; i < elementsInputs[intCounter].options.length; i++)
             {
              if(elementsInputs[intCounter].options[i].selected == true)
                {
                    currentfile = elementsInputs[intCounter].options[i].value;
                    openform[i] = window.open(currentfile);
                    Isdownload = true;
                  }
             }
          }

    }
    elementsInputs = document.getElementsByTagName("input");
    for (var intCounter = 0; intCounter < elementsInputs.length; intCounter++)
    {
        if (elementsInputs[intCounter].getAttribute('isorderform')==1)
        {         
            if (elementsInputs[intCounter].value == "")
                qtys = qtys + "|||" + 0;              
            else
                if (isNaN(elementsInputs[intCounter].value))
                {
                    alert("Please enter a number in the Qty box.");
                    elementsInputs[intCounter].focus();
                    return false;
                }
                else
                    if (parseInt(elementsInputs[intCounter].value)<0)
                    {
                         alert("Please enter a positive number in the Qty box.");
                         elementsInputs[intCounter].focus();
                         return false;
                    }
                    else
                        qtys = qtys + "|||" + elementsInputs[intCounter].value;
        }

    }
    //alert(productids);
    //alert(qtys)
     if (currentAction == "downloads")
     {
        if ((!Isdownload)&&(currentAction == "downloads"))
            alert("Please select a file to download.");
    }
    else
    {
        document.getElementById("qtys").value = qtys;
        document.mainform.action = currentAction;
        document.mainform.submit();
        //openCartlay();
    }

}
/*
function showdownloads(showitem, hideitem1, hideitem2)
{

var item1=document.getElementById(hideitem1);
var item2=document.getElementById(hideitem2);
if (item1 !=null )
{
       if (document.getElementById(hideitem1).style.display == 'block')
        document.getElementById(hideitem1).style.display = 'none';
}

//alert(document.getElementById(hideitem1).value + " " + hideitem2);
 
if (item2 !=null )
{    
    if (document.getElementById(hideitem2).style.display == 'block')
        document.getElementById(hideitem2).style.display = 'none';
}
    if (document.getElementById(showitem).style.display == 'none')
        document.getElementById(showitem).style.display = 'block';
    //alert(document.getElementById(showitem).style.display);
}
*/
function extendList(ListWidth,extendListID)
{
    document.getElementById(extendListID).style.width=ListWidth;
    document.getElementById(extendListID).focus();
}

function compactList(extendListID)
{
    document.getElementById(extendListID).style.width="";
}

function downloadDocument(element, product)
{
	for (var i = 1; i < element.options.length; i++) {
		if (element.options[i].selected == true) {
			currentfile = element.options[i].value;
			window.open('/shop/SigninDownload.asp?from='+ currentfile + '&product=' + product, "download");
		}
	}
}

function changeHref()
{
    document.getElementById("singleLink").href = document.getElementById("singleLink").href + "&lastOpenTable=" + document.getElementById("lastOpenTable").value;
}

//for rep site buildaquote page
function deleteitem(itemnum, currentAction)
{
    document.mainform.submitsearch.value = '';  //prevent submit search form
    document.mainform.deleteitem.value = itemnum;
    document.mainform.action = currentAction;
    document.mainform.submit();
}

function addfreeform()
{
    document.mainform.submitsearch.value = ''; //prevent submit search form
    document.mainform.addfreeform.value = "1";
    document.mainform.txtProductName.value = document.getElementById("txtProductName").value;
    document.mainform.txtPrice.value = document.getElementById("txtPrice").value;
    document.mainform.txtQuantity.value = document.getElementById("txtQuantity").value;
    document.mainform.submit();
}

function deleteall()
{
    document.mainform.submitsearch.value = ''; //prevent submit search form
    document.mainform.deleteall.value= "1";
    document.mainform.submit();
}