/*
	shared.js
	v1.0 - 27/nov/2007 - Bob Kersten - Initial version.
	(C) Copyright 2007 Fellownet.
	All rights reserved.
*/

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("mainmenu");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList

function openSheet(sheet_, product_id_) {
	new Ajax.Updater('sheets', 'sec.sheets.php', {
		method:'get',
		evalScripts:true,
		parameters:'sheet=' + sheet_ + '&product_id=' + product_id_
	} );
}

function openImage(img_, product_id_) {
	new Ajax.Updater('imgcap', 'sec.product.php', {
		method:'get',
		evalScripts:true,
		parameters:'img=' + img_ + '&product_id=' + product_id_
	} );
}

function sendForm(form_, target_, button_, onSuccess_) {
	/**
	 * This is a generic function to submit forms and parse the results.
	 */	
	var fields = $A(document.getElementsByClassName('field_error'));
	fields.each( function(el_) {
		Element.removeClassName(el_, 'field_error');
	} );
	if ($(button_)) $(button_).style.visibility = 'hidden';

	// This is the first step in the registration process. Let's validate all the
	// supplied data before we continue.
	new Ajax.Request(
		target_, {
			method:'post',
			parameters:Form.serialize(form_),
			onComplete:function(req_) {
				var results = req_.responseText.toQueryParams();
				if (results['result'] && results['result'] != 'OK') {
					var errors = $A(results['fields'].split(';'));
					errors.each( function(el_) {
						if ($(el_)) Element.addClassName(el_, 'field_error');
					} );
					dialog.open( {
						content:results['content'],
						title:results['title'],
						buttons:'Close',
						width:320,
						duration:0,
						callback:function(action_, dialog_) {
							try {
								if ($(button_)) $(button_).style.visibility = 'visible';
								dialog_.close();
								if (false != (field = $(errors[0]))) field.focus();
							} catch(e_) { /* do nothing */ }
						}
					} );
				} else if (results['result'] && results['result'] == 'OK') {
					if (onSuccess_) onSuccess_(results);
				} else {
					if ($(button_)) $(button_).style.visibility = 'visible';
					alert(req_.responseText);
				}
			}
		}
	);
}
function onContactFormSubmit(button_) {
	sendForm('contactForm', 'xf.contact.php', button_, function(results_) {
		document.location.href = "http://www.stagingconcepts.com/submit.contact.php";
/*		dialog.open( {
			content:results_['content'],
			title:results_['title'],
			buttons:'Close',
			width:320,
			duration:0
		} ); */
	} );
	return false;
}

function onQuoteFormSubmit(button_) {
	sendForm('quoteForm', 'xf.quote.php', button_, function(results_) {
		document.location.href = "http://www.stagingconcepts.com/submit.quote.php";
/*		dialog.open( {
			content:results_['content'],
			title:results_['title'],
			buttons:'Close',
			width:320,
			duration:0
		} ); */
	} );
	return false;
}

var helpers = $H( {
} );

function startIconRotate(id_, icons_) {
	helpers['pos_' + id_] = 0;
	new PeriodicalExecuter(function(pe_) {
		var icons = icons_.split(',');
		helpers['pos_' + id_]++;
		if (helpers['pos_' + id_] >= icons.length) helpers['pos_' + id_] = 0;
		$('icon_' + id_).setAttribute('src', '/images/' + icons[helpers['pos_' + id_]]);
	}, (Math.random() * 3) + 2);
}
