	//Main JavaScript functions
	//Retrieving screen resolution for centering window
	var mainwin= null;
	var  mainwinl = (screen.width-640)/2;
	var  mainwint = (screen.height-400)/2;

	function ShowHideLayer(layerName)
	{
		var layer = getLayer(layerName);
		var Action
		if (document.layers) 
		{
			if (layer.visibility == "hide")
				Action='Show';
			else
				Action='Hide';
		}		
		else if (document.getElementById)
		{
			if (layer.style.display == 'none')
				Action='Show';
			else
				Action='Hide';
		}
		if(Action=="Hide")
		{
			if (document.layers) 
				layer.visibility = "hide" ;
			else if (document.getElementById)
				layer.style.display = 'none';
		}
		else
		{
			if (document.layers) 
				layer.visibility = "show" ;
			else if (document.getElementById) 
				layer.style.display = '';
		}
	}
	
	function getLayer(layerName)
	{
		if (document.layers) 
	        return document.layers[layerName];
		else if (document.getElementById)
			return document.getElementById(layerName);
	}

	function EscapeKeyPress() 
	{
		if (window.event.keyCode == 27)
		window.close();
	}

	function Navigate(Direction)
	{	
		if(Direction=="Back")
		{
			history.go(-1);
		}

		if(Direction=="Forward")
		{
			history.go(+1);
		}
	}

	function UploadFile(FileType,ToLocation,PreviousFileLocation,DeleteFilename,RefreshParentWindow)
	{    
		var option = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=640,height=300,maximize=0,"
      		option +='top='+mainwint+',';
      		option +='left='+mainwinl;
		
		var uploadwin = window.open(rootPath+"/include/upload/upload.asp?filetype="+FileType+"&tolocation="+ToLocation+"&previousfilelocation="+PreviousFileLocation+"&deletefilename="+DeleteFilename+"&refreshparentwindow="+RefreshParentWindow,"UploadFileWindow", option);
		uploadwin.focus();
	 }

	function ShowImagePreview(File)
	{    
		var option = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=300,maximize=0,"
      		option +='top='+mainwint+',';
      		option +='left='+mainwinl;
		
		var imagewin = window.open(File,"ImagePreviewWindow", option);
		imagewin.focus();
	 }

	function ColorTextBox(FormName,ObjectName)
	{	
		//More Colors: Lightred (#FFD9D9), Lightblue(#EFF7FA), Lightgray(#F0F0F0), LightOrange(#FFDBA6)
		var ActiveColor = '#FFDBA6';
		var PassiveColor = '#EFF7FA';
		if(eval("document."+FormName+"."+ObjectName+".value")=="")
		{
			eval("document."+FormName+"."+ObjectName+".style.background='"+ActiveColor+"'")
		}
		else
		{
			eval("document."+FormName+"."+ObjectName+".style.background='"+PassiveColor+"'")
		}
	}

	function isWhiteSpaces(S)
	{
		var isNull
		if (S.length == 0 ) 
			isNull = true;
		else
		{
			for (I=0;I < S.length; I++ )
			{
				isNull = S.substring(I,I+1)==" "?true:false
				if (!isNull) break;
			}
		}
		return isNull;
	}
	
	function isAlpha(S)
	{
		for (var i=0; i<S.length; i++) 
		{
			var ch = S.charAt(i);
			if ((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' ') && (ch <'0') && (ch >'9')) 
				return false;
		}
		return true;
	}
	
	function isNumeric(S)
	{
		if (!isNaN(S))	
		{
		return true;	
		}
		return false;
	}

	function isEmail(email)
	{
		var isNullEmail = isWhiteSpaces(email)
		var emailLength = email.length
		var isSPACEexists = email.indexOf(" ") + 1
		var isATexistsFirst = email.indexOf("@")
		var isATexistsLast = email.lastIndexOf("@")
		var isDOTexistsFirst = email.indexOf(".",isATexistsFirst+1)
		var isDOTexistsNext1 = email.indexOf(".",isATexistsFirst+1)
		var isDOTexistsNext2 
		var isDOTexistsLast = email.lastIndexOf(".")
	
		if ((emailLength < 8 ) || (isDOTexistsFirst < isATexistsFirst+3) || (isATexistsFirst < 2) ||
	   	 	(isDOTexistsLast == emailLength-1) || (isATexistsLast == emailLength-1) ||
	    	(isDOTexistsFirst == 0) || (isATexistsFirst == 0) || (isATexistsFirst == isDOTexistsFirst) ||
	    	(isATexistsFirst != isATexistsLast) || isSPACEexists || isNullEmail)
		{
			return false;
		}
	
		while (isDOTexistsNext1 < isDOTexistsLast)
		{
			isDOTexistsNext2 = email.indexOf(".",isDOTexistsNext1+1)
			if (isDOTexistsNext1+1 == isDOTexistsNext2)
			{
				return false;
			}
			isDOTexistsNext1 = isDOTexistsNext2
		}
		return true;
	}

	// function for checking spaces
	function check(S)
	{
		var flag;
	   	var Str=S.length
	  	for(I=0;I<Str;I++)
	  	{
	    	var space=S.charAt(I)
	    	if (space==" ") 
	    	{
	    		flag=true;
    			break;
	    	} 
	  	}
	   	if(flag==true)
	    	return true;
	   	else
	      	return  false;
	}

	function exec (command) 
	{
		if (document.layers && navigator.javaEnabled()) 
		{
			window._command = command;
			window.oldOnError = window.onerror;
			window.onerror = function (err) 
			{
				if (err.indexOf ("User didn't grant") != -1) {
				        alert('command execution of ' + window._command + 
				              ' disallowed by user.'); 
				        return true;
			}
		else return false;
		}
		    netscape.security.PrivilegeManager.enablePrivilege
		('UniversalExecAccess');
		    java.lang.Runtime.getRuntime().exec(command);
		    window.onerror = window.oldOnError;
		  }
		  else if (document.all) {
		    window.oldOnError = window.onerror;
		    window._command = command;
		    window.onerror = function (err) {
		      if (err.indexOf('utomation') != -1) {
		        alert('command execution of ' + window._command + 
		              ' disallowed by user.'); 
		        return true;
		      }
		      else return false;
		    };
		    var wsh = new ActiveXObject('WScript.Shell');
		    if (wsh)
		      wsh.Run(command);
		    window.onerror = window.oldOnError;
		  }
	}