var preImgs = ['images/link_viewcart-over.gif']
for(var i=0; i<preImgs.length; i++){
	var newImg = new Image();
	newImg.src = preImgs[i];
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function swapCartBGimg(link, trigger){
	if(trigger){
		link.style.backgroundImage = 'url(images/link_viewcart-over.gif)';
	}
	if(!trigger){
		link.style.backgroundImage = 'url(images/link_viewcart.gif)';
	}
}


contDiv = function(){
	var me = this;
	this.rawContent = document.getElementById('listContent').innerHTML;
	this.contentArray = this.rawContent.split(',');
	this.currentDiv;

	this.div = document.getElementById('divSpecifications');
	this.addItemDiv = function(obj){
		obj.className = 'itemDiv';
		this.div.appendChild(obj);
		this.currentDiv = obj;
	}

	this.addItems = function(){
		var div = document.createElement('div');

		for(var i=0; i<me.contentArray.length; i++){
			var tempItem = new listItem();
			tempItem.div.innerHTML = me.contentArray[i];
			if(i == 0 || i % Math.floor(me.contentArray.length/3) != 0){
				div.appendChild(tempItem.div);
			}else{
				div.appendChild(tempItem.div);
				me.addItemDiv(div);
				div = document.createElement('div');
			}
		}
		me.addItemDiv(div);	
		var clear = document.createElement('div');
		clear.className = 'clear';
		clear.innerHTML = '&nbsp;';
		me.div.appendChild(clear);
	}
	this.addItems();
}

listItem = function(){
	this.div = document.createElement('div');
	this.div.className = 'prodListItem';
}

var cont;

function init_specs(){
	cont = new contDiv();

}


function closeZoomDiv(){
	document.getElementById('zoomDiv').style.display = 'none';
}

function zoomImgs(){
	var preloads = (document.getElementById('views'))?document.getElementById('views').getElementsByTagName('img'):null;
	if(preloads)
	{
		for(var i=0; i<preloads.length; i++){
			var img = new Image();
			img.src = preloads[i].src.replace('.jpg','_zoom.jpg');
		}
	}

		if(document.getElementById('zoomDiv').style.display != 'block'){
			document.getElementById('zoomDiv').style.display = 'block';
		}else{
			document.getElementById('zoomDiv').style.display = 'none';
		}
}

function swapZoomImg(newSrc){
	document.getElementById('zoomImg').src = newSrc;
}


// pop up generator
function dynaGoPop( page, name, width, height, yesORno ){
	var yon = yesORno;
	yon = (yon)? yesORno : 'auto';
	var goPopX = (screen.width/2) - (width/2);
	var goPopY = (screen.height/4) - 100;
	var loc = "left="+goPopX+",top="+goPopY;
	goPopWindow = window.open( page,name,"scrollbars="+yon+",resizable=no,width="+width+",height="+height+","+loc );
}

function applyFilter(dropdown) {
	if (dropdown.value){
		location.href=dropdown.value;
	}
}




function printView(){
	var loc = window.location.href;
	var newWin = window.open(loc+'?print=yes', 'newWin', 'width=958,height=500,status=no,location=no,address=no,menubar=no,resizable=yes,scrollbars=yes');
}


function validateACEDForm()
{
	
	if( document.getElementById( 'ddlBusinessTypeProfession' ).value	== '' ||
		document.getElementById( 'upgrade_FederalStateTaxId' ).value	== '' ||
		document.getElementById( 'labeltxtTaxId' ).value				== '' )
	{
		alert( 'Plese fill in all required information.' );
		return false;
	}
	else
	{
		return true;
		clearUpgradeForm();
	}
}

function validateContactForm()
{	
	if( !document.getElementById( 'contactus_fname' ).value.length	> 0	||
		!document.getElementById( 'contactus_lname' ).value			> 0	||
		!document.getElementById( 'contactus_email' ).value			> 0 )
	{
		alert( 'Plese fill in all required information.' );
		return false;
	}
	else
	{
		/*
		var humanAddition = document.getElementById( 'humanAddition' );
		var numResult = parseInt( humanAddition.value );

		if( isNaN( numResult ) )
		{
			alert( 'Please enter a number' )
			humanAddition.value = '';
			humanAddition.focus();
			return false;
		}
		else
		{
			if( numResult == num1 + num2 )
			{
				return true;
			}
			else
			{
				alert( 'Addition incorrect' );
				humanAddition.value = '';
				humanAddition.focus();
				return false;
			}
		}
		*/
		return true;
	}
}

function validateReturnsForm()
{	
	if( !document.getElementById( 'returns_fname' ).value.length	> 0	||
		!document.getElementById( 'returns_lname' ).value			> 0	||
		!document.getElementById( 'returns_email' ).value			> 0 ||
		!document.getElementById( 'returns_orderNo' ).value			> 0 ||
		!document.getElementById( 'returns_email' ).value			> 0 )
	{
		alert( 'Plese fill in all required information.' );
		return false;
	}
	else
	{
		return true;
	}
}

function validateNewsletterForm()
{	
	if( !document.getElementById( 'newsletter_email' ).value.length > 0 )
	{
		alert( 'Plese fill in all required information.' );
		return false;
	}
	else
	{
		return true;
	}
}

function clearUpgradeForm(){	
	var upgradeInputs = document.upgradeForm.getElementsByTagName('input');
	for(var i=0; i<upgradeInputs.length; i++){
		upgradeInputs[i].value = '';
	}
	var upgradeSelects = document.upgradeForm.getElementsByTagName('select');
	for(var i=0; i<upgradeSelects.length; i++){
		upgradeSelects[i].value = '';
	}
}
