//** 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')
}

function memberPopup() {
	window.open('members/member.php', 'memberWindow', 'status=0, titlebar=0, menubar=0, location=0, scrollbars=1, height=700, width=980')
}

function updateParent(url) {
	window.location.href=(url);
	//window.open(url, '_blank');
	Control.Modal.close();
}

//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 = '<img src="images/spinner.gif" />';
	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,
		opacity: 0.85
	});
	myTypModal.open();
}

function updateDiv(targetDiv, url){
	new Ajax.Updater(targetDiv, url, {
		asynchronous:true,
		evalScripts:true
	});
	new Effect.Appear(targetDiv,{duration:0.5, from:0.3, to:1.0});
}

function openIframeModal(url, fwidth, fheight){
	var w=fwidth;
	var h=fheight;
	var myIFModal = new Control.Modal({
		href: url
		},
		{
		//overlayCloseOnClick: false,
		fade: true,
		iframe: true,
		iframeTemplate: new Template('<iframe src="#{href}" width="'+w+'px" height="'+h+'px" frameborder="0" id="#{id}"></iframe>')
	});
	myIFModal.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 )
}

//bookmark
function bookmarkpage(url, title) {
	// user agent sniffing is bad in general, but this is one of the times 
	// when it's really necessary
	var ua=navigator.userAgent.toLowerCase();
	var isKonq=(ua.indexOf('konqueror')!=-1);
	var isSafari=(ua.indexOf('webkit')!=-1);
	var isMac=(ua.indexOf('mac')!=-1);
	var buttonStr=isMac?'Command/Cmd':'CTRL';

	if(window.external && (!document.createTextNode ||
		(typeof(window.external.AddFavorite)=='unknown'))) {
			// IE4/Win generates an error when you
			// execute "typeof(window.external.AddFavorite)"
			// In IE7 the page must be from a web server, not directly from a local 
			// file system, otherwise, you will get a permission denied error.
			window.external.AddFavorite(url, title); // IE/Win
	} else if(isKonq) {
		alert('You need to press CTRL + B to bookmark our site.');
	} else if(window.opera) {
		void(0); // do nothing here (Opera 7+)
	} else if(window.home || isSafari) { // Firefox, Netscape, Safari, iCab
		alert('You need to press '+buttonStr+' + D to bookmark our site.');
	} else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
		alert('You need to press Command/Cmd + D to bookmark our site.');    
	} else {
		alert('In order to bookmark this site you need to do so manually '+
			'through your browser.');
	}
}

