/*  ^^^^^^^^^^^Move from default.aspx ^^^^^^^^^^^^^^^^^^^*/
var MyKeyCtrl;
function MyKey(e)
{

	if(MyKeyCtrl == null)
	{ 
		return false; 
	}	
	if (MyKeyCtrl.length == 0) 
	{
		return false;
	}
	else if (MyKeyCtrl.length == 1) 
	{
		return true;
	}
	else
	{
		fnTrapKD(MyKeyCtrl, e);
	}
}

function IsGreaterThanOne(sender,e)
{
	if (e.Value=="" || e.Value==" ")
	{
	 e.IsValid = false;
	 } else {
		if (e.Value * 1 > 0)
		{
			e.IsValid = true;
		} else {
			e.IsValid = false;
		}
	}
}
			
function fnTrapKD(btnID, e)
{

btn = findObj(btnID);
 if (document.all){
  if (e.keyCode == 13){
   e.returnValue=false;
   e.cancel = true;
   btn.click();
  }
 }
 else if (document.getElementById){
  if (e.which == 13){
   e.returnValue=false;
   e.cancel = true;
   btn.focus();
   btn.click();
  }
 }
 else if(document.layers){
  if(e.which == 13){
   e.returnValue=false;
   e.cancel = true;
   btn.focus();
   btn.click();
  }
 }
}
function clearValue(idname)
{
	var t = findObj(idname, false);
	t.value = "";
		return false;
	
}
function findObj(n, d) { 
	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=findObj(n,d.layers[i].document);
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
	return x;
}
var agt=navigator.userAgent.toLowerCase();
			var version  = parseInt(navigator.appVersion);
			var is_nav    = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
			var is_nav6   = (is_nav && (agt.indexOf('netscape6') != -1));
			var is_nav4 = (is_nav && (version == 4));
			
/*  ^^^^^^^^^^^Move from default.aspx ^^^^^^^^^^^^^^^^^^^*/




var popUp; 
function doOpen(x)
{
newWin = window.open(x,"small","width=800,height=600,toolbar=no,scrollbars=yes,resizable=no");
}
/*
function OpenCalendar(idname, postBack)
{
	
	idname = 'RadDesigner1:_ctl2' + idname;
	popUp = window.open('CalendarPop.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=208,left=200,top=250');
}
*/
function OpenCalendar2(idname, postBack)
{
	popUp = window.open('CalendarPop.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=265,height=220,left=350,top=200');
}

function OpenCalendarForCorrespondingRadioButton (idname, rbidname, rbindex, postBack)
{
	popUp = window.open('CalendarPop.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&rid=' + rbidname + '&rbindex=' + rbindex + '&postBack=' + postBack, 
		'popupcal', 
		'width=265,height=220,left=350,top=200');
}


function OpenCalendar3(idname, postBack)
{
	popUp = window.open('../CalendarPop.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=208,left=200,top=250');
}

function OpenCalendar1(idname, postBack)
{
	
	//idname = 'RadDesigner1:_ctl2' + idname;
	var date = document.forms[0].elements[idname].value
	
	//alert(document.forms[0].elements[idname].name)
	//popUp = window.open('/CalendarPop.aspx?formname=' + document.forms[0].name + 
	//	'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
	//	'popupcal', 
	//	'width=165,height=208,left=200,top=250');
	
	popUp = window.open('../CalendarPop.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=208,left=200,top=250');
}

