// JavaScript Document

var thisSPAN = false;
   var http_request = false;
   
   function makePOSTRequest(url, parameters, spanname) {
  
 
      thisSPAN = spanname;
      
      

			
			
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
	  //alert(spanname);
   }

   function alertContents() {
   
   
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            if(http_request.responseText != "") {result = http_request.responseText;

					
						
						   		var div = document.getElementById(thisSPAN);		//
																					//
								div.innerHTML = result;  							//
								
				 				//			This section was added to make sure JS is executed...
								
								
								var scripts = div.getElementsByTagName("script");
								
								
								//
								// found @ 
								//http://www.coderanch.com/t/117983/HTML-JavaScript/Execute-JavaScript-function-present-HTML
								//			modified to fit within the main ajax functiont. 
								
								// added if(scripts.length) to check if array is empty... seems like on fabmiami, it freezes
								//when there are not "scripts to feed array..
								// debugger was set to stop on all errors... that is how it was found and why it (?) occurs (?)
								// 
								
								if(scripts.length){
								for(var i=0;i<scripts.length;i++){
									
												
												var script = scripts[ i ].innerHTML;
												//alert(script);
												eval(script);  
												
									}
								}
							
				
			}


         } else { alert('There was a problem with the request. ' + thisSPAN + ': Check file Location'); }
      } else {}
	  
   }





function OptionSwap(OriginalID, dir){
	
	
	
	
	switch(dir){
	
	case 'right' :
	
	document.getElementById('LeftMenuOriginalState').value = document.getElementById(OriginalID).style.backgroundPosition;
	
	document.getElementById(OriginalID).style.backgroundPosition = '-200% 0px';
	break;

	case 'left' :
	
	document.getElementById('LeftMenuOriginalState').value = document.getElementById(OriginalID).style.backgroundPosition;
	
	document.getElementById(OriginalID).style.backgroundPosition = '0px 0px';
	break;
	}


}




function RestoreSwap(OriginalID){
	
	if(document.getElementById('clicked').value =='0'){
	
	document.getElementById(OriginalID).style.backgroundPosition = document.getElementById('LeftMenuOriginalState').value;	
	}
	
	document.getElementById('clicked').value ='0' ;
	
	
	}

 


function setContent(OriginalID, Position, OptionSwapID, dir, ThisElem){
	
	
	
	document.getElementById('LeftTopMenu').style.backgroundPosition = '-100% 0px';
	document.getElementById('LeftBtmMenu').style.backgroundPosition = '-100% 0px';
	
	
	OptionSwap(OptionSwapID, dir);
	
	
	document.getElementById('LeftMenuBodyOriginalState').value = document.getElementById(OriginalID).style.backgroundPosition;
	
	
	
	document.getElementById(OriginalID).style.backgroundPosition = (-100 * Position) + '% 0px';
	
	
	document.getElementById('clicked').value = 1;
	
	
	
	
clearBtns(OriginalID);

Show('Btn' + ThisElem.id);

	
	}



function CheckIfEmpty(ElementID){

var isError = false;


 if (document.getElementById(ElementID).value == '') {
	  //document.getElementById(ElementID).style.backgroundColor = '#2D2D2D';
	  document.getElementById(ElementID + 'Box').style.backgroundPosition = 'top';
	  
	  isError = true;
	  
	  return isError;
	  
		} else {
			
	  //document.getElementById(ElementID).style.backgroundColor = '#92B3D3';
	  document.getElementById(ElementID + 'Box').style.backgroundPosition = 'bottom';
			}

	
	};

/*
function Join(){
	 
	var EmptyFirstName = CheckIfEmpty('FirstName');
	var EmptyLastName = CheckIfEmpty('LastName');
	var EmptyEmail = CheckIfEmpty('Email');
	
	 
	if(EmptyFirstName || EmptyLastName || EmptyEmail){return}; 
	 
	//alert('no empties');
	 
	
 
 
		var poststr = 	"Name=" + encodeURIComponent(document.getElementById('FirstName').value)
		
		+ "&Last=" 	+  encodeURIComponent( document.getElementById('LastName').value)
		
		+ "&Email="		 +  encodeURIComponent( document.getElementById('Email').value);
			
			;
			
 		var File = 'contact_ty.php';
		
		var spanname = 'JoinMenu';
		
		makePOSTRequest(File, poststr, spanname);	
	}
*/


/*
function SaveContact(){

var ThePromo 		= document.getElementById('Promo');
var TheThanks 		= document.getElementById('PromoThanks');
var File 			= 'contact_ty.php';
var	spanname 		= 'Promo';

			var poststr = 	"Name=" + encodeURIComponent(document.getElementById('Name').value) 
			
			+				"&Email=" + encodeURIComponent(document.getElementById('Email').value) 
			
			;
			

			ThePromo.style.visibility = 'hidden';
			ThePromo.style.display = 'none';

			TheThanks.style.visibility = '';
			TheThanks.style.display = '';			
	
			
		makePOSTRequest(File, poststr, spanname);
				
				
	
};
*/

