var http = httpGetObject();
IS_DOM = (document.getElementById) ? true : false;

function toggleList()
{
	var theListItems = document.getElementById("penListUl").getElementsByTagName("LI");
	if (penListState == "off") {
		turnListOn(theListItems);
	} else {
		turnListOff(theListItems);
	}
}

function turnListOn(theListItems)
{
	for (var i = 0; i < theListItems.length; i++)
	{
		theListItems[i].style.display = "inline";
	}
	penListState = "on";
}

function turnListOff(theListItems)
{
	for (var i = 0; i < theListItems.length; i++)
	{
		theListItems[i].style.display = "none";
	}
	document.getElementById("firstOne").style.display = "inline";
	penListState = "off";
}

var address;
function displayEmail() {
    var x = document.getElementsByTagName('span');

    for (var i=0;i<x.length;i++) {
        if (x[i].className == 'hiddenemail') {
			scanHiddenEmail(x[i])
                if ((x[i].innerHTML !== null) && (address !== null))
                x[i].innerHTML = '<a href=\'mailto:' + address + '\'>' + address + '</a>';
        }

		if (x[i].className == 'hiddenTitleEmail') {
			scanHiddenEmail(x[i])
                if ((x[i].innerHTML !== null) && (address !== null))
  				         x[i].innerHTML = '<a href=\'mailto:' + address + '\'><img src=\'../../images/subpage-email.gif \' height= \'33\' /> </a>';

		}

        if (x[i].className == 'hiddenMenuEmail') {
            scanHiddenEmail(x[i])
                if ((x[i].innerHTML !== null) && (address !== null))
                           x[i].innerHTML = '<a href=\'mailto:' + address + '\'><img src=\'images/subpage-email.gif \' height= \'33\' /> </a>';

        }

		if (x[i].className == 'hiddenMainPageEmail') {
			scanHiddenEmail(x[i])
                if ((x[i].innerHTML !== null) && (address !== null))
  				         x[i].innerHTML = '<a href=\'mailto:' + address + '\'><img src=\'images/email.gif \' width=\'233\' height= \'27\' /> </a>';

		}

    }
}

function scanHiddenEmail(s) {
	var y = s.getElementsByTagName('span');
                for (var j=0;j<y.length;j++) {
                    if (y[j].className == 'name') {
                        if (y[j].innerHTML !== null)
                        address = y[j].innerHTML + '@';
                    }
                    if (y[j].className == 'domain') {
                        if (y[j].innerHTML !== null)
                        address = address + y[j].innerHTML + '.';
                    }
                    if (y[j].className == 'extension') {
                        if (y[j].innerHTML !== null)
                        address = address + y[j].innerHTML;
                    }
                 }
 return address;
}

function copyrightYear(startYear)
{
	d = new Date();
	if (startYear != d.getFullYear()) { return startYear + " - " + d.getFullYear(); }
	else { return startYear; }
}

var penListState = "off";

function toggleList(collapse) {
	if (collapse == "off") { penListState = "on"; }
	var theListItems = document.getElementById("pensList").getElementsByTagName("li");
	if (penListState == "off") {
		turnListOn(theListItems);
	} else {
		turnListOff(theListItems);
	}
}

function turnListOn(theListItems) {

	for (var i = 0; i < theListItems.length; i++)
	{
		theListItems[i].style.display = "block";
	}
	penListState = "on";
}

function turnListOff(theListItems) {
	for (var i = 0; i < theListItems.length; i++){
		theListItems[i].style.display = "none";
	}
	document.getElementById("firstOne").style.display = "block";
	penListState = "off";
}

function check(min)
{
	if(isNaN(document.first_quote.quantity.value))
	{
		alert("Please enter a numerical value for Quantity");
		document.first_quote.quantity.focus();
		return false;
	}

	var min_quantity = min;
	var input = document.first_quote.quantity.value;

	if( input < min_quantity )
	{
		alert("Please enter an amount higher than the minimum order quantity (minimum for this product is "+min_quantity+")");
		document.first_quote.quantity.focus();
		return false;
	}
}

function checkmail()
{
	var regEmail = /^([-a-zA-Z0-9._]+@[-a-zA-Z0-9.]+(\.[-a-zA-Z0-9]+)+)$/;  ////E-Mail Checking
	if(!regEmail.test(document.frmMail.youremail.value))
	{
		alert("Please enter your e-mail address");
		document.frmMail.youremail.focus();
		return false;
	}
	if(!regEmail.test(document.frmMail.friendemail.value))
	{
		alert("Please enter an e-mail address for your friend");
		document.frmMail.friendemail.focus();
		return false;
	}
}

function grabimage()
{
	document.getElementById('prodimginput').value = document.getElementById('prodimg').src;
}

function fastquoteSubmit(name, id)
{
	document.getElementById('fqName').value = name;
	document.getElementById('fqID').value = id;
	document.getElementById('fqForm').submit();
}

function openTab(elem ,tab)
{
	var ttcPG = document.getElementById("ttcPG"),
		ttcFQ = document.getElementById("ttcFQ"),
		ttcON = document.getElementById("ttcON"),
		tabPG = document.getElementById("tabPG"),
		tabFQ = document.getElementById("tabFQ"),
		tabON = document.getElementById("tabON");

	ttcPG.style.display = "none";
	ttcFQ.style.display = "none";
	ttcON.style.display = "none";
	tabPG.setAttribute("class", "");
	tabPG.setAttribute("className", "");
	tabFQ.setAttribute("class", "");
	tabFQ.setAttribute("className", "");
	tabON.setAttribute("class", "");
	tabON.setAttribute("className", "");

	switch( tab )
	{
		case 1:
			ttcPG.style.display = "block";
			elem.setAttribute("class", "activeTab");
			elem.setAttribute("className", "activeTab");
			break;
		case 2:
			ttcFQ.style.display = "block";
			elem.setAttribute("class", "activeTab");
			elem.setAttribute("className", "activeTab");
			break;
		case 3:
			ttcON.style.display = "block";
			elem.setAttribute("class", "activeTab");
			elem.setAttribute("className", "activeTab");
			break;
	}
}

function httpGetObject(){
	var req;
	if(window.XMLHttpRequest && !(window.ActiveXObject)){
		try {
			req = new XMLHttpRequest();
		} catch(e){
			req = false;
		}		
	} else if(window.ActiveXObject){
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e){
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
				req = false;
			}
		}
	}
	return req;
}

function httpRequestData(oHTTP, sEventHandler, sURL, sMethod, params){
	if(oHTTP){
		oHTTP.open(sMethod, sURL, true);
		if(params){
			oHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			oHTTP.setRequestHeader("Content-length", params.length);
			oHTTP.setRequestHeader("Connection", "close");
		}
		oHTTP.onreadystatechange = eval(sEventHandler);
		oHTTP.send(params);
	}
}