function Test()
{
	//popUp = window.open('CalendarPop.aspx','width=165,height=208,left=200,top=250');
	//window.open('/CalendarPop.aspx');
	alert('test');
	//alert(document.forms[0].name);
	alert('12' + document.Stanford[12].name);
	alert('13' + document.Stanford[13].name);
	alert('14' + document.Stanford[14].name);
	alert('15' + document.Stanford[15].name);
	alert('16' + document.Stanford[16].name);
	alert('17' + document.Stanford[17].name);
	alert('18' + document.Stanford[18].name);
	alert('19' + document.Stanford[19].name);
	alert('20' + document.Stanford[20].name);
	
	alert(document.Form2[12].value);
	//alert(document.Form2.value)
}
function OpenCalendar(ElementNumber, postBack)
{
	//ElementNumber = the index of element within the form being passed in
	//We have to pass in the element # b/c the RadDesigner appends a funky name to our elements
	
	popUp = window.open('../CalendarPop.aspx?formname=' + document.forms[0].name + 
		'&id=' + ElementNumber + '&selected=' + document.forms[0].elements[ElementNumber].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=208,left=200,top=250');
}
function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}	


function SetDateWithRadioButton (formName, id, newDate, rId, rIndex, PostBack)
{
       

	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	theform.elements[rId].checked = true;	
	
	if (postBack)
		__doPostBack(id,'');
}



function deleteCookie(name, path, domain) {
  if (Get_Cookie(name)) document.cookie = name + "=" +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) {
      c_start = c_start + c_name.length + 1;
      c_end = document.cookie.indexOf(";", c_start);
      if (c_end == -1) c_end = document.cookie.length;
      return unescape(document.cookie.substring(c_start, c_end));
    }
  }
  return "";
}


function setCookie(c_name, value, expiredays) {

  var exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  document.cookie = c_name + "=" + escape(value) + ";expires=" + exdate.toGMTString();
  //alert(exdate.toGMTString())
}


function WarnUser(SchoolName, timeout,logouturl, refresh)
{
	dStarted = new Date();
	window.focus();
	var url
	if (logouturl == "")
	  url = "default.aspx?logout=true"
	else {

	  url = "default.aspx?logout=true&logouturl=" + logouturl
	}

	// for facebook only
	// want to avoid the session timing out
	/* --Adam was trying this 3/4/2009
	if (top != self) {
	    window.refresh();
	}
    */

	 var RememberMe = getCookie('EngageAuth');
	 if (RememberMe != null && RememberMe != "") {
	   KeepAlive(url, SchoolName, timeout, logouturl, refresh)
	 }

	
	if ( confirm("Due to inactivity you are about to be logged out.\nClick 'OK' to continue your session, or click 'Cancel' to log out.\nFor your security reasons, if you are unable to respond to this message\nwithin 2 minutes you will be automatically logged out.")) 
	/*if ( confirm("There has been no activity on the " + SchoolName + " site for " + timeout + " minutes.\nClick 'OK' to continue your session,or click 'Cancel' to log out.\nFor your security if you are unable to respond to this message\nwithin 2 minutes you will be logged out automatically.")) */
	{ 
		//post the page to itself 
		dNow  = new Date();
		dWatch = dNow.getTime() - dStarted.getTime();
		if (dWatch > 120000) //if longer than 2 minutes, logout
		{
		  document.location.href = url
		}
		else {
		  KeepAlive(url, SchoolName, timeout, logouturl, refresh);
		}
	} 
	else 
	{
	  document.location.href = url
	}
}

function KeepAlive(url, SchoolName, timeout,logouturl, refresh) {
  j1_3_2.ajax({
    type: "POST",
    url: "modules/common/COMN.asmx/SessionKeepAlive",
    data: '{"UserGUID":"' + UserGUID + '"}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(result) {
      if (result.d != null) {
        //alert(result.d);
        if (result.d == true) {
          var timerTimeout = timeout * 60000
          window.setTimeout("WarnUser('" + SchoolName + "','" + timeout + "','" + logouturl + "','" + refresh + "')", timerTimeout);
        }
        else {
          document.location.href = url
        }
      }
    },
    complete: function() {

    }
  });
}

function CenterWindow() 
{ 
	var NS=document.all;
	if(!NS){self.moveTo((self.screen.width - self.outerWidth) / 2, (self.screen.height - self.outerHeight) / 2);}
	else{self.moveTo((self.screen.width-document.body.clientWidth) / 2, (self.screen.height-document.body.clientHeight) / 2);}
	self.focus(); 
}

