// stealthFire: Shows/hides items. Takes idName (id of item to show/hide).

function stealthFire(idName) 
{
	element = document.getElementById(idName);
	if(element.style.display != "none") 
	{
		element.style.display = "none";
	} else 
	{
		element.style.display = "block";
	}
}

// ajaxConnect: AJAX function. Takes reqType (either "POST" or "GET"), theURL (the URL to fetch),
// 						asynch (boolean - asynchronous or not?), and respHandle (the
//						function to call when the HTTP readyState changes). respHandle
//						should read the AJAX data from request.responseText.

function ajaxRequest() 
{
	
	var theRequest;
	
	if(window.XMLHttpRequest) 
	{
		theRequest = new XMLHttpRequest();
	}
	
	else if(window.ActiveXObject) 
	{
		theRequest = new ActiveXObject("Microsoft.XMLHTTP");
		if(!theRequest) 
		{ 
			theRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
		}
	}

	if(theRequest) 
	{
		return theRequest;
	} 
	else 
	{
		alert("AJAX not supported.");
	}
}

function ajaxConnect(theRequest,reqType,theURL,asynch,respHandle) 
{
	if(theRequest) 
	{
		if(reqType.toUpperCase() != "POST") 
		{
			theRequest.onreadystatechange = respHandle;
			theRequest.open(reqType,theURL,asynch);
			theRequest.send(null);
			//initRequest(reqType,theURL,asynch,respHandle);
		} 
		else 
		{
			var post_data = arguments[4];
			theRequest.onreadystatechange = respHandle;
			theRequest.open(reqType,theURL,asynch);
			if(post_data != null && post_data.length > 0) 
			{
				theRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
				theRequest.send(post_data);
			}
		}
	}
}

//Added by Sudhakar//
function OnlySpaces(str)
{
	var i;
	for(i=0;i<str.length;++i)
	{
		if(str.charAt(i)!= ' ')
		{
			return false;
		} 
	}
	return true;	
}

function validateSpecialChars(vInputField)
{   

	var vFormField = eval(vInputField);

	reSpChar = new RegExp(/[\n\*\+\/\\\~\%\!\&\#\$\^\'\(\)\{\}\|\;\:\<\>\,\[\]\"\)]/);
	
	if (reSpChar.test(vFormField.value))
	{
		 alert("Please do not use the following special characters: \n* + / \\ ~ % ! & # $ ^ ' ( ) { } | ; : < > . , [ ] \" ");  
		 vFormField.focus();
		 vFormField.select();
		 return false;
	}
	else
	{
		return true;
	}
}

function hasWhiteSpace(s) 
{
     reWhiteSpace = new RegExp(/^\s+$/);
     // Check for white space
     if (reWhiteSpace.test(s)) 
	 {
          alert("Entry cannot be blank");
          return false;
     }
}

function CheckTime_24hrFormat(sInputString)
{
	var sText = sInputString;
	if ((sText.length<=0)||(sText.length>5))
	{
		alert ('Not a valid time / Time not in 24 hr format');
		return false;
	}
	else
	{
		if (sText.indexOf(":")==-1)
		{
			alert ('Not a valid time / Time not in 24 hr format');
			return false;
		}
		else
		{
			var sResult = sText.split(":")
			var hr = sResult[0];
			if ((parseInt(hr)>23) || (parseInt(hr)<0) || (isNaN(parseInt(hr))))
			{
				alert ('Not a valid time / Time not in 24 hr format');
				return false;
			}
			var mn = sResult[1];
			if ((parseInt(mn)>59) || (parseInt(mn)<0) || (isNaN(parseInt(mn))) )
			{
				alert ('Not a valid time / Time not in 24 hr format');
				return false;
			}
			if ((parseInt(hr)==0) && (parseInt(mn)==0))
			{
				alert ('Not a valid time / Time not in 24 hr format');
				return false;			
			}
		}
	}
}

function IsDate(dateStr)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	var datestatus=true;
	datemsg="";
	if (matchArray == null)
	return false;
   
	day = matchArray[3];
	month = matchArray[1]; // p@rse date into variables
	year = matchArray[5];

	if (month < 1 || month > 12)
	{ // check month range
		datemsg=datemsg + "Month must be between 1 and 12." + "\n";
		datestatus=false;
	}

	if (day < 1 || day > 31)
	{
		datemsg=datemsg + "Day must be between 1 and 31." + "\n";
		datestatus=false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31)
	{
		datemsg=datemsg + "Month " + month + " doesn`t have 31 days!" + "\n";
		datestatus=false;
	}

	if (month == 2)
	{ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap))
		{
			datemsg=datemsg + "February " + year + " doesn`t have " + day + " days!" + "\n";
			datestatus=false;
		}
	}
	return datestatus;
}
function Mask(e, m)
{
	if (event.keyCode>=47 && event.keyCode<=57)
	{
	}
	else
	{ 
		return false;
	}
}
function Validatedates(dtFrDate, dtToDate){
	var datemsg="";
	var status=IsDate(dtFrDate.value);
	if(!status)
	{
		alert("Invalid Date");
		dtFrDate.focus();
		dtFrDate.select();
		return false;
	}else{
		status=IsDate(dtToDate.value);
		if(!status)
		{
			alert("Invalid Date");
			dtToDate.focus();
			dtToDate.select();
			return false;		
		}
	}
}

function ValidateURL(objField) 
{ 
	//Evaluate the object and assign it to an variable
	var obj = eval(objField);
	
	//Create Regular Expression Object
    var v = new RegExp(); 
	
	//Create Regular Expression and compile it
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
	
    if (v.test(obj.value)) 
	{ 
		return true;
    } 
	else
	{
        alert("Give a valid URL."+"like http://www.yahoo.com"); 
        return false; 
	}
} 
function ValidateURL1(objField) 
{ 
	//Evaluate the object and assign it to an variable
	var obj = eval(objField);
	
	//Create Regular Expression Object
    var v = new RegExp(); 
	
	//Create Regular Expression and compile it
   v.compile("^([A-Za-z]+://)?[A-Za-z0-9-_]+\\.[A-Za-z0-9\-_%\~&\?\/\.,\+=:#]+$"); 
	
    if (v.test(obj.value)) 
	{ 
		return true;
    } 
	else
	{
        //alert("Give a valid URL."+"like http://www.yahoo.com"); 
        return false; 
	}
} 

function checkemail(objField)
{
	if (eval(objField))
	{
		var str=objField.value;
		//var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
		//var filter=/^.+@.+\..{2,3}$/;
		var filter=/^[a-zA-Z0-9._\-\~\&`\$!\^%#\?\*\{\}\/\+\|=&]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		if (filter.test(str))
		{
			return true;
		}
		else
		{
			alert("Please input a valid email address!");
			objField.focus();
			return false;
		}
	}
	//Added By Venkat for valid Email Checking
  /* function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	} */
// End By Venkat 
}
