// JavaScript Document

function defValue(fld,val,act){
	
	if (act == true){
		// this runs when we leave the field
		// reset to default value if left blank
		if ($F(fld) == ''){
			// set value
			$(fld).value = val;
			$(fld).addClassName('defaultValue');
		}
	}else{
		// this runs when we click or focus on the field
		// remove class
		$(fld).removeClassName('defaultValue');
		// on initial click we clear it if it matches the value
		if($F(fld).toUpperCase() == val.toUpperCase()){
			$(fld).value = '';
		}
	}
	
}

function checkEmailFrm(){
	
	// Webservice URL
	var url='/includes/cfc/ajax.cfc?wsdl';
	// Parameters
	var pars='method=registerEmail&regName=' + $F('regName') + '&regEmail=' + $F('regEmail');
	var goodCall = true;
	var msg = '';
	
	$('signup').disable();
	//$('signup').value = 'Registering';
	$('signup').setStyle({color: '#999'});
	$('signupFrm').setOpacity(0.75);
	
	if ($F('regName') == '' || $F('regName').toLowerCase() == v.valName.toLowerCase() ){
		msg = v.reqName;	
		goodCall = false;
	}
	else if ($F('regEmail') == '' || $F('regEmail').toLowerCase() == v.valEmail.toLowerCase() ){
		msg = v.reqEmail;	
		goodCall = false;
	}
	
	// make ajax call if still good
	if(goodCall){
		// New Ajax Request
		new Ajax.Request(url,{
			// changed method to post due to IE7 cache bug
			method: 'post',
			parameters:pars,
			onSuccess: function (transport){
				var retVal=transport.responseText.stripTags().strip();
								
				// start return
				if (retVal == 0){
					resetSubmit(v.reqEmail);
				}else{
					
					Effect.Fade('theFrm', { duration: .25 });
					$('theMsg').update('<p>' + v.confirmMsg + $F('regName') + '.</p>');
					$('theMsg').innerHTML;
					Effect.Appear('theMsg', { duration: .25, delay:.25 })
					
				}
				// end return
			}
		});
	}
	
	if(!goodCall){
		resetSubmit(msg);
	}	
	
}

function resetSubmit(msg){
		alert(msg);
		$('signup').enable();
		$('signup').setStyle({color: 'inherit'});	
		$('signupFrm').setOpacity(1);
}

/*
*	function chkSelectValue 
*	passed from user management cfforms to check the select field has returned a positive value
*/
function chkSelectValue (form, ctrl, value){
	if (value == 'forgot'){
			return false;
		}else{
			return true;
		}
}


function checkRegFrm(mID){
	
	// first check the email and password entries ,atch then run ajax functions
	
	if (mID == undefined){
		mID = 0;	
	}
	
	if ($F('cstPassword') != $F('cstPasswordConfirm')){
		$('cstPasswordConfirm').className = 'inputWithError';
		$('cstPasswordConfirm').focus();
		$('errorPwd').show();
		alert(v.pwdNoMatch);
		return false;
	}
	
	// this function exists in ajax.js
	chkEmailExists(1,mID); // after this function returns it continues to the email check and if all is good we submit
	
}

function showHideSimple(theList){
	//split the list
	thisList=theList.split(',');
	// set display properties
	$(thisList[0]).show();
	$(thisList[1]).hide();
}
