var ajax_url='/includes/cfc/ajaxBridge_user.cfc?wsdl';
/*
* function chkUserNameExists
* This function is ran after all default form validations pass
* By default the form will not submit, if this Ajax Call returns false
* then it submits the form for you, if not the username exists error displays
*/
function chkUserNameExists(cnt){
	if ($F('email') == $F('cEmail') || !cnt){
		// Parameters
		var pars='method=checkUserName&qUserName='+ $F('email');
		// New Ajax Request
		new Ajax.Request(ajax_url,{
			// changed method to post due to IE7 cache bug
			method: 'post',
			parameters:pars,
			onSuccess: function (transport){
				// une = Name Exists
				var une=transport.responseText.stripTags().strip();
				if (une == 0){
					if (cnt){
					// Name is good call submit form function
					// Set the action value
					$('theFrm')['action2'].value='CREATING REGISTRATION...';
					//
					$('theFrm')['action2'].disabled=true;
					// Submit Form
					document.theFrm.submit();
					}
				}else{
					// Name already exists call alert function
					if (cnt){alert('The e-mail address '+ $F('email') +' is already in use, please enter another e-mail address.');}
					$('email').className='inputWithError';
					$('cExists').update('E-mail already in use');
					$('cExists').show();
					if (!cnt){Effect.Pulsate('cExists',{ duration:.5, pulses:2, from:.25 });}
				}			
			}
		});
	}else{
		if (cnt){
			alert('Your e-mail entries do not match');	
		}
	}
}

function chkUserNameExists2(cnt){
	if ($F('email') != $F('oEmail')){
		// Parameters
		var pars='method=checkUserName&qUserName='+ $F('email');
		// New Ajax Request
		new Ajax.Request(ajax_url,{
			// changed method to post due to IE7 cache bug
			method: 'post',
			parameters:pars,
			onSuccess: function (transport){
				// une = Name Exists
				var une=transport.responseText.stripTags().strip();
				if (une == 0){
					if (cnt){
					// Name is good call submit form function
					// Set the action value
					$('theFrm')['action2'].value='UPDATING ACCOUNT...';
					$('theFrm')['action2'].disable();
					// Submit Form
					document.theFrm.submit();
					}
				}else{
					// Name already exists call alert function
					if (cnt){alert('The e-mail address '+ $F('email') +' is already in use, please enter another e-mail address.');}
					$('email').className='inputWithError';
					$('cExists').update('E-mail already in use');
					$('cExists').show();
					if (!cnt){Effect.Pulsate('cExists',{ duration:.5, pulses:2, from:.25 });}
				}			
			}
		});
	}else{
		if (cnt){
			// Submit Form
			$('theFrm')['action2'].value='UPDATING ACCOUNT...';
			$('theFrm')['action2'].disable();
			document.theFrm.submit();	
		}
	}
}

/*
**********************************
WINDOW OBJECT VARIABLES
**********************************
*/
	var WindowObjectReference = null; // global variable
	var PreviousUrl;	
/*
*	function openWin (Opens a centered window object)
*
*	@url = URL String (Required)
*	@win = Window Name (Required)
*	@myWidth = Window Width (Required)
*	@myHeight = Window Height (Required)
*	@scrollBars = Yes/No Value (Required)		
*/
function openWin(url,win,myWidth,myHeight,scrollBars){
	var tHeight=screen.height/2;
	var tWidth=screen.width/2;
	var top=tHeight-myHeight/2;
	var left=tWidth-myWidth/2;
	var Feats="width="+myWidth+",height="+myHeight+",top="+top+",left="+left+", screenY=" +top+",screenX="+left+",scrollbars="+scrollBars+", toolbar=no, status=yes, resizable=no,alwayRaised=yes";
	if(WindowObjectReference == null || WindowObjectReference.closed)
		{
			WindowObjectReference=window.open(url,win,Feats);
			WindowObjectReference.focus();
		}
		else if(previousUrl !=url)
		{
			WindowObjectReference=window.open(url,win,Feats);
			WindowObjectReference.focus();
		}
		else
		{
			WindowObjectReference.focus();
		}
	previousUrl=url;
}
/*
*	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 chkPWDLen2(form, ctrl, value){
	if (value.length!=0 && value.length < 6){
		return false;
	}else{
		return true;
	}
}

/*
*	function chkPWDMatch
*	passed from password reset form
*/
function chkPWDMatch(form, ctrl, value){
	if (form.n_password.value != form.c_password.value){
		return false;
	}else{
		return true;
	}
}

/*
*	function showHideSimple (Closes one div object and displays another based on list)
*
*	@theList = List with 2 divs (div to close, div to open)
*/
function showHideSimple(theList){
	//split the list
	thisList=theList.split(',');
	// show the specified div
	document.getElementById(thisList[0]).style.display = "block";
	document.getElementById(thisList[1]).style.display = "none";
}

/*
*	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 to retrieve the flash movie - used for js-swf connections
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		 return window[movieName];
	} else {
		 return document[movieName];
	}
}

// functions used to load movies in lightbox
function activateMovie(whichMovie){
		var arrayPageSize = getPageSize();
		
		Element.setWidth('video_overlay', arrayPageSize[0]);
		Element.setHeight('video_overlay', arrayPageSize[1]);
		$('video_overlay').setOpacity(0);
		$('video_overlay').show();
		new Effect.Opacity('video_overlay', {from:0,to:.75,duration:.5,afterFinish:function(){
				// calculate top and left offset for the lightbox 
				var arrayPageScroll = getPageScroll();
				var video_holderTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
				Element.setTop('video_holder', video_holderTop);
				$('video_holder').setOpacity(100);
				$('video_holder').show();
				loadMovie(whichMovie);
			}
		});
}

function deActivateMovie(){
	
		swfobject.removeSWF("mov_fl");
		
		$('video_border').update('<div id="video_player"></div>');
		
		new Effect.Opacity('video_holder', {from:1,to:0,duration:.5});
		new Effect.Opacity('video_overlay', {from:.75,to:0,duration:.5,delay:.5,afterFinish:unloadMovie});
}

function loadMovie(whichMovie){
		
		// embed the flash movies
		var flashvars = {
			ldmov: whichMovie
		};
		var params = {
		  menu: "false",
		  wmode: "transparent"
		};
		var attributes = {
		  id: "mov_fl",
		  name: "mov_fl"
		};
	
		swfobject.embedSWF("../includes/swf/v3_movieLoader_nstc.swf?v=2", "video_player", "720", "486", "7", "", flashvars, params, attributes);
		
}

function unloadMovie(){
	
		$('video_overlay').hide();
		$('video_holder').hide();
		
}

function loadAnimation(theMovie,theDiv,theSWF,theWidth,theHeight){
	var temp = theDiv + '_flsw';
	
	
	
	// embed the flash movies
	var flashvars = {
		ldmov: theMovie
	};
	var params = {
	  menu: "false",
	  bgcolor: "#ffffff"
	};
	var attributes = {
	  id: temp,
	  name: temp
	};

	swfobject.embedSWF("/includes/swf/"+theSWF, theDiv, theWidth, theHeight, "7", "", flashvars, params, attributes);
		
}