//** Featured Content Slider script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Oct 28th, 06

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_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function adminPopup() {
	window.open('login.php', 'adminWindow', 'status=0, titlebar=0, menubar=0, location=0, scrollbars=1, height=700, width=980')
}

//new Ajax.Request('ajax_test.php', {
//	method: 'get',
//	onSuccess: function(transport){
//		var response = transport.responseText || "no response text";
//		alert("Success! \n\n" + response);
//	},
//	onFailure: function(){ alert('Something went wrong...') }
//});

function phpRequest(ID, page) {
	document.getElementById(ID).innerHTML = '<p align="center">Loading...</p>';
	new Ajax.Updater({success:ID, failure:'ajaxError'}, page, {asynchronous:true, evalScripts:true});
}

function formSubmit(ID, page, fid) {
	new Ajax.Updater({success:ID, failure:'ajaxError'}, page, {
		method:'post',
		parameters:$(fid).serialize(),
		asynchronous:true,
		evalScripts:true
	});
}

function myResponder(divID, progressID) {
	Ajax.Responders.register({onCreate:showProcessing, onComplete:hideProcessing});
	var activeDiv = document.getElementById(divID);
	
	function showProcessing() {
		if(Ajax.activeRequestCount > 0)
			Element.hide(activeDiv);
			document.getElementById(progressID).style.display = 'block';
	}
	
	function hideProcessing() {
		if(Ajax.activeRequestCount <= 0)
			new Effect.Appear(activeDiv);
			document.getElementById(progressID).style.display = 'none'; 
	}
	
	Ajax.Responders.unregister({onCreate:showProcessing, onComplete:hideProcessing});
}

function setButtonState(target, state) {
	var element = document.getElementById( target );
	if( element )
		element.disabled = state;
}

function ChangeClass(menu, newClass) { 
	 if (document.getElementById) { 
	 	document.getElementById(menu).className = newClass;
	 } 
} 
document.onselectstart = new Function("return true");

function openTypModal(url){
	var myTypModal = new Control.Modal({
		href: url
		},
		{
		//overlayCloseOnClick: false,
		fade: true
	});
	myTypModal.open();
}

function openCoupon(url){
	var myModal = new Control.Modal({
		href: url
		},
		{
		//overlayCloseOnClick: false,
		fade: true,
		offsetLeft: 110, //for use with 'relative'
		offsetTop: 50, //for use with 'relative'
		position: 'relative' //'absolute' or 'relative'
	});
	myModal.open();
}

function disableModalPrint() {
	document.getElementById('modalPrint').disabled=true;
}

function enableModalPrint() {
	document.getElementById('modalPrint').disabled=false;
}

function onElementAvailable( sId , callback ){
	if( (typeof(sId) != 'string') || 
		(typeof(callback) != 'function') ) return false;
	
	
	var fn = function(){
		var el = document.getElementById(sId);
		if( el) return callback.call(el);
		fn = null;
		return setTimeout(arguments.callee);
	};
	fn();

}

function onElementContentReady( sId , callback ){
	if( (typeof(sId) != 'string') ||
		(typeof(callback) != 'function') ) return false;
	
	var fn = function(){
		var el = this;
		var sTag = el.tagName ;
		var fn2 = function(){
			
			//check readyState first
			if(el.readyState != 'complete') return setTimeout(arguments.callee,100);
			
			//if close tag is not required, then call callback
			if(!el.canHaveHTML){
				//close tag is not required
				return callback.call(el);
			}

			//check if it has a close tag
			if(el.cloneNode(false).outerHTML.indexOf( '</' + sTag + '>') === -1 ) {
				//close tag is not available yet
				return setTimeout(arguments.callee,100);
			}
			
			//now we have the full outerHTML
			
			fn = fn2  = null; //release some memory, if applicable
			callback.call(el);//call callback			
		};
		fn2();
	}
	onElementAvailable( sId , fn )
}