function VisOff(Element, opacity, empty  ){
	


opacity = typeof(opacity) != 'undefined' ? opacity : 0;
	
	
	if(empty == 'true' && document.getElementById(Element).value != ''){ return; }

	document.getElementById(Element).style.filter = 'alpha(opacity="'+ opacity + '")';
	document.getElementById(Element).style.opacity = opacity/100;
	
	}
	
	
function VisOn(Element, opacity){
	
opacity = typeof(opacity) != 'undefined' ? opacity : 100; 


	document.getElementById(Element).style.filter = 'alpha(opacity="'+ opacity + '")';
	document.getElementById(Element).style.opacity = opacity/100;
	
	}
	
	
function Show(ElementId){

/*
alert(ElementId 
	  + ' \nvisibility =  ' + document.getElementById(ElementId).style.visibility 
	  
	  + ' \n display  =  ' + document.getElementById(ElementId).style.display );
*/


if(ElementId != null  ){
	
	
	
	

				document.getElementById(ElementId).style.visibility = '';
				document.getElementById(ElementId).style.display = ''
				showBtns(ElementId);
				





	}

/*
alert(ElementId 
	  + ' \nvisibility =  ' + document.getElementById(ElementId).style.visibility 
	  
	  + ' \n display  =  ' + document.getElementById(ElementId).style.display );	
*/	
	}	

	
function ToggleVisi(ElementId){
	



if(ElementId != null  ){
	
	
	if(document.getElementById(ElementId).style.visibility != 'hidden' && document.getElementById(ElementId).style.display != 'none'){
		

				document.getElementById(ElementId).style.visibility = 'hidden';
				
				
		
		} else {	

				document.getElementById(ElementId).style.visibility = '';
	
		}
	
	}
}	


function clearBtns(ParentContainter){//because get elements by tagname is recursive you have to be careful what you wish for!
	
 
var TheDivs = document.getElementById(ParentContainter).getElementsByTagName("div");
								
								if(TheDivs.length){
								for(var i=0;i<TheDivs.length;i++){

												TheDivs[ i ].style.visibility = 'hidden';
												TheDivs[ i ].style.display = 'none';

										//alert(TheDivs[ i ].id);
		
									}
								}

	}




function showBtns(ParentContainter){  //because get elements by tagname is recursive you have to be careful what you wish for!
	
 
var TheDivs = document.getElementById(ParentContainter).getElementsByTagName("div");
								
								if(TheDivs.length){
								for(var i=0;i<TheDivs.length;i++){

												TheDivs[ i ].style.visibility = '';
												TheDivs[ i ].style.display = '';

										//alert(TheDivs[ i ].id);
		
									}
								}

	}
	
	
function Join(){
	
	
	if(document.getElementById('emailAddress').value != '' && document.getElementById('emailAddress').value != 'email') {
	
		if(document.getElementById('SubsSpinner')){ document.getElementById('SubsSpinner').style.visibility ='';}
		
	
	var poststr = 'email=' + encodeURIComponent(document.getElementById('emailAddress').value) 
	
			//	+ '&last=' + encodeURIComponent(document.getElementById('last').value) 

			//	+ '&email=' + encodeURIComponent(document.getElementById('email').value) 

	;
	
	
		var File = '/thankyou.php';
	
	
		var spanname = 'subscribe_ok_button';
		
	
		makePOSTRequest(File, poststr, spanname);	
	
	}	
	
}
	
	
	
	
function PrepField(Obj, DefaultVal){
 
		
		switch(trim(Obj.value)){
		
			case DefaultVal: Obj.value = '' ;break;
		
			case '': Obj.value = DefaultVal ;break;	
			
			default : Obj.value = trim(Obj.value); break;
	
		
		}

 
	}	
	
	
	
	
	
	function trim(str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

	
	
	
	
	
	
function Load(toLoad, ElementId){


if(ElementId == ''){
	
		spanname = 'SiteHolder';
	
	}  else {	spanname = ElementId;} 

	var poststr = 'toLoad=' + encodeURIComponent(toLoad) 
	
			//	+ '&last=' + encodeURIComponent(document.getElementById('last').value) 

			//	+ '&email=' + encodeURIComponent(document.getElementById('email').value) 

	;

		var File = '/' + toLoad + '.php';
	
	
		var spanname = ElementId;
		
	
		makePOSTRequest(File, poststr, spanname);	
	
	return(false);
	
	}
	
	
function clearField(Obj){
	
	if(Obj.value == Obj.defaultValue ){Obj.value = '';} else if(Obj.value == '') {Obj.value = Obj.defaultValue; }
	
	
		
	};
		
function osciloscopeExec(action){
	
	var osci = document.getElementById('osciloscopeImg');

	
	
	
	switch(action){

	case 'play' : 
	
		osci.style.display = '';
		osci.style.visibility = '';	
		
		break;	

		
	case 'stop' : 
	
		osci.style.display = 'none';
		osci.style.visibility = 'hidden';	
		
		break;		
		
		default :

	
	//ity:hidd
	if(osci.style.display == 'none'){
		
		osci.style.display = '';
		osci.style.visibility = '';
	
		
		} else {
			
		osci.style.display = 'none';
		osci.style.visibility = 'hidden';			
			
	break;
		}
			
			}
	
	
	
	
	
	
	
};
