/*				_javascript/default.js
*/

var requiredFieldsARR=new Array();

// pageload
$(document).ready(function() {    

	$('#myForm').submit(function(){

		//alert($('#field_myModule').val());
		//alert($('#field_myFunction').val());
		
		return false;

	});

	// dynamic validation

	if(typeof(requiredFieldsARR)!='undefined'){
		for(i=0;i<requiredFieldsARR.length;i++){

			$('#'+requiredFieldsARR[i]).blur(function(){

					if($(this).val()==""){

						$(this).addClass('blockError');

					} else {

						$(this).removeClass('blockError');

					}
			});

		}
	}

	openModal=function(id,width,height,sourceElement){

		$('.flashObject').css('visibility','hidden');

		var id='#modal_'+id;

		var documentMargin = ($(window).width()-$('body').width())/2;
		var maskHeight = $(document).height();
		var maskWidth = $(window).width()+documentMargin;
		var maskX = 0-documentMargin;

		// Set height and width to mask to fill up the whole screen  
		$('#mask').css({'width':maskWidth,'height':maskHeight});  
		$('#mask').css({'left':maskX});  

		// transition effect       
		$('#mask').fadeTo(1000,0.85);      
		$('#mask').fadeTo(500,0.65);
/*
		if(sourceElement!=null){

			// resize and position to sourceElement
			var sourceWidth=sourceElement.width();
			var sourceHeight=sourceElement.height();
			var sourceLeft=sourceElement.offset().left;
			var sourceTop=sourceElement.offset().top-$(window).scrollTop();;

			$(id).width(sourceWidth);
			$(id+'>iframe').width(sourceWidth);
			$(id).height(sourceHeight);
			$(id+'>iframe').height(sourceHeight);
			$(id).css('left',sourceLeft+'px');
			$(id).css('top',sourceTop+'px');

			// animate to full size and center
			var left=($(window).width()/2)-(width/2);
			var top=($(window).height()/2)-(height/2);
	
			$(id).fadeIn(500).animate({width:width,left:left,height:height,top:top},400);


		} else {
*/
			if(width!=null){
				$(id).width(width);
				$(id+'>iframe').width(width);
			}

			if(height!=null){
				$(id).height(height);
				$(id+'>iframe').height(height);
			}


			var winH = $(window).height();  
			var winW = $(window).width();

			//var scrollTop = $(window).scrollTop();
			//$(id).css('top',  (winH/2-$(id).height()/2)+(scrollTop)-50);

			$(id).css('top',  (winH/2-$(id).height()/2));
			$(id).css('left', (winW/2)-($(id).width()/2)); 

			$(id).fadeIn(500);


//		}


	}

 


	closeModalWindow=function(id,timeout,callback){
		
		if(timeout==null){timeout=1;}

		setTimeout(function(){
			$('#mask').fadeOut(1000);
			$('#modal_'+id).fadeOut(1000);
			if(callback){
				setTimeout(function(){
					eval(callback);
				},1000);
			}
		},timeout);
	 };

	// used for child iframes
	closeAllModalWindows=function(){

		$('.modalWindow').hide();  
		$('#mask, .modalWindow').hide();

	}



	// if close button is clicked  
	$('.modalExit').click(function (e) {  
		//Cancel the link behavior  
		e.preventDefault();
		$('#mask, .modalWindow',top.document).hide();  
	});       
       
	// if mask is clicked  
	$('#mask').click(function () {  

		$('.flashObject').css('visibility','visible');

		$(this).hide();
		$('.modalWindow').hide();
		$('.contextMenu').hide(500);
/*
		$('#accordion_units').accordion('option','collapsible',true);
		$('#accordion_diagnostic').accordion('option','collapsible',true);
		$('#accordion_interest').accordion('option','collapsible',true);
*/

	});  


	loadIframe=function(id,src){

		var iframe=document.getElementById('iframe_'+id);
		if(src){
			iframe.src=src;
		} else {
			iframe.src=iframe.src;
		}
	}

	loadModal=function(src,modalID){

		if(modalID==null){modalID='myModal';}
		
		var iframe=document.getElementById('iframe_'+modalID);
		iframe.src=src;
		
	}

	resizeModal=function(width,height,modalID){

		if(modalID==null){modalID='myModal';}

		var id='#modal_'+modalID;


		if(width!=null){
			$(id).width(width);
			$(id+'>iframe').width(width);
		}

		if(height!=null){
			$(id).height(height);
			$(id+'>iframe').height(height);
		}


		var winH = $(window).height();  
		var winW = $(window).width();

		//var scrollTop = $(window).scrollTop();
		//$(id).css('top',  (winH/2-$(id).height()/2)+(scrollTop)-50);

		$(id).css('top',  (winH/2-$(id).height()/2));
		$(id).css('left', (winW/2)-($(id).width()/2)); 



	}
       
}); 




/* form functions */

function switchFunction(myFunc,myModule){
// switches function select 
// submits form





		var myFunctionInput=document.getElementById('field_myFunction');
		var myModuleInput=document.getElementById('field_myModule');
		myFunctionInput.value=myFunc;
		myModuleInput.value=myModule;

		document.myForm.submit();

}



function changeFormAction(url){

		document.myForm.action=url;

}


/* helper functions */


function navigateURL(url){
// used for buttons

	window.location.href=url;

}



function formatOrdinalSuffix(n) {

	n=String(n);
	n_lastTwo=n%100;

	if((n_lastTwo >10&&n_lastTwo<14)||n==0){
	
		formatted=n+"th";

	} else {

		switch(n.substr(n.length-1,1)) {
			case '1':
				formatted=n+"st";
				break;
			case '2':    
				formatted=n+"nd";
				break;
			case '3':
				formatted=n+"rd";
				break;
			default:
				formatted=n+"th";
				break;
		 }
	 }

	 return formatted;
}




/*			created on [ 09.29.2009 ] Grenard Madrigal
/*			updated on [ 09.29.2009 ] Grenard Madrigal
/*			evolve, create © 2009
*/












