<!--
// -------------------------------------- Make XMLHttpRequest Request Object --------------------------------------
// Build a new Object and check to see what browser it is
var request = null;

try {
 request = new XMLHttpRequest();
} catch (trymicrosoft) {
 try {
   request = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (othermicrosoft) {
   try {
     request = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (failed) {
     request = null;
   }
 }
}

if (request == null)
 alert("Error creating request object!");

var request2 = null;

try {
 request2 = new XMLHttpRequest();
} catch (trymicrosoft) {
 try {
   request2 = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (othermicrosoft) {
   try {
     request2 = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (failed) {
     request2 = null;
   }
 }
}

if (request2 == null)
 alert("Error creating request object!");

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e){
 // Internet Explorer
 try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
 }
return xmlHttp;
}

//includes js files for the application
function include(file){
  var script  = document.createElement('script');
  script.type = 'text/javascript';
  script.src  = file;
  script.defer = false;
  document.getElementsByTagName('head').item(0).appendChild(script);
}
// Include other files
include('/templates/common/js/livesearch.js');  // live search bar
//include('/templates/common/js/ticker.js');      // ticker
include('/templates/common/js/newsticker.js'); // news and weather ticker
include('/templates/common/js/trim.js'); // news and weather ticker
include('/templates/common/js/level2-newsevents.js'); // level news and calendar piece
//include('/templates/common/js/lightwindow-vcsu.js');  // Light window library for popup windows

function trim(str){
	var newstr = '';
	for(var i = 0;i<str.length;i++) { newstr = (str.charAt(i)!=' ' && str.charAt(i)!='')? newstr + str.charAt(i):newstr; }
	return newstr;
}

// ScriptAculoUs Effects 
function myEffects(effect,id,val1,val2){
	//alert(val1);
	//val1 = parseFloat(val1)*1000;
	//val2 = parseFloat(val2)*1000;
	
	switch(effect){
		case 'blindUp':
		case 'slideUp':
			$('#' + id).slideUp(val1);
			//new Effect.SlideUp(document.getElementById(id), {duration:val1}); return false;
		break;
		case 'slideDown':
		case 'blindDown':
		    $('#' + id).slideDown(val1);
			//new Effect.SlideDown(document.getElementById(id), {duration:val1}); return false;
		break;
		case 'fade':
			$('#' + id).fadeOut(val1);
			//new Effect.Fade(document.getElementById(id), {duration:val1}); return false;
		break;
		case 'appear':
			$('#' + id).show(val1);
			//new Effect.Appear(document.getElementById(id), {duration:val1}); return false;
		break;
	}	
}
// inherited from dojo
function wipes(effect,id,duration,other)
{
	//var duration = duration/1000;
	//alert(duration);
	switch(effect) {
		case 'wipeIn':  $('#' + id).slideDown(duration); //new Effect.SlideDown(document.getElementById(id), {duration:duration}); return false; break;
		case 'wipeOut': $('#' + id).slideUp(duration);   //new Effect.SlideUp(document.getElementById(id), {duration:duration}); return false; break;
		case 'fadeIn':  $('#' + id).fadeIn(duration);    //new Effect.Appear(document.getElementById(id), {duration:duration}); return false; break;
		case 'fadeOut': $('#' + id).fadeOut(duration);   //new Effect.Fade(document.getElementById(id), {duration:duration}); return false; break;
	}
}

//Opacity
/* ------------------------------------ This function sets opacity on an object using JQuery------------------------------------ */
function setJOpacity(opacity, theID) {
	$("#"+theID).fadeTo(200,(opacity*(.01)));
}

function setOpacity(opacity, theID) {
 var object = document.getElementById(theID).style;
 // If it's 100, set it to 99 for Firefox.
 if (navigator.userAgent.indexOf("Firefox") != -1) {
  if (opacity == 100) { opacity = 99.9999; } // This is majorly awkward
 }
try {object.filter  = "alpha(opacity=" + opacity + ")"; } catch(err) { object.opacity = (opacity / 100); }
 
}

// Email Validation
function emailValidate(field){
	var emailID=document.getElementById(field);
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailID.value)){
	return (true)
	}	
	return (false)
 }

// Create random string
function randomString(mylength,withnumbers) {
	if(withnumbers) {
		var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	} else {
		var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	}
	var randomstring = '';
	for (var i = 0; i < mylength; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

// Create dynamic XMLHttpRequest object
function fetchObj(){
	var myobj   = randomString(6,0);
	try { myobj = new XMLHttpRequest(); } catch (trymicrosoft) { try { myobj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { myobj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { myobj = null; } } }
	if (myobj   == null) alert("Error creating request object!");
	return myobj;
}

//-->
