function setColorDataEntry(hex){
	if('select' != hex){
		currColorValue = hex;
		var colorCode = '#'+hex;
		document.getElementById('colorswatch').style.backgroundColor = colorCode;
		document.getElementById('colorHexText').value = hex;				
	}
}

function setColor(hex){
	if('select' != hex){
		var currColorValue = hex;
		var colorCode = '#'+hex;
		document.getElementById('plugID').style.backgroundColor = colorCode;
		document.getElementById('mHEX').innerHTML = hex;
//		alert(document.getElementById('colorCriteria').value);
//		document.getElementById('currColor').value = hex;
		document.getElementById('colorCriteria').value = hex;
	}
}


function init(){
	var inp1 = document.getElementById('input1');
	var inp2 = document.getElementById('colorHexText');
	var inp3 = document.getElementById('input3');
	var inp4 = document.getElementById('input4');
	if(inp1) attachColorPicker(inp1);
	if(inp2) attachColorPicker(inp2);
	if(inp3) attachColorPicker(inp3);
	if(inp4) attachColorPicker(inp4);
}

window.onload = init;


function clearText(thefield,thisdefault){
	//alert(thefield.defaultValue+" "+thefield.value);
	if (thisdefault==thefield.value)
	thefield.value = "";
}

function createAjaxObject(){
	var xmlHttp;
	try{
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e){
	  // Internet Explorer
		try{
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
		      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function showHideDiv(theDiv){
	//alert(document.getElementById(theDiv).style.display);
	if(document.getElementById(theDiv).style.display!='block'){
		document.getElementById(theDiv).style.display='block';
	}else{
		document.getElementById(theDiv).style.display='none';
	}
}

function checkSetCookiesEnabled(){
	//alert("in checkset");
	/*
	var http = createAjaxObject();
	if(http == null){
		if(!navigator.cookieEnabled){
			alert("Your browser does not support AJAX! WTF Mate?");
		}
	}
	var url = "/artsupplywarehouse.com/setCookiesVariable.php";
	var params = "cookies="+navigator.cookieEnabled;
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function() {//Call a function when the state changes.
		alert(http.readyState+" && "+http.status);
		if(http.readyState == 4 && http.status == 200) {
			if(http.responseText!=''){
				alert(http.responseText);	
			}
		}
	}
	http.send(params);
	*/
	if(!navigator.cookieEnabled){
		alert("Note: Apparently you have cookies disabled in your browser. You must have cookies enabled to make a purchase. If this is an issue, please contact us and we'll gladly take you order over the phone.");
	}
}

/*
Dynamic tabs section
*/
function getChildElementsByClassName(parentElement, className)
{
	var i, childElements, pattern, result;
	result = new Array();
	pattern = new RegExp("\\b"+className+"\\b");


	childElements = parentElement.getElementsByTagName('*');
	for(i = 0; i < childElements.length; i++)
	{
		if(childElements[i].className.search(pattern) != -1)
		{
			result[result.length] = childElements[i];
		}
	}
	return result;
}


function BuildTabs(containerId)
{
	var i, tabContainer, tabContents, tabHeading, title, tabElement;
	var divElement, ulElement, liElement, tabLink, linkText;


	// assume that if document.getElementById exists, then this will work...
	if(! eval('document.getElementById') ) return;

	tabContainer = document.getElementById(containerId);
	if(tabContainer == null)
		return;

	tabContents = getChildElementsByClassName(tabContainer, 'tab-content');
	if(tabContents.length == 0)
		return;

	divElement = document.createElement("div");
  	divElement.className = 'tab-header'
  	divElement.id = containerId + '-header';
	ulElement = document.createElement("ul");
  	ulElement.className = 'tab-list'

	tabContainer.insertBefore(divElement, tabContents[0]);
	divElement.appendChild(ulElement);

	for(i = 0; i < tabContents.length; i++)
	{
		tabHeading = getChildElementsByClassName(tabContents[i], 'tab');
		title = tabHeading[0].childNodes[0].nodeValue;

		// create the tabs as an unsigned list
		liElement = document.createElement("li");
		liElement.id = containerId + '-tab-' + i;

		tabLink = document.createElement("a");
		linkText = document.createTextNode(title);

		tabLink.className = "tab-item";

		tabLink.setAttribute("href","javascript://");
		tabLink.setAttribute( "title", tabHeading[0].getAttribute("title"));
		tabLink.onclick = new Function ("ActivateTab('" + containerId + "', " + i + ")");

		ulElement.appendChild(liElement);
		liElement.appendChild(tabLink);
		tabLink.appendChild(linkText);

		// remove the H1
		tabContents[i].removeChild
	}
}

function ActivateTab(containerId, activeTabIndex)
{
	var i, tabContainer, tabContents;

	tabContainer = document.getElementById(containerId);
	if(tabContainer == null)
		return;

	tabContents = getChildElementsByClassName(tabContainer, 'tab-content');
	if(tabContents.length > 0)
	{
		for(i = 0; i < tabContents.length; i++)
		{
			//tabContents[i].className = "tab-content";
			tabContents[i].style.display = "none";
		}

		tabContents[activeTabIndex].style.display = "block";


    		tabList = document.getElementById(containerId + '-list');
		tabs = getChildElementsByClassName(tabContainer, 'tab-item');
		if(tabs.length > 0)
		{
			for(i = 0; i < tabs.length; i++)
			{
				tabs[i].className = "tab-item";
			}

			tabs[activeTabIndex].className = "tab-item tab-active";
			tabs[activeTabIndex].blur();
		}
	}
}

function keepAlive(){
	http = createAjaxObject();
	if(http == null){
      //alert("Your browser does not support AJAX! WTF Mate?");
      return false;
	}
	var url = "keepAlive.php";
	var params = "";
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
//	http.onreadystatechange = function() {//Call a function when the state changes.
//		if(http.readyState == 4 && http.status == 200) {
//			if(http.responseText!=''){
//				alert(http.responseText);
//			}
//		}
//	}
	http.send(params);
	return true;
}

