function ValidateIP(fld)
{
		var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
		var ipArray = trim(fld.value).match(ipPattern); 
		
		if (trim(fld.value) == "0.0.0.0")
		{
			alert("" +(fld.value)+ " is a special IP address and cannot be used here");
			fld.focus();
			return false;
		}
		if (trim(fld.value) == "255.255.255.255")
		{
			alert("" +(fld.value)+ " is a special IP address and cannot be used here");
			fld.focus();
			return false;
		}
		if(ipArray == null)
		{
			alert("" +(fld.value)+ " is not a valid IP address.");
			fld.focus();
			return false;
		}
		else
		{
			for (i = 0; i < 4; i++) 
			{
				thisSegment = ipArray[i];
				if (thisSegment > 255) 
				{
					alert("" +(fld.value)+ " is not a valid IP address.");
					fld.focus();
					return false;
					i = 4;
				}
				if ((i == 0) && (thisSegment > 255)) 
				{
					alert("" +(fld.value)+ " is a special IP address and cannot be used here");
					fld.focus();
					return false;
					i = 4;
				}
			}
		}

}


function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths Email Id contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The Email Id doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}



function ValidateDate(dt,msg)
{
	if(isValidDate(dt)==false)
	{
		return false
	}
}

function Required(ctrl, msg)
{
	if(trim(ctrl.value)="")
	{
		alert(msg);
		ctrl.focus();
		return false
	}
}

function ValidateAlphaSpaceOnly(ctrl,msg)
{
			for(x=0;x<ctrl.value.length;x++)
		{
			i=(ctrl.value.charCodeAt(x));
			if((i<65 || i >122 || i==94 || i==95) &&  i !=13  && i !=32)
			{
				alert("Please Enter Alphabets Only (A-Z )  "+ msg);
				ctrl.focus();
				return false
			}
		}
}

function ValidateAlphaSpace(ctrl,msg)
{
		for(x=0;x<ctrl.value.length;x++)
		{
			i=(ctrl.value.charCodeAt(x));
			if((i<65 || i >122 || i==94 || i==95) &&  i !=13  && i !=32 )
			{
				alert("Please Enter Alphabets Only (A-Z )  "+ msg);
				ctrl.focus();
				return false
			}
		}

}
function AlphaSpaceOnly(ctrl, e)
{
		if((e.keyCode<65 || e.keyCode >122 || e.keyCode==94 || e.keyCode==95) &&  e.keyCode !=13  && e.keyCode !=32)
		{
			alert("Please Enter Alphabets Only (A-Z )");
			return false
		}
}

function ValidateAlpha(ctrl,msg)
{
		for(x=0;x<ctrl.value.length;x++)
		{
			i=(ctrl.value.charCodeAt(x));
			if((i<65 || i >122 || i==94 || i==95) &&  i !=13 )
			{
				alert("Please Enter Alphabets Only (A-Z )  "+ msg);
				ctrl.focus();
				return false
			}
		}

}

function AlphaOnly(ctrl, e)
{
		if((e.keyCode<65 || e.keyCode >122 || e.keyCode==94 || e.keyCode==95) &&  e.keyCode !=13 )
		{
			alert("Please Enter Alphabets Only (A-Z )");
			ctrl.focus();
			return false
		}

}

function AlphaNumSpaceOnly(ctrl,e)
{
	if((e.keyCode<48 || e.keyCode >57) && (e.keyCode < 65 || e.keyCode >122 || e.keyCode == 94 || e.keyCode==95 ) && (e.keyCode !=13) && (e.keyCode!=32))
	{
		alert("This Field Accepts  Only Alpha Numeric and Space Characters");
		return false
	}
}

function ValidateAlphaNum(ctrl,msg)
{
		for(x=0;x<ctrl.value.length;x++)
		{
			i=(ctrl.value.charCodeAt(x));
			if((i<48 || i >57) && (i < 65 || i >122 || i == 94 || i==95 ) && (i !=13))
			{
				alert("Please Enter Alphabets Only (A-Z )  "+ msg);
				ctrl.focus();
				return false
			}
		}

}
function AlphaNumOnly(ctrl,e)
{
	if((e.keyCode<48 || e.keyCode >57) && (e.keyCode < 65 || e.keyCode >122 || e.keyCode == 94 || e.keyCode==95 ) && (e.keyCode !=13))
	{
		alert("This Field Should be AlphaNumeric Only");
		return false
	}
}

function ValidateForMasters(ctrl,msg)
{
//alert("/".charCodeAt(0));

		for(x=0;x<ctrl.value.length;x++)
		{
			i=(ctrl.value.charCodeAt(x));
			if((i<65 || i >122 || i==94 || i==95) &&  i !=13 && i!=45 && i !=32 && i!=41 && i !=40 && i!=46 && i!=38 && i !=47 && i !=48)
			{
				alert("Please Enter Alphabets Only (A-Z )  "+ msg);
				ctrl.focus();
				return false
			}
		}

}

function AlphaHyphenDot(ctrl,e)
{

	if((e.keyCode<48 || e.keyCode >57) && (e.keyCode < 65 || e.keyCode >122 || e.keyCode == 94 || e.keyCode==95 ) && (e.keyCode !=13) && (e.keyCode !=95) && (e.keyCode !=46))
	{
	
		alert("This Field Should be AlphaNumeric Only");
		return false
	}
}
function AlphaNum_Dot(ctrl,e)
{

	if((e.keyCode<48 || e.keyCode >57) && (e.keyCode < 65 || e.keyCode >122 || e.keyCode == 94 || e.keyCode==95 ) && (e.keyCode !=13) && (e.keyCode !=95) && (e.keyCode !=46))
	{
	
		alert("This Field Should be AlphaNumeric Only");
		return false
	}
}

function ValidateAlpha(ctrl,msg)
{
		for(x=0;x<ctrl.value.length;x++)
		{
			i=(ctrl.value.charCodeAt(x));
			if((i<65 || i >122 || i==94 || i==95) &&  i !=13 )
			{
				alert("Please Enter Alphabets Only (A-Z )  "+ msg);
				ctrl.focus();
				return false
			}
		}

}

function ValidateNumeric(ctrl,msg)
{
		for(x=0;x<ctrl.value.length;x++)
		{
			i=(ctrl.value.charCodeAt(x));
			if((i<48 || i >57 ) &&  i !=13)
			{
				alert("Please Enter Numeric Values (0-9 )  "+ msg);
				ctrl.focus();
				return false
			}
		}

}
function NumericOnly(ctrl, e)
{

		if((e.keyCode<48 || e.keyCode >57 ) &&  e.keyCode !=13 )
		{
			alert("Please Enter Numeric Values Only (0-9)");
			ctrl.focus();
			return false
		}
}
function Required(field,msg)
{
	if(trim(field.value)=="")
	{
		alert(msg);
		field.focus();	
		return false
	}
}
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function GoOtherWhatsNew1(cmb,nodeid)
{//alert(cmb.options[cmb.selectedIndex].value+"?NodeId="+nodeid);
	document.location=cmb.options[cmb.selectedIndex].value+"&NodeId="+nodeid;
}

function GoOtherWhatsNew(cmb)
{//alert(cmb.options[cmb.selectedIndex].value+"?NodeId="+nodeid);
	document.location='../'+cmb.options[cmb.selectedIndex].value;
}

function GoOtherAOI(cmb,nodeid)
{//alert(cmb.options[cmb.selectedIndex].value+"?NodeId="+nodeid);
	document.location=cmb.options[cmb.selectedIndex].value+"?NodeId="+nodeid;
} 

function checkLen(field, maxlimit) {

if (field.value.length > maxlimit)
{
field.value = field.value.substring(0, maxlimit-1);

}
else
{
field.value = field.value.substring(0, maxlimit-1);
//field.value = maxlimit - field.value.length;
//document.getElementById(field.id+"_maxChar").value = maxlimit - field.value.length;
}
} 



function OpenMicrosite(node, url, Menu)
{
	window.location = "Microsite.aspx?Node="+node+"&url="+url+"&Menu"+Menu;
}

function RefreshPage()
{
	  window.opener.location=window.opener.location;
	  //window.opener.location.reload();
	  
}

function OpenUserDetails(uid)
{
   
	window.open("../userprofile/UserDetails.aspx?uid="+uid,'author','addressbar=no scrollbars=yes width=760 height=500 resizable=yes');
	//
	return false;	
}

function OpenPopup(sURL,sName){

	if(sURL.indexOf("?")>=0)

		window.open(sURL,null);
		else
		window.open(sURL,null);

		}
function OpenPopupNodeID(sURL,Node,sName)
{

	if(sURL.indexOf("?")>=0)
		window.open(sURL+"&NodeID="+Node,sName,'addressbar=no scrollbars=yes width=760 height=500 resizable=yes');
	else
		window.open(sURL+"?NodeID="+Node,sName,'addressbar=no scrollbars=yes width=760 height=500 resizable=yes');
}
function OpenAuthor(uid){
	window.open("ShowUserProfile.aspx?uid="+uid,"UserProfile");
}
function OpenWindow(){

	window.open(sURL,sName);
}
function ChangeLocation(url){
	alert(url);
	window.location = url;
}
function OpenThread(tid){

	window.open("AddThread.aspx?ThreadID="+tid,"Thread");
}

function isValidDate(dateStr,strField) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
 var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
//alert("Date is not in a valid format for "+strField+".")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
//alert("Month must be between 1 and 12 for "+strField+".");
return false;
}
if (day < 1 || day > 31) {
//alert("Day must be between 1 and 31 for "+strField+".");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("Month "+month+" doesn't have 31 days for "+strField+"!")
return 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)) {
//alert("February " + year + " doesn't have " + day + " days for "+strField+"!");
return false;
   }
}
return true;  // date is valid
}

