/**
* NOTE: change fileloaderPath variable to fileloader.php path
* Lets say from browse you can access it by: http://www.example.com/xyz/abc/fileloader.php
* then
* var fileloaderPath = "/xyz/abc/";
* 
*/ 
var fileloaderPath = "/";
/**
*
*
* if in browse website is accessed with https://example.com then
* AJAX requests must be on https://example.com domain
* Actually for security purpose cross domain requests are not allowed.
* AJAX requests should have same protocol (http or https)
* and domain name by which user has accessed the page. Else it will not work
* 
*/
var currentHostname = location.hostname;
var currentProtocol = location.protocol;
function loadingImage(filename) {
	findObj("loadingHere").style.display = "block";
	findObj("loadingHere").innerHTML = "<img src='./images/Loading_ani.gif' border='0' alt='Loading ...' width='51' height='9'>";	
}
/**
* load the files dinamically when user clicks on the links
* 
*/
function loadFile(filename) {
	/**
	* for showing rounded corners
	*/
	var brokenfilename=filename.split("?");
	var filenameForRoundedCorner=brokenfilename[0];
	if(filenameForRoundedCorner=='contact_form.php' || filenameForRoundedCorner=='pass_form.php' || filenameForRoundedCorner=='register_form.php') {
		Rounded("div#scheduler","#fff","#CCCCCC");
	}
		
	/**
	* show that something is going on
	*/	
	loadingImage(filenameForRoundedCorner);			
	/**
	* if browser is Firefox or similar then request is sent by these functions
	*/
	if (window.XMLHttpRequest) {		
		/**
		* create an instance of XMLHttpRequest
		*/
		loader = new XMLHttpRequest();
		/**
		* 
		* Some versions of some Mozilla browsers won't work properly if the response 
		* from the server doesn't have an XML mime-type header. To satisfy this, you 
		* can use an extra method call to override the header sent by the server, just 
		* in case it's not text/xml.
		*
		*/
		if(loader.overrideMimeType) {
			loader.overrideMimeType('text/xml');
		}
		/**
		* tell the callback function name
		*/
		loader.onreadystatechange = loadFileCB;
		/**
		* send a request
		*/		
		loader.open("GET", location.protocol+"//"+location.hostname+""+fileloaderPath+"fileloader.php?fn="+filename, true);
		loader.send(null);
	} else if (window.ActiveXObject) { 
		/*
		 * if browser is IE then request is sent by these functions
		*/
		loader = new ActiveXObject("Microsoft.XMLHTTP");
		if (loader) {
			loader.onreadystatechange = loadFileCB;
			loader.open("GET", location.protocol+"//"+location.hostname+""+fileloaderPath+"fileloader.php?fn="+filename, true);
           	loader.send();
     	}
	}
}
/**
* this function includes a call for rounded corner function
* otherwise it is same as loadfile
* loads the files dinamically with windows 'onload' property
* so the Rounded() function which is otherwise called by 
* windows onload property is by-passed, hence, included here
*/
function loadFileWithNifty(filename) {
	/**
	* for showing rounded corners
	*/	
	var brokenfilename=filename.split("?");
	var filenameForRoundedCorner=brokenfilename[0];	
	Rounded("div#nifty","#DCDCDC","#F2F2F2");
	if(filenameForRoundedCorner=='contact_form.php' || filenameForRoundedCorner=='user_pass.php' || filenameForRoundedCorner=='user_phone.php') {
		Rounded("div#scheduler","#fff","#CCCCCC");
	}	
	/**
	* show that something is going on
	*/	
	loadingImage(filenameForRoundedCorner);				
	/**
	* if browser is Firefox or similar then request is sent by these functions
	*/
	if (window.XMLHttpRequest) {		
		/**
		* create an instance of XMLHttpRequest
		*/
		loader = new XMLHttpRequest();
		/**
		* 
		* Some versions of some Mozilla browsers won't work properly if the response 
		* from the server doesn't have an XML mime-type header. To satisfy this, you 
		* can use an extra method call to override the header sent by the server, just 
		* in case it's not text/xml.
		*
		*/
		if(loader.overrideMimeType) {
			loader.overrideMimeType('text/xml');
		}
		/**
		* tell the callback function name
		*/
		loader.onreadystatechange = loadFileCB;
		/**
		* send a request
		*/		
		loader.open("GET", location.protocol+"//"+location.hostname+""+fileloaderPath+"fileloader.php?fn="+filename, true);
		loader.send(null);
	} else if (window.ActiveXObject) { 
		/*
		 * if browser is IE then request is sent by these functions
		*/
		loader = new ActiveXObject("Microsoft.XMLHTTP");
		if (loader) {
			loader.onreadystatechange = loadFileCB;
			loader.open("GET", location.protocol+"//"+location.hostname+""+fileloaderPath+"fileloader.php?fn="+filename, true);
           	loader.send();
     	}
	}
}
/**
*
*
* loadFile callback function
*
*/
function loadFileCB()  {
	/**
	*
	* when readyState is 4 - we are supposed to get some data
	* here "loader" is the same variable in above function
	* alert(loader.readyState);
	*
	*/
    if (loader.readyState == 4) {
	   	/**
		* when status is 200 - means requested page (i.e. fileloader.php) found
		*/		
	   	if (loader.status == 200) {	    	
    		if (loader.responseText=="404") {
				findObj("loadingHere").style.display = "block";
    			findObj("loadingHere").innerHTML = " File Not Found";
	   		} else if (loader.responseText=="500") {
				findObj("loadingHere").style.display = "block";
    			findObj("loadingHere").innerHTML = "Request not supported";
	   		} else {
				findObj("loadingHere").style.display = "none";
				findObj("loadFilesHere").innerHTML = loader.responseText;
    		}
	    } else {
    		alert("Server Internal Error. Please contact Awards Administrator");
	    }    
	}
}
//
//
function formHanding() {
	var argv = formHanding.arguments;
	var argc = argv.length;
	var request = "?";
	for (var i = 0; i < argc; i=i+4) {
		if (argv[i+2]=="notnull" && argv[i+1]=="") {
			if(argv[i]=="tit" || argv[i]=="tit_1" || argv[i]=="tit_2" || argv[i]=="tit_3" || argv[i]=="tit_4" || argv[i]=="tit_5" || argv[i]=="tit_6" || argv[i]=="tit_7" || argv[i]=="tit_8" || argv[i]=="tit_9" || argv[i]=="tit_10") {
				alert("Title: is madatory ");
			} else {				
				alert(argv[i+3]+": is madatory ");				
			}
			return false;
		} else {			
			if (i==0) {
				/**
				* handle checkbox of award entry file 
				*/
				if (argv[i] == "autologin") {
					if (findObj(argv[i]).checked) {
						 request = request+""+argv[i]+"="+argv[i+1];
					} else {
						argv[i+1]="N";
						request = request+""+argv[i]+"="+argv[i+1];
					}
				} else {
					request = request+""+argv[i]+"="+argv[i+1];
				}		
			} else {							
				if (argv[i] == "autologin") {					
					if (findObj(argv[i]).checked) {	
						 request = request+"&"+argv[i]+"="+argv[i+1];
					} else {						
						argv[i+1]="N";
						request = request+"&"+argv[i]+"="+argv[i+1];
					}					
				} else {							
					request = request+"&"+argv[i]+"="+argv[i+1];
				}
			}
		}		
	}
	findObj("loadingHere").style.display = "block";
	findObj("loadingHere").innerHTML = "<img src='./images/Loading_ani.gif' border='0' alt='Loading ...' width='51' height='9'>";
	if (window.XMLHttpRequest) {
		/**
		* create an instance of XMLHttpRequest
		* 
		*/		
		formHandler = new XMLHttpRequest();
		/**
		* tell the callback function name
		*/
		formHandler.onreadystatechange = formHandingCB;
		/**
		* send a request	
		*/	
		formHandler.open("GET", location.protocol+"//"+location.hostname+""+fileloaderPath+"formHandling.php"+request, true);
		formHandler.send(null);
	} else if (window.ActiveXObject) { 
		/**
		* if browser is IE then request us sent by these functions
		*/
		formHandler = new ActiveXObject("Microsoft.XMLHTTP");
		if (formHandler) {
			formHandler.onreadystatechange = formHandingCB;
			formHandler.open("GET", location.protocol+"//"+location.hostname+""+fileloaderPath+"formHandling.php"+request, true);
           	formHandler.send();
     	}
	}
}
//
//
function formHandingCB() {		
    	if (formHandler.readyState == 4) {
	    	if (formHandler.status == 200) {
    			if (formHandler.responseText=="0") {
	    			//display changed to none by op
					findObj("loadingHere").style.display = "none";
    				findObj("loadingHere").innerHTML = " Data Incorrect";
	    		} else if (formHandler.responseText=="404") {
					findObj("loadingHere").style.display = "block";
    				findObj("loadingHere").innerHTML = " File Not Found";
	    		} else if (formHandler.responseText=="500") {
					findObj("loadingHere").style.display = "block";
    				findObj("loadingHere").innerHTML = " Request Not Supported";
	    		} else {
		    		var stringReturned = formHandler.responseText;
		    		if (stringReturned.indexOf('~redirect~') != -1) {
						redirectVariables = stringReturned.split('~');
						findObj("loadingHere").style.display = "block";
						findObj("loadingHere").innerHTML = redirectVariables[4];
						setTimeout('redirectPage(redirectVariables[2])', redirectVariables[3]);
			   		} else {
						findObj("loadingHere").style.display = "none";
						findObj("loadFilesHere").innerHTML = formHandler.responseText;						
					}					
    			}
	    	} else {
      		alert("Server Internal Error. Please contact Awards Administrator");
	      }    
	}
}
/**
*
*****************************************
** BELOW WE HAVE SOME HANDY FUNCTIONS
*****************************************
*
*/
function redirectPage (page) {
	window.location = page;
}
//
function newWindow(url, height, width) {
	nameW='feature'
	if (navigator.appVersion.indexOf('4') != -1) {
		// Vars for centering the new window on Version 4 Browsers
		xTop = screen.width/2 - (width/2);
		yTop = screen.height/2 - (height/2);
		window.open(url, nameW, 'height='+height+',width='+width+',scrollbars,resizable,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + xTop + ',top=' + yTop + '');
	} else {
		window.open(url, nameW, 'height='+height+',width='+width+',scrollbars,resizable,menubar=0,toolbar=0,status=0,location=0,directories=0,left=150,top=200');
	}
}
/**
* show security risks if user selects auto login
*/
var checkobj;
function show_message(el){
	autologin=el;
	if (window.autologin&&autologin.checked) {
	 	window.open("alert_user.php", "AlertWindow", "height=250, width=500, scrollbar=no, toolbar=no resizable");
		return true;
	}
}
function findpos(obj){
	return {x:findPosX(obj), y:findPosY(obj)};
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
//
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
//
function 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;
}