var flag=0;

function openWinPrint(link)
{     
	window.open(link,"printable","toolbar=1,menubar=1,scrollbars=1,resizable=1,width=700,height=550,marginwidth=0,marginheight=0");
}

//FUNCTION TO TOGGLE QUICKLINKS AND FORMS BOXES - CAN BE USED WITH ANY TOGGLING BOXES
function blocking(nr,or)
{
	if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
		old = (document.layers[or].display == 'block') ?  'none' :'block';
		document.layers[or].display = old;
	}
	else if (document.all)
	{
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
		old = (document.all[or].style.display == 'block') ? 'none' : 'block';
		document.all[or].style.display = old;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
		oldvista = (document.getElementById(or).style.display == 'block') ? 'none' : 'block';
		document.getElementById(or).style.display = oldvista;
	}
}


function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function printit(){  
	if (window.print) {
    	window.print() ;  
	} else {
    	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">	</OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    	WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}

// Close header
function showclose(a) {
	obj = document.getElementById('bannerClose');
	if(a==0) {
		obj.style.display = 'block';
	}
	if(a==1) {
		obj.style.display = 'none';
	}
}

function closeBanner() {
	obj = document.getElementById('banner');
	obj.style.display = 'none';
}

// Simple Ajax
function simpleAjax(page,params) {
	var ajaxRequest; // The variable that makes Ajax possible!
	
	try { 
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	}
	catch(e) {
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
			
		}
	}


// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function() {
	// We still need to write some code here
	if(ajaxRequest.readyState == 4) {
		// Get the data from the server's response
		//var ajaxDisplay = document.getElementById('ajaxDiv');
		//ajaxDisplay.innerHTML = ajaxRequest.responseText;		
		//close banner
		closeBanner();
	}
}

var queryString = params;

ajaxRequest.open("GET",page + queryString,true);
ajaxRequest.send(null);

}



function checkCouncil() {

  var obj = document.council;
  var myOption = document.council.title;
  
   if (isBlank(myOption.value)){
   		alert('Please select a Council.');
        myOption.focus();
        myOption.selected();
        return false;
   }
   if (isBlank(obj.email.value)){
   		alert('Please enter your John Jay Email Address.');
        obj.email.focus();
        obj.email.selected();
        return false;
   }
   if (!isBlank(obj.email.value)){
   	 if (!IsValidEmail(obj.email.value)){
   		alert('Please enter a valid John Jay Email Address. Example: john.doe@jjay.cuny.edu.');
        obj.email.focus();
        obj.email.selected();
        return false;
   	 }   
   }
   if (isBlank(obj.subject.value)){
   		alert('Please enter a Subject.');
        obj.subject.focus();
        return false;
   }
   if (isBlank(obj.question.value)){
   		alert('Please enter your Question.');
        obj.question.focus();
        return false;
   }
   
	obj.submit();
	return true;    
}


function isBlank(data){
	var datalen = data.length;
	var datavalue = data;

	for (i=0; i <= datalen; i++)	{
      aChar = datavalue.substring(i,i+1);
      if(aChar =="" || aChar==" ") {
      	blank = 'y';
      }
      else {
      	blank = 'n';
      	break;
      }
  	}
   if (blank=='y')
      return true;
   else 
	  return false;	
} 


function IsValidEmail(sText)
{
   var ss = sText;
   var result = ss.indexOf("@jjay.cuny.edu");
   var IsValid=true;

   if (result == -1)
   		IsValid = false;

   return IsValid;
   
}
