function MWJ_findObj( oName, oFrame, oDoc ) {
	if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
	if( oDoc[oName] ) { return oDoc[oName]; } if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
	if( oDoc.getElementById && oDoc.getElementById(oName) ) { return oDoc.getElementById(oName); }
	for( var x = 0; x < oDoc.forms.length; x++ ) { if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
	for( var x = 0; x < oDoc.anchors.length; x++ ) { if( oDoc.anchors[x].name == oName ) { return oDoc.anchors[x]; } }
	for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
		var theOb = MWJ_findObj( oName, null, oDoc.layers[x].document ); if( theOb ) { return theOb; } }
	if( !oFrame && window[oName] ) { return window[oName]; } if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
	for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
		var theOb = MWJ_findObj( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
	return null;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


var gObj,gHex,timer,m1id,m2id,m3id;
function NN_tr_start(obj,hex,type){
	//window.status = obj.id;
	var isMoz = parseInt(navigator.appVersion) >= 5 && navigator.appName == 'Netscape' ? true : false;
	if (type == 'fade' && !isMoz){gHex=hex;gObj=obj;NN_tr_fadeIn();
	} else { obj.style.backgroundColor=hex;}
	obj.style.cursor='hand';
	l1 = obj.id.substring(2,1);
	if (l1 == '2')
	{
		//NN_tr_start(MWJ_findObj('m1_10'),'#89bae1','fade');
	}
	else
	{
		//NN_tr_reset(MWJ_findObj('m1_10'),'#dbdbdb');
	}
	//alert(l1);
}

function NN_tr_fadeIn_old(){
	var cntr=0,pObj=gObj.style.backgroundColor;
	var r = parseInt(gHex.substring(1,3),16),g = parseInt(gHex.substring(3,5),16), b = parseInt(gHex.substring(5,7),16);
	var rr = parseInt(pObj.substring(1,3),16),gg = parseInt(pObj.substring(3,5),16),bb = parseInt(pObj.substring(5,7),16);
		if (r!=rr){if(rr<r){rr++;}else{rr--;}}else{cntr++;}
		if (g!=gg){if(gg<g){gg++;}else{gg--;}}else{cntr++;}
		if (b!=bb){if(bb<b){bb++;}else{bb--;}}else{cntr++;}
	rr=rr.toString(16);gg=gg.toString(16);bb=bb.toString(16);
	rr=rr.length==1?'0'+rr:rr;gg=gg.length==1?'0'+gg:gg;bb=bb.length==1?'0'+bb:bb;
	gObj.style.backgroundColor='#'+rr.toUpperCase()+gg.toUpperCase()+bb.toUpperCase();
	if (cntr!=3){timer=setTimeout('NN_tr_fadeIn()',0);}
}

function NN_tr_fadeIn(){
	var cntr=0,pObj=gObj.style.backgroundColor;
	gObj.style.backgroundColor= gHex;
}

function NN_tr_reset(obj,hex){
	obj.style.backgroundColor=hex;clearTimeout(timer);
}

function fnOpenPrint(url)
{
	window.open(url);
}



function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


var xmlhttp

function loadXMLDoc(url)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("POST",url,true)
  xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  xmlhttp.send(null)
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  //alert(xmlhttp.getResponseHeader("Content-Type"));
  //alert(xmlhttp.getAllResponseHeaders());
  document.getElementById('cs_holder').innerHTML=xmlhttp.responseText
  }
  else
  {
  alert("Problem retrieving page data:" + xmlhttp.statusText)
  }
  }
}

function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	//alert(y);
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}


var pageoffset = 402;

function scrollmeFF(myid)
{
	coords = getAnchorPosition("link" + myid);
	document.getElementById('cs_scroller').scrollTop = coords.y - pageoffset;
}



function autoscroll()
{
	document.increment = document.increment + 9;
	if (document.sdiff >= 0)
	{
		document.getElementById('cs_scroller').scrollTop = document.sstart + document.increment;
		if (document.getElementById('cs_scroller').scrollTop <= document.starget)
		{
			setTimeout("autoscroll()",1);
		}
	}
	else
	{
		document.getElementById('cs_scroller').scrollTop = document.sstart - document.increment;
		if (document.getElementById('cs_scroller').scrollTop >= document.starget)
		{
			setTimeout("autoscroll()",1);
		}
	}
	
}

function loadcs(dept,csid)
{
	document.mycsid = csid;
	myinp = MWJ_findObj('cs_holder');
	myinp.innerHTML="<div style='height:316px;'><div style='position:relative;left:230px; top:140px;'><img src='images/ajax-loader.gif'></div></div>";
	setTimeout("loadXMLDoc('cs_builder.asp?dept=" + dept + "&csid=" + csid + "')",500);
	myinp.style.height = 'auto';
	document.increment = 0;
	document.coordinates = getAnchorPosition("link" + csid);
	document.myid = csid;
	document.starget = document.coordinates.y - pageoffset;
	document.sstart = MWJ_findObj('cs_scroller').scrollTop;
	document.sdiff = document.starget - document.sstart;
	if (navigator.userAgent.indexOf("MSIE")!=-1)
	{
		//autoscroll();
	}
	else
	{
		//autoscroll();
		//scrollmeFF(csid);
	}
	//initscroll(document.getElementById('cs_scroller').scrollTop,document.coords.y - 442);
	//scrollme2(csid);
	
}

function loadalert(id)
{
	if (id != 0)
	{
	if (confirm('Are you sure you want to load this e-alert?.\nAll unsaved changes will be lost.'))
	{
		window.location = 'etemplate.asp?load=' + id;
	}
	}
	else
	{
		alert('Please choose an e-alert from the list.');
	}
	
}

function addalert()
{	
	if (confirm('Are you sure you want to start a new e-alert?'))
	{
		window.location = 'addalert.asp';
	}
}
