/*				_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');
						$('label[for="'+this.id+'"]').children().addClass('error');


					} else {

						$(this).removeClass('blockError');
						$('label[for="'+this.id+'"]').children().removeClass('error');

					}


			});



		}
	}

	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));
			$(id).css('left', (winW/2)-($(id).width()/2)); 

			$(id).fadeIn(500);


//		}


	}

 


	closeModalWindow=function(id,timeout,callback){
		

		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').hide(); 
		parent.closeAllModalWindows();
	});       
       
	// if mask is clicked  
	$('#mask').click(function () {  

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

		$(this).hide();
		$('.modalWindow').hide();
		$('.contextMenu').hide(500);

	});  


	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';}
		$('#modal_'+modalID).width(width);
		$('#modal_'+modalID).height(height);
		$('#iframe_'+modalID).width(width);
		$('#iframe_'+modalID).height(height);

	}

       
}); 




/* 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;
}



// navigation 

$(document).ready(function(){

	$('#navigation2 > ul > li').hover(
		
		function(){
			$(this).children('.submenu').slideDown();
		},
		function(){
			$(this).children('.submenu').slideUp();
		}

	);



});

$(document).ready(function(){ // need to generate modal_myTip for each tip that doesn't already have one

	$('.tippable').hover( // handles tool tips
		function(){
			var tip=$('#tip_'+$(this).attr('id'));
			
			if(tip.parent().hasClass('tipContainer')==false){
				var tipContainer=$(document.createElement('div'));
				tipContainer.addClass('tipContainer');
				tip.parent().append(tipContainer);
				tipContainer.append(tip);
				tip.show();
				var tipBottom=$(document.createElement('img'));
				tipBottom.attr('src',_masterURL+'_images/_structure/icon_tipBottom.png');
				tipBottom.addClass('tipBottom');
				tipBottom.css('top',tip.height());
				tipContainer.append(tipBottom);
			} else {
				var tipContainer=tip.parent();
				tipContainer.clearQueue();
			}


			tipContainer.fadeIn();
			tipContainer.children('.tipBottom').css('top',tip.height());
			tipContainer.children('.tipBottom').css('left',tip.width()-40);
			tipContainer.css('width',tip.width());
			tipContainer.css('height',tip.height());
			var tippableLeft=$(this).offset().left-tip.width();
			var tippableTop=$(this).offset().top-tip.height();
			tipContainer.css('left',tippableLeft);
			tipContainer.css('top',tippableTop);
			/*
			$('#modal_myTip').clearQueue();
			var tip=$('#tip_'+$(this).attr('id'));
			var currentTip=$('#modal_myTip').children(':last-child');
			if(currentTip.attr('id')!=tip.attr('id')){
				currentTip.hide();
			}
			tip.show();
			if(currentTip.attr('id')!=tip.attr('id')){
				$('#modal_myTip').append(tip);
			}

			$('#modal_myTip').fadeIn();
			$('#modal_myTip').css('width',tip.width());
			$('#modal_myTip').css('height',tip.height());
			var tippableLeft=$(this).offset().left-tip.width();
			var tippableTop=$(this).offset().top-tip.height();
			$('#modal_myTip').css('left',tippableLeft);
			$('#modal_myTip').css('top',tippableTop);
			*/
		},
		function(){
			var tip=$('#tip_'+$(this).attr('id'));
			var tipContainer=tip.parent();
			tipContainer.fadeOut();
		}
	);

});



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












