/*
*	function showHideSimple (Closes one div object and displays another based on list)
*
*	@theList = List with 2 divs (div to close, div to open)
*/
function showHide(s,h){
	// set display properties
	$(s).show();
	$(h).hide();
}
function showHideSimple(theList){
	//split the list
	thisList=theList.split(',');
	// set display properties
	$(thisList[0]).show();
	$(thisList[1]).hide();
}
/*
*	function showHideFade (Fades out one div object and Fades in another based on list)
*
*	@theList = List with 2 divs (div to close, div to open)
*/
function showHideFade(theList){
	//split the list
	thisList=theList.split(',');
	// run animations
	new Effect.Opacity($(thisList[1]), {duration: .25, from:1.0, to:0.0, afterFinish:function(){
			$(thisList[1]).hide();
			$(thisList[0]).setOpacity(0);
			$(thisList[0]).show();
			new Effect.Opacity($(thisList[0]), {duration: .5, from:0, to:1.0});																														  
	  }
	});
}
/*
*	function showHideSimpleSingle (Opens and Closes a single div based on current display status)
*
*	@theItem = div id
*/
function showHideSimpleSingle(theItem){
	if(document.getElementById(theItem).style.display == "none") {
		document.getElementById(theItem).style.display = "block";
	} else {
		document.getElementById(theItem).style.display = "none";
	}
}

/*
*	function chkPWDLen 
*	passed from user management cfforms to check the password minimum length
*	this function is set here because it is a global value which can be changed here
*/
function chkPWDLen(form, ctrl, value){
	if (value.length < 6){
			return false;
		}else{
			return true;
		}
}
/*
*	function chkSelectValue 
*	passed from user management cfforms to check the select field has returned a positive value
*/
function chkSelectValue (form, ctrl, value){
	if (value == 0){
			return false;
		}else{
			return true;
		}
}
/*
*	function isNumeric
*	this is a basic regular expression check on a value to see if it is numeric
*/
function isNumeric (value){
	theRegEx=/^-{0,1}\d*\.{0,1}\d+$/;
	if (!theRegEx.test(value)){
			return false;
		}else{
			return true;
		}
}
/*
* function chkPromoType
* This function is used to set the value of the promotion value based on promo type if set to full
*/
function chkPromoType(){
	if ($F('typeFK')==3){
		$('promoValue').value='100.00';
		$('promoValue').disabled=true;
	}else{
		$('promoValue').disabled=false;		
	}
}
/*
*	function tab 
*	This new function is for tabs sections in the site, all it requires is one
*	argument (theID) which specifies the position to set (should always stat as 0 in calling page)
*	It then goes and grabs all the links and pages available in the current page
*	displays the selected page div and sets the selected link on and hides the rest of the pages
*	and removes current class from a=other available links,
*/
function tab(theID){
	// Get All Anchor elements within the PageTabs Div Element in calling Page
	var aArray = $$('#pageTabs a');
	// Get All Div Elements with Page Class in calling Page
	var idArray = $$('div.page');
	idArray.each(function(i,index){
		if (index == theID){
			// Index matches the ID - set link to current and display page
			aArray[index].className='current';
			i.show();
		}else{
			// Not a match hide the page and remove any class from links
			aArray[index].className='';
			i.hide();
		}		
	});
}
/*
*	function ClearOptions 
*	This function deletes all options in a select field
*/
function ClearOptions(OptionList) {
   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}
/*
*	function AddToOptionList 
*	This function add an option to a select field
*/
function AddToOptionList(OptionList, OptionValue, OptionText) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}
/*
*	function showErrorScreen
*	This function is called when the error screen requires an update
*/
function showErrorScreen(theScreen,theString){
	// Update the list to HTML tags from XML
	theString = theString.replace(/\&gt;/g, ">");
	theString = theString.replace(/\&lt;/g, "<");
	$(theScreen).update(theError);
	$(theScreen).innerHTML;
	$(theScreen).show();
	new Effect.Pulsate(theScreen, {pulses:2, duration: 1})
}
/*
*	function showConfirmationScreen
*	This function is called when the confirmation screen requires an update
*/
function showConfirmationScreen(theScreen,theString){
	$(theScreen).update(theString);
	$(theScreen).innerHTML;
	$(theScreen).show();
	new Effect.Pulsate(theScreen, {pulses:2, duration: 1})
}
/*
*	function closeScreen
*	This functions closes a form screen
*/
function closeScreen(theScreen,theLink){
	// If theLink variable is passed show it
	if (theLink!=undefined){
		$(theLink).show(); 
	}
	// If an exists error exists hide it
	if ($('cExists')!=undefined){
		$('cExists').hide();
	}
	// If a userName field exists clear its class
	if ($('userName')!=undefined){
		$('userName').className=''
	}
	// If a promoName field exists clear its class
	if ($('promoName')!=undefined){
		$('promoName').className=''
	}
	// Hide the Form
	if (!Prototype.Browser.IE){
		new Effect.BlindUp(theScreen, {duration: .5}); 
	}else{
		$(theScreen).hide();	
	}
}
/*
*	function showScreen
*	This functions opens a form screen
*/
function showScreen(theScreen,theLink,theFrm,scrollPos){
	// If theLink variable is passed hide it
	if (theLink!=undefined && theLink!=''){
		$(theLink).hide(); 
	}
	// Get All text inputs in theFrm if passed and clear the values
	if (theFrm!=undefined){
		var iArray=$$('#' + theFrm + ' input[type=text]');
		iArray=iArray.concat($$('#' + theFrm + ' input[type=password]')); // push password elements as well
		iArray=iArray.concat($$('#' + theFrm + ' textarea')); // push textarea elements as well
		//consoleDump(iArray.length);
		iArray.each(function(i,index){
			//consoleDump(i);
			i.value='';							 
		})
	}
	// Show the Form - No animation for IE because it is a horrible browser
	if (!Prototype.Browser.IE){
		new Effect.BlindDown(theScreen,{
				duration: 0.5, 
				scaleFrom:0,
				afterFinish:function(){
						if (scrollPos!=undefined){
							Element.scrollTo(scrollPos)
						}
					}
				});
	}else{
		$(theScreen).show();
		if (scrollPos!=undefined){
			Element.scrollTo(scrollPos)
		}
	}
}
/*
*	function handleDelete
*	This functions is called when something is requesting deletion
*/
function handleDelete(delItem,theFrm,theMsg,theBtns){
	if (confirm('Are you sure you want to delete ' + delItem + '\nThis action can not be undone!')){
		document[theFrm]['action'].value=theMsg;
		showHideSimple(theBtns);
		document[theFrm].submit();
	}else{
		return;	
	}
}
// Console Dump Functions
function consoleDump(text){
	if(window.console) {
		window.console.log(text);
	}
}
