function getCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if(c_start!=-1){ 
			c_start=c_start + c_name.length+1 ;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1){c_end=document.cookie.length;}
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return null;
}
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate);
}

function bgChanger(whatCel, which){
	count=1;
	if(which=="over"){
		while(document.getElementById("mainFooter"+count)){
			//alert("count: " + count);
			if(whatCel==document.getElementById("mainFooter"+count)){
				whatCel.style.backgroundColor='#F9F9F9';
				whatCel.style.backgroundImage='url(../images/section_footer_over.gif)';
			}else{
				document.getElementById("mainFooter"+count).style.backgroundColor='#FFFFFF';
				document.getElementById("mainFooter"+count).style.backgroundImage='url(../images/section_footer.gif)';
			}
			count=count+1;
		}
	}else{
		while(document.getElementById("mainFooter"+count)){
			//alert("count: " + count);
			if(count==1){
				document.getElementById("mainFooter"+count).style.backgroundColor='#F9F9F9';
				document.getElementById("mainFooter"+count).style.backgroundImage='url(../images/section_footer_over.gif)';
			}else{
				document.getElementById("mainFooter"+count).style.backgroundColor='#FFFFFF';
				document.getElementById("mainFooter"+count).style.backgroundImage='url(../images/section_footer.gif)';
			}
			count=count+1;
		}
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function linkImgSwap(which, state){
	if(state=='over'){
		which.childNodes[1].src='../images/link_arrow_over.gif';
	}else{
		which.childNodes[1].src='../images/link_arrow.gif';
	}
}

function jstrim(stringIn){
	stringOut=stringIn;
	stringOut=stringOut.replace(/ /gi, "");
	stringOut=stringOut.replace(/\n/gi, "");//remove lines
	stringOut=stringOut.replace(/\r/gi, "");//remove lines
	stringOut=stringOut.replace(/\t/gi, "");//remove tabs
	return stringOut;
}

function clearField(theTextField, mode){
	var theString;
	theString=theTextField.value;
	theString=jstrim(theString);
	BrowserDetect.init();
	if(theTextField.name=="user_password" && BrowserDetect.browser=="Explorer"){
		if((theTextField.value=="PASSWORD" && mode=="focus") || (theTextField.value.length==0 && mode=="focus")){
			theTextField.value="";
		}else if(theString.length==0){
			theTextField.value="";
		}
	}else{
		if(theTextField.name=="user_password"){
			if(theTextField.value=="PASSWORD" && mode=="focus"){
				theTextField.value="";
			}else if(theString.length==0){
				theTextField.value="PASSWORD";
			}
		}else{
			if(theTextField.value==theTextField.defaultValue && mode=="focus"){
				theTextField.value="";
			}else if(theString.length==0){
				theTextField.value=theTextField.defaultValue;
			}
		}
	}
 }


// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

//FROM http://developer.apple.com/internet/webcontent/styles.html
// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type.
// args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) {
	// first loop over elements, because if they've been modified they
	// will contain style data more recent than that in the stylesheet
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					var theStyle = eval('node.style.' + p);
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}		
	}
	// if we got here it's because we didn't find anything
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if((allStyleRules[y] == c) ||
						   (allStyleRules[y] == (t + "." + c))) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) &&
						   ((rules[y].selectorText == c) ||
						    (rules[y].selectorText == (t + "." + c)))) {
							return z[p];
						}
					}
				}
			}
		}
	}

	return null;
}

// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}
//end from http://developer.apple.com/internet/webcontent/styles.html
	
// *** BROWSER VERSION ***
//FROM http://www.quirksmode.org/js/detect.html
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: "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"
		}
	]

};

function searchForm(theForm){
	return true;
}

function shareForm(theForm){
	errCount=0;
	if(theForm.comments.value.length==0 || theForm.comments.value==theForm.comments.defaultValue){
		errCount=errCount+1;
	}
	if(theForm.recipients_email.value.length==0 || theForm.recipients_email.value==theForm.recipients_email.defaultValue){
		errCount=errCount+1;
	}
	if(theForm.your_name.value.length==0 || theForm.your_name.value==theForm.your_name.defaultValue){
		errCount=errCount+1;
	}

	if(errCount>0){document.getElementById("submitError").innerHTML='<BR>Please complete the fields below.';return (false);
	}else{document.getElementById("submitError").innerHTML='';return (true);}
}