function Refocus()
{
	this.focus();
}

function InsertImage(idname, folder) {

	//var folder = 'Schools/Stanford/Images';
	var galleryscript = 'SelectImage.aspx?rif='+folder+'&cif='+folder;
	//if (FTB_HelperFilesParameters != '') galleryscript += '&' + FTB_HelperFilesParameters;
	imgArr = window.showModalDialog(galleryscript,window,'dialogWidth:560px; dialogHeight:500px;help:0;status:0;resizeable:1;');

	if (imgArr != null) {
		imagestring = imgArr['filename'];
		//sel = editor.document.selection.createRange();
		//sel.pasteHTML(imagestring);
		document.forms[0].elements[idname].value = imagestring
	} else {
		//alert("You did not select an image");
	}
}

function InsertImage1(idname, folder) {

	//var folder = 'Schools/Stanford/Images';
	var galleryscript = '../../PCIControls/SelectImage.aspx?rif='+folder+'&cif='+folder;
	//if (FTB_HelperFilesParameters != '') galleryscript += '&' + FTB_HelperFilesParameters;
	imgArr = window.showModalDialog(galleryscript,window,'dialogWidth:560px; dialogHeight:500px;help:0;status:0;resizeable:1;');

	if (imgArr != null) {
		imagestring = imgArr['filename'];
		//sel = editor.document.selection.createRange();
		//sel.pasteHTML(imagestring);
		document.forms[0].elements[idname].value = imagestring;
	} else {
		//alert("You did not select an image");
	}
}

function InsertImage2(idname, folder) {
	var galleryscript = '../../PCIControls/SelectImage.aspx?rif='+folder+'&cif='+folder;
	imgArr = window.showModalDialog(galleryscript,window,'dialogWidth:560px; dialogHeight:500px;help:0;status:0;resizeable:1;');
	if (imgArr != null) {
		imagestring = imgArr['filename'];
		imagestring = imagestring.substr(imagestring.lastIndexOf("/")+1)
		
		document.forms[0].elements[idname].value = imagestring;
	} else {
		//alert("You did not select an image");
	}
}
/*
function __doPostBack(eventTarget, eventArgument) {
var theform = document.Form1;
theform.submit();
}

var upLevel = false;
var ns4 = false;
var ie4 = false;
 
if(document.getElementById) { // IE 5 and up, NS 6 and up
upLevel = true;
}
else if(document.layers) { // Netscape 4
ns4 = true;
}
else if(document.all) { // IE 4
ie4 = true;
}

function showObject(obj) 
{
if (ns4) {
obj.visibility = "show";
}
else if (ie4 || upLevel) {
obj.style.visibility = "visible";
}
}

function hideObject(obj) {
if (ns4) {
obj.visibility = "hide";
}
if (ie4 || upLevel) {
obj.style.visibility = "hidden";
}
}
*/

function clickButton(e, buttonid)
{ 
  var bt = document.getElementById(buttonid); 
  if (typeof bt == 'object')
  { 
     var key = e? e.keyCode : event.keyCode;
     if (key == 13)
     {
        bt.click(); 
        return false;
     }
  } 
} 

function clickHiddenButton(buttonid)
{
     var bt = document.getElementById(buttonid); 
  if (typeof bt == 'object')
  {      
     bt.click(); 
     return false;   
  } 
   return false;
}

function checkAll(chkall) 
{
    
  var checks = document.body.getElementsByTagName("INPUT");
  for ( i=0; i < checks.length; i++ ) 
  {
        if (checks[i].type.toLowerCase() == "checkbox" && chkall != checks[i])
            checks[i].checked = chkall.checked;
  }
}

function include(filename)
{
	var body = document.getElementsByTagName('body').item(0);
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';
	body.appendChild(script);
}



