// ==JSFunctionIncludeFile==
// @incFilename bgajaxfunct.js (this should be the this files name)
// @author Anthony Ortega
// @griefdescription  this file will handel most of  the core functions will also contain sone event handeler templates
// @version N/A (optional)
// @prereqFile prototype.js*
// @prereqFile scriptaculous.js*
// @developed 2006-04-17
// @updated 2006-04-19
// @updateAuthor list of people who have modified this file
// @compatible MarketPlace
// ==/JSFunctionIncludeFile==
/* @filenotes FILE_NOTES
* more info
* if needed
 file for new marketplace functions
 if you add something here PLEASE COMMENT IT 
*/

// ==JSFunction==
// @fnname  var jsLoader return:object// function name ie fnClose or var fname
// @authorDate Anthony Ortega, 01/15/07
// @description Put a good description in here
// @dependson// [name type internam or external
// @dependson// [name,  type, int|ext], [//next go here] internam or external
// @developed 2006-04-17
// @updated 2006-04-19
/* @updatenote    
star here(add lines as nedded)
*/
// ==JSFunction==



// ==JSFunction==
// this should be the this files name
// @scriptname bgajaxfunct.js //function name 
// @author Anthony Ortega
// @description Put a good description in here
// @dependson// name type internam or external
// @dependson// name type internam or external// @developed 2006-04-17
// @updated 2006-04-19
// @updateAuthor list of people who have modified this file
// @compatible MarketPlace
// ==JSFunction==

var jsLoader =  {
  Version: '1',
  require: function(libraryName) {
    // inserting via DOM fails in Safari 2.0, so brute force approach
    document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
  },
  cssLoad: function(libraryName) {
    // inserting via DOM fails in Safari 2.0, so brute force approach
    new Insertion.Bottom($("head"), "<link rel=\"stylesheet\" type=\"text/css\" href=\""+libraryName+"\" media=\"screen\" />");

  },
  load: function() {
    if((typeof Prototype=='undefined') || 
       (typeof Element == 'undefined') || 
       (typeof Element.Methods=='undefined') ||
       parseFloat(Prototype.Version.split(".")[0] + "." +
                  Prototype.Version.split(".")[1]) < 1.5)
       throw("Prototype JavaScript framework >= 1.5.0");
    
    $A(document.getElementsByTagName("script")).findAll( function(s) {
      return (s.src && s.src.match(/bgajaxfunct\.js(\?.*)?$/))
    }).each( function(s) {
      var path = s.src.replace(/bgajaxfunct\.js(\?.*)?$/,'');
      var includes = s.src.match(/\?.*load=([a-z,]*)/);
      (includes ? includes[1] : '').split(',').each(
       function(include) {
	 //  alert(path+include+'.js');
	   jsLoader.require(path+include+'.js'); 
	   
	   });
	  var cssPath = "/stylessheets/";
	  var incCSS = s.src.match(/\?.*cssLoad=([a-z,]*)/);
	        (incCSS ? incCSS[1] : 'm247Globals').split(',').each(
       function(include) {
	 //  alert(path+include+'.js');
	   //jsLoader.require(path+include+'.css'); 
	   
	   });
    });
  }
}


// attaches functions using the prototype page load DOM method
jsLoader.load();
// anthony ortega  developed 02/07

	Event.observe(window, 'load', function() { 
		if(document.getElementById('divResults') != null)
	{
		$('prntImage').hide();
	}
		//  alert(jsLoader.Version);
									   

})
function fnLoadPrint()
{
	var msg="Use your browsers print button to print results. <input type='button' value='Click here to return' onclick='fnUnloadPrint()'>";
	var printdiv = '<div style="width:500px;" id="printarea">'+msg+'<br/>'+$('divResults').innerHTML+'</div>';
	new Insertion.Before($('structuraltable').id, printdiv);
	$('structuraltable').hide();
	$('btnPrintRes').hide();
	//document.body.innerHTML = ;
	//$('prntremsg').update(msg);
}
function fnUnloadPrint()
{
	$('printarea').remove();
	$('structuraltable').show();
	$('btnPrintRes').show();
}
// ==JSFunction== 
// activate the "other" text area
// fieldty is either "rd" for radio or "cb" for checkbox
function fnCheckOther(intQuest, fieldty)
{
	var form = $('pollForm');
	var input;
	if(intQuest > 0 && fieldty)
	{
		
		if(fieldty =="cb")
		{
			input = form["question"+intQuest+"_other"];
	
			if($(input).checked)
			{
				$("str_"+intQuest+"_other").show();
				$("str_"+intQuest+"_other").enable();
				$("ComCt_"+intQuest).show();
				$("Ct_"+intQuest).update($F("str_"+intQuest+"_other").length);
			}else if(!$(input).checked)
			{
				
				$("str_"+intQuest+"_other").disable();
				$("str_"+intQuest+"_other").value ="";
				$("str_"+intQuest+"_other").hide();
				$("ComCt_"+intQuest).hide();
			}
		}
		else if(fieldty =="rd")
		{
			input = "input.rdgr"+intQuest;
			if(Object.isElement($("str_"+intQuest+"_other")))
			{
				var clearOth = 1;
				$$(input).each(function(s, index) {
									
									if($(s).checked && $(s).value == "other")
									{
											$("str_"+intQuest+"_other").show();
											$("ComCt_"+intQuest).show();
											clearOth = 0;
											$("str_"+intQuest+"_other").enable();
									} else
									{
											$("str_"+intQuest+"_other").disable();
											//
											$("str_"+intQuest+"_other").hide();
											$("ComCt_"+intQuest).hide();
											// alert("str_"+intQuest+"_other  is clear =0"+$(s).checked);
										
									}
});
			if(clearOth == 1)
			{
				$("str_"+intQuest+"_other").value ="";
			} else
			{
				$("Ct_"+intQuest).update($F("str_"+intQuest+"_other").length);
			}
			}
		 } else
		alert(fieldty);
	
	}
}