function changeTextMode(whichItem,mode){
	BrowserDetect.init();
	if(mode=="focus"){
		if (BrowserDetect.browser=="Explorer"){
			document.getElementById("user_password").style.backgroundImage='none';
			//document.getElementById("password_holder").innerHTML="<input type=\"password\" id=\"user_password\" name=\"user_password\" value=\"PASSWORD\" class=\"fields\" onFocus=\"clearField(this, 'focus');changeTextMode(this,'focus');\" onBlur=\"clearField(this, 'blur');changeTextMode(this,'blur');\" />";
		}else{
			whichItem.type="password";
		}
	}else if((mode=="blur" && whichItem.value=="PASSWORD") || (mode=="blur" && whichItem.value.length==0)){
		if (BrowserDetect.browser=="Explorer"){
			document.getElementById("user_password").style.backgroundImage='url(../images/password_bg.gif)';
			//document.getElementById("password_holder").innerHTML="<input type=\"text\" id=\"user_password\" name=\"user_password\" value=\"PASSWORD\" class=\"fields\" onFocus=\"clearField(this, 'focus');changeTextMode(this,'focus');\" onBlur=\"clearField(this, 'blur');changeTextMode(this,'blur');\" />";
		}else{
			whichItem.type="text";
		}
	}
}

//http://www.safalra.com/programming/javascript/collapsible-lists/
function toggle(image,list, titleExtra){
	var elementStyle=document.getElementById(list).style;
	if (elementStyle.display=="block"){
		elementStyle.display="none";
		image.src="../images/nav/close.gif";
	}else{
		elementStyle.display="block";
		image.src="../images/nav/open.gif";
	}
}

function toggleBlock(item){
	var elementStyle=document.getElementById(item).style;
	if (elementStyle.display=="block"){
		elementStyle.display="none";
	}else{
		elementStyle.display="block";
	}
}

