function isBlank( s )
{
	if(trim(s).length == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//Trim
function ltrim ( s )
{
	return s.replace( /^\s*/, "" )
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}

function trim ( s )
{
	return rtrim(ltrim(s));
}


//email validate
function validateEmail(str) {
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\_\-\.]+\.([a-zA-Z]{2,5}|[0-9]{1,5})(\]?)$/; // valid
  if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
    return true;
  }
  return false;
}

function isDigit (c)
{
   return ((c >= "0") && (c <= "9"))
}

function isFloat (s)
{
    var decimalPointDelimiter = "."
    var i;
    var seenDecimalPoint = false;

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isProper(string) {

   if (!string) return false;
   var iChars = "~!^&+=-*|,:<>[]{}`\';()@&$#%\".";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
} 

function getOSPlatform()	
{
	var agt=navigator.userAgent.toLowerCase();
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) || 
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
               (agt.indexOf("windows 16-bit")!=-1) );  

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 || 
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

	if(is_win == true)
	{
		if(is_win95 == true){return "win95"; return false;}
		if(is_win16 == true){return "win16"; return false;}
		if(is_win31 == true){return "win31"; return false;}
		if(is_winme == true){return "winme"; return false;}
		if(is_win2k == true){return "win2k"; return false;}
		if(is_win98 == true){return "win98"; return false;}
		if(is_winnt == true){return "winnt"; return false;}
		if(is_win32 == true){return "win32"; return false;}
	}
}

function selectdatabasevalue(toselect,cmb) //compares value not text
{
	for(i=0;i<eval(cmb).length;i++)
	{
		if(eval(cmb).options[i].value==toselect)
		{
			eval(cmb).selectedIndex = i;
		}
	}
}

function openExit(sPageUrl)
{
	if(window.screenLeft >= 10004)
 	{
		var nwindow = window.open(sPageUrl,'','width=800,height=270');
		nwindow.moveTo(screen.availWidth/2-400,screen.availHeight/2-135);
	}
}


//check date validation
function checkdate(dateField)
{
// ------------- Checking for date in MM/DD/YYYY format ---------------------

	var expirydate="";
	var date="";
	var month="";
	var year="";
	expirydate = dateField;
	month=expirydate.substring(0,expirydate.indexOf("/"));
	date=expirydate.substring((expirydate.indexOf("/")+1),expirydate.indexOf("/",(expirydate.indexOf("/")+2)));
	year=expirydate.substring((expirydate.lastIndexOf("/")+1));

	if(expirydate.indexOf("/")==-1)
	{
		alert("Invalid Date Format");
		return false;
	}

	if(isNaN(date) || isNaN(month) || isNaN(year))
	{
		alert("Enter Date In Numerics Only");
		return false;
	}

	if(date > 31 || date < 1)
	{
		alert("Invalid Date Of Month");
		return false;
	}

	if(month > 12 || month < 1)
	{
		alert("Invalid Month");
		return false;
	}

	if(year < 1850 || year > 5002)
	{
		alert("Invalid Year");
		return false;
	}

	if(month == 4 || month == 6 || month == 9 || month == 11)
	{
		if(date > 30)
		{
			alert("Invalid Date Of Month")
			return false;
		}
	}

	if(month == 2)
	{
//----------- checking for leap year-------------
		var lyear=year-1848
		if((lyear%4==0) && (date<30))
		{
			if(date > 29)
			{
				alert("Invalid Date Of Month")
				return false;
			}
			//alert("leap year")
		}
		else if(date > 28)
		{
			alert("Invalid Date Of Month")
			return false;
		}
	}
	
	return true;
}

function getAge(o, now) 
{ 
	var d = new Date(o.getTime()); 
	var age = -1; 
	if (typeof(now) == 'undefined') now = new Date(); 
	while (now >= d) 
	{ 
	age++; 
	d.setFullYear(d.getFullYear() + 1); 
	} 
	return age; 
} 

function disableCtrlN()
{
	if ((event.keyCode == 78) && (event.ctrlKey))
	{
		//alert ("No new window")
		event.cancelBubble = true;
		event.returnValue = false;
		event.keyCode = false; 
		return false;
	}
}

