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

var sLoadingAnimation = '<div class="ajaxLoading"><img src="css/img/ajax-loader.gif" alt="" border="0" /></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({ 
		encoding: 'iso-8859-1', // Must be ISO to match charset of DB and page. 
		onRequest: function(){
				//
		},
		onStateChange: function(){
				//
		}, 
		onSuccess: function(sHTML) {
			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) {
		try{
			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);
							
					}, 
					'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);
					}
				},oFX); 
					
		}catch(oError){
			// alert(oError.description);
		}
	});
	

}