function onOffCheck(theLayer, effectLayer, force){
	if(force=="block"){
		document.getElementById(effectLayer).innerHTML=" -- ";
		document.getElementById(theLayer).style.display="block";
	}else if(document.getElementById(theLayer).style.display=="block" || force=="none"){
		document.getElementById(effectLayer).innerHTML="+";
		document.getElementById(theLayer).style.display="none";
	}else{
		document.getElementById(effectLayer).innerHTML=" -- ";
		document.getElementById(theLayer).style.display="block";
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

bTextareaWasTinyfied = false; //this should be global, could be stored in a cookie...
function setTextareaToTinyMCE(sEditorID) {
	var oEditor = document.getElementById(sEditorID);
	if(oEditor && !bTextareaWasTinyfied) {
		tinyMCE.execCommand('mceAddControl', true, sEditorID);
		bTextareaWasTinyfied = true;
	}
	return;
}
function unsetTextareaToTinyMCE(sEditorID) {
	var oEditor = document.getElementById(sEditorID);
	if(oEditor && bTextareaWasTinyfied) {
		tinyMCE.execCommand('mceRemoveControl', true, sEditorID);
		bTextareaWasTinyfied = false;
	}
	return;
}

function resizeEditor(sEditor, iX, iY){
	var oEditor = document.getElementById(sEditor);
	if (oEditor){
		  var iCurrentX = parseInt(oEditor.style.width);
		  var iCurrentY = parseInt(oEditor.style.height);
		//oEditor.style.width = eval(iCurrentX+iX);
		//oEditor.style.height = eval(iCurrentY+iY);
		oEditor.style.width = eval(iX);
		oEditor.style.height = eval(iY);
		var oSizeinfo = document.getElementById('sizeinfo');
		/*if(oSizeinfo){
			var oSizeinfoNode = oSizeinfo.firstChild;
			if(oSizeinfoNode){
				oSizeinfoNode.data = 'Current size is X=' + oEditor.style.width + ' and Y=' + oEditor.style.height;
			}
		}*/
	}else{
		alert('Couldn\'t find editor named: ' + sEditor);
	}
}

function handleEnter(field, event) {
	/***********************************************
	* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
	* This notice must stay intact for use
	* Visit http://www.dynamicdrive.com/ for full source code
	***********************************************/
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		/*var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();*/
		return false;
	} 
	else
		return true;
} 

function getCheckedValue(radioObj){
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function getImages(productID,paging,pageID){
	thumbs_paging_out=getCookie('thumbs_paging')+paging;
	setCookie('thumbs_paging', thumbs_paging_out, 1000);
	var url="../ajax_feeders/get_thumbs.php?id=" + Math.random() + "&productID=" + productID + "&paging=" + thumbs_paging_out + "&pageID=" + pageID;
	xmlThumb=GetXmlHttpObject(thumbFeeder);
	xmlThumb.open("GET", url , true);
	xmlThumb.send(null);
}

function thumbFeeder(){
	if(xmlThumb.readyState==4 || xmlThumb.readyState=="complete"){ 
		document.getElementById("thumbArea").innerHTML=xmlThumb.responseText;
	}
}

function GetXmlHttpObject(handler){
	var objXmlHttp=null;
	if(navigator.userAgent.indexOf("Opera")>=0){
		//alert("This Version of Ajax is setup for Opera. My apologys");
		return;
	}
	if(navigator.userAgent.indexOf("MSIE")>=0){ 
		var strName="Msxml2.XMLHTTP";
		if(navigator.appVersion.indexOf("MSIE 5.5")>=0){
			strName="Microsoft.XMLHTTP";
		} 
		try{ 
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler;
			return objXmlHttp;
		} 
		catch(e){ 
			//alert("Error. Scripting for ActiveX might be disabled");
			return;
		} 
	} 

	if(navigator.userAgent.indexOf("Mozilla")>=0){
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
}


function thumbProngs(whichSet, mode){//over none gray
	if(mode=="over"){
		document.getElementById('prongLeft'+whichSet).style.backgroundImage="url(../images/left_prong_over.gif)";
		document.getElementById('prongRight'+whichSet).style.backgroundImage="url(../images/right_prong_over.gif)";
		document.getElementById('prongBottom'+whichSet).style.backgroundColor="#A8962B";
		document.getElementById('prongBottom'+whichSet).style.backgroundImage="url(../images/bottom_prong_over.gif)";
	}else if(mode=="none"){
		document.getElementById('prongLeft'+whichSet).style.backgroundImage="none";
		document.getElementById('prongRight'+whichSet).style.backgroundImage="none";
		document.getElementById('prongBottom'+whichSet).style.backgroundColor="transparent";
		document.getElementById('prongBottom'+whichSet).style.backgroundImage="none";
	}else if(mode=="gray"){
		document.getElementById('prongLeft'+whichSet).style.backgroundImage="url(../images/left_prong.gif)";
		document.getElementById('prongRight'+whichSet).style.backgroundImage="url(../images/right_prong.gif)";
		document.getElementById('prongBottom'+whichSet).style.backgroundColor="#C6C6C6";
		document.getElementById('prongBottom'+whichSet).style.backgroundImage="url(../images/bottom_prong.gif)";
	}
}

function popper(url){
	popwin = this.open(url, "pop_check", "width=600,height=400,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
	popwin.focus();
}

MM_preloadImages(
	'../images/section_footer_over.gif'
	, '../images/link_arrow_over.gif'
	, '../images/nav/close.gif'
	, '../images/nav/open.gif'
	, '../images/pdf_link_over.gif'
	, '../images/bottom_prong_over.gif'
	, '../images/left_prong_over.gif'
	, '../images/right_prong_over.gif'
	, '../images/admin_images/move_left_over.gif'
	, '../images/admin_images/move_right_over.gif'
	, '../images/password_bg.gif'
	, '../images/home_page/current_promotions_over.gif'
	,'../images/home_page/firms_and_partners_over.gif'
	,'../images/section_footer.gif'
	,'../images/section_footer_over.gif'
); 
