﻿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(parseInt(elementsInputs[intCounter].value)))
                {
                    alert("Please enter a positive 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();
    }

}
/*
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;

}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
