/*
 * Javascript Functions for Scunci.com
 * Mootools functions. Requires the Mootools Javascript Framework v1.2 (www.mootools.net)
 * @Author Tony Collings
 * @Copyright Conair Corporation
 * @Date July 2009
 * @Version 1.0
 *
 */


var sLoadingAnimation = '<div class="ajaxLoading"><img src="css/img/grey-ajax-loader.gif" alt="" border="0" /><br />Loading... Please Wait...</div>';
var bSelectBoxesDisabled; // Boolean flag set if IE6 and z-index is toggled and SELECT boxes are present. IE6 & SELECT Bug

// AJAX Wrapper function.... 
function gogogadgetAJAX(sURL,sElementToInject){
	var oElementToInject = $(sElementToInject);
	//var objAJAX; // AJAX object
	oElementToInject.set('html',sLoadingAnimation);
	oXHR = new Request.HTML({ 

		onRequest: function(){
				//
		},
		onStateChange: function(){
				//
		}, 
		onSuccess: function(sHTML) {
			
			// IE6 SELECT BOX BUG FIX
			// Remove Select Boxes for IE6 ONLY. IE6 + z-index = problem. 
			var oBrowserName = BrowserDetect.browser;
			var oBrowserVersion = BrowserDetect.version;
			if(oBrowserName == 'Explorer' && oBrowserVersion <= 6){
				// Grab ALL Select Boxes
				var arrElementArray = $$('select');
				fixIE6SelectBox(arrElementArray,false);
				bSelectBoxesDisabled = true; 
			}
		
		
			if(oElementToInject){
				oElementToInject.set('html', '');
				oElementToInject.adopt(sHTML);
			} else {
				alert('We\'re sorry, there seems to have been a technical issue in getting the content you have requested. Please refresh the page and try again. If the problem persists please contact us here at web_helpme@conair.com. Thank you for your patience');	
			}
		},
		onFailure: function() {
			if(oElementToInject){
				oElementToInject.set('html', '<span class="ajaxError">Please accept our apologies, but we have been unable to process this <a href="http://en.wikipedia.org/wiki/Ajax_(programming)" title="AJAX" target="_blank"><acroynm title="(A)synchronous (J)avaScript (A)nd (X)ML"><strong>AJAX</strong></acroynm></a> request. Please close this window and try again. If you still experience problems please contact us at : web_helpme@conair.com<br /><p><a href="javascript:window.location=document.URL" title="Close this Window"><strong>Close</strong></a></span></p>');
			} else {
				alert('We\'re sorry, there seems to have been a technical issue in getting the content you have requested. Please refresh the page and try again. If the problem persists please contact us here at web_helpme@conair.com. Thank you for your patience');	
			}
		}
	});
	oXHR.post(""+sURL+"")
	
}


// Passes in an array of elements (should all be select boxes) and true/false to toggle on/off
function fixIE6SelectBox(arrElementArray,toggle){
	if(toggle){
		// Show Elements	
		arrElementArray.each(function(el) {
			el.setStyle('display','block');
		});
	}else{
		// Hide Elements
		arrElementArray.each(function(el) {
			el.setStyle('display','none');
		});
	}
}
 
// Applies an onfocus/onblur effect to form borders. Input : array
function fancyBorders(arrFormElements,sFocusColor,sBlurColor){
	var oFX;
	arrFormElements.each(function(oElement,index,oFX) {
	
	if(oElement){
	oElement.setStyles({'border':'1px solid '+sBlurColor});
	oElement.addEvents({
			'focus' : function() {
					if($type(this.oFX) == 'object') this.oFX.cancel();
					oElement.setStyles({'border-width':'1px','border-style':'solid'});
					//this.oFX = new Fx.Tween(oElement,  {property: 'border-color', duration: 600/*, transition: Fx.Transitions.Back.easeOut*/}).start(sBlurColor,sFocusColor); // Mootools v1.2.1 ONLY !
					this.oFX = new Fx.Style(oElement, 'border-color', {duration: 600}).start(sBlurColor,sFocusColor);
					
			}, 
			'blur' : function() {
					if($type(this.oFX) == 'object') this.oFX.cancel();
					oElement.setStyles({'border-width':'1px','border-style':'solid'});
					//this.oFX = new Fx.Tween(oElement,  {property: 'border-color', duration: 600/*, transition: Fx.Transitions.Back.easeOut*/}).start(sFocusColor,sBlurColor); // Mootools v1.2.1 ONLY !
					this.oFX = new Fx.Style(oElement, 'border-color', {duration: 600}).start(sFocusColor,sBlurColor);
			}
		}); 
	} else {
		// Element not found... 	
	}
	
	});
}


