/* Somewhat useful functions by Azad Ratzki */

/* String Cleanser 
	-Cleans strings before submission to prevent database errors.
		2 Arguments:
			frmId: Id of <FORM> tag that contains the form elements you wish to replace.
			forcesubmit(Optional): If = true, will submit form after replacing strings.
*/
//<-----
function StringClean(frmId, forceSubmit)
	{
		var x=document.getElementById(frmId)
		for (var i=0;i<x.length;i++)
		  {
		   x[i].value = x[i].value.replace(/'/g,"''")
  		}
	if(forceSubmit==true)
		{
		x.submit()
		}
	}
//----->


/* String Enter 
	-Enters default value in form if nothing entered
*/
//<-----
function StringEnter(elementId, varString)
	{
		var x = document.getElementById(elementId)
		
		if(x.value==varString)
			{
				x.value=""
			}
		else if(x.value.length<1)
			{
				x.value=varString
			}	
	}
//----->
/* Save Screen, for looks and to prevent double submission.
	ScreenSave:
	-varSaveMessage(string:Message you want), varBGBackgroundColor(string:Background color of screen)
	-varFGBackgroundColor(string:Background color of foreground window containing message)
	-varBorderColor(string:Border color of foreground window)
	-varTextColor(string:Isn't it obvious?)
	-varFrmId_SS(string:ID of Form that will be submitted after 'saving')
	TimeKeeper: used for ScreenSave()
*/
//<-----
var tix = 0
var timer
var tstring
function ScreenSave(varSaveMessage, varBGBackgroundColor, varFGBackgroundColor, varBorderColor,  varTextColor, varFrmId_SS)
	{
		var sElementBG = document.createElement("div");
		sElementBG.id = "saveScreenBG";
		sElementBG.style.cssText = "filter: Alpha(Opacity=1, FinishOpacity=80, Style=2, StartX=20, StartY=20)";
		sElementBG.style.cssText = sElementBG.style.cssText + ";position:fixed;z-index:199;display:inline;top:0px;left:0px";
		sElementBG.style.cssText = sElementBG.style.cssText + ";background-color:" + varBGBackgroundColor;
		var sElementFG = document.createElement("div");
		var sElementText = document.createTextNode(varSaveMessage);
		sElementFG.id = "saveScreenFG";
		sElementFG.align = "center";
		sElementFG.style.cssText = "font-family:Verdana;font-weight:bold;font-size:2em;vertical-align:middle;padding-top:20px";
		sElementFG.style.cssText = sElementFG.style.cssText + ";height:65px;width:250px;text-align:center";
		sElementFG.style.cssText = sElementFG.style.cssText + ";border:thick inset " + varBorderColor + ";z-index:200";
		sElementFG.style.cssText = sElementFG.style.cssText + ";display:inline;top:40%;left:35%;position:fixed";
		sElementFG.style.cssText = sElementFG.style.cssText + ";background-color:" + varFGBackgroundColor;
		sElementFG.style.cssText = sElementFG.style.cssText + ";color:" + varTextColor;
		document.body.appendChild(sElementBG);
		document.getElementById("saveScreenBG").style.width = screen.availWidth;
		document.getElementById("saveScreenBG").style.height = screen.availHeight;
		document.body.appendChild(sElementFG);
		document.getElementById("saveScreenFG").appendChild(sElementText);
		TimeKeeper(varFrmId_SS);
	}

function TimeKeeper(varFrmId_TK)
			{
				if(tix<=100)
					{
						document.getElementById('saveScreenBG').style.filter = "Alpha(Opacity=" + tix + ", FinishOpacity=80, Style=2, StartX=20, StartY=20)";
						tix = tix + 1;
						tstring = "TimeKeeper('"+varFrmId_TK+"')";
      					timer = setTimeout(tstring, 10);
					}
				else
					{
						StringClean(varFrmId_TK, true)
					}
			};	
//----->

//Obsolete dyamic menu.
function ShowMenu(ulID, aID) 
	{
		var ulDisplay = document.getElementById(ulID);
		var aDisplay = document.getElementById(aID);
		if(ulDisplay.style.display=="none")
			{
				ulDisplay.style.display="inline";
				var newHTML = aDisplay.innerHTML.replace("+","-");
				aDisplay.innerHTML = newHTML ;
			}
		else
			{
				ulDisplay.style.display="none";
				var newHTML = aDisplay.innerHTML.replace("-","+");
				aDisplay.innerHTML = newHTML ;
			};
	}
	
//Basic resolution checking.
//<-----
function CheckRes()
	{

		var mDiv = document.getElementById("MainDiv");
		var resCombined = screen.width + "x" + screen.height ;
		alert(resCombined);
		/*
		if(resCombined=="800x600")
			{
				mDiv.style.marginTop="0%";
			}
		else if(resCombined=="1024x768")
			{
				mDiv.style.marginTop="8%";
			}
		else if(resCombined=="1280x1024")		
			{
				mDiv.style.marginTop="12%";
			};
		*/
	}
function SiteRes()
	{
		if((screen.width<1024) & (screen.height<768))
			{
				return false;
			}
		else
			{
				return true;
			}
	}
	
function SiteRes2()
{
	if((document.body.clientWidth<885) || (document.body.clientHeight<540))
		{
			return false;
		}
	else
		{
			return true;
		}
}
		
		
		
function TestRes()
	{
		var mDiv = document.getElementById("MainDiv");
		var varWidth = screen.availWidth + "px";
		var varHeight = screen.availHeight + "px";
		{
				mDiv.style.width = varWidth
     			mDiv.style.height = varHeight
				mDiv.style.left = screen.availWidth * 0.15 + "px"
		};
	}
//----->
//Detect the user's browser.
function IsIE()
	{
		if(window.navigator.appName=="Microsoft Internet Explorer")
			{
				return true;
			}
		else
			{
				return false;
			}		
	}

//Make sure if is IE7.
function IsIE7()
	{
				var x = new Array();
				x = window.navigator.appVersion.split(";");
				x[1] = x[1].replace(" ","");				
				if(x[1]=="MSIE 7.0" || x[1]=="MSIE 8.0" )
					{
						return true;
					}
				else
					{
						return false;
					}
	}
//Make sure is IE first then if is IE7.
function IsOldIE()
	{
		
		if(IsIE() & !IsIE7())
			{
				return true;
			}
		else
			{
				return false;
			}
		
		/*
		if(IsIE())
			{
				if(IsIE7())
					{
						return false;
					}
				else
					{
						return true;
					}
			}
		else
			{
				return false;
			}
		*/
		
	}