/*var win;
var msie3=false;
var name="";
browserVer=parseInt( navigator.appVersion );
if( browserVer == 2 && navigator.appName == "Microsoft Internet Explorer" ) { browserVer++; msie3=true; }*/

function checkdate(datevalue)
{
	var err=0 ;
	var err1=0 ;
	var a,b,c,d,e,f
	a	=	datevalue
	if (a.length == 0)
	{
		return true ;
	}
	if (!(a.length == 8 || a.length == 6 ))
	{
		err=1 ;
	}
	if (a.length == 8)
	{
		b = a.substring(3, 5)// month

		c = a.substring(2, 3)// '/'

		d = a.substring(0, 2)// day

		e = a.substring(5, 6)// '/'

		f = a.substring(6, 8)// year
	}
	else
	{
		b = a.substring(2, 4)// month

		// c = a.substring(2, 3)// '/'

		d = a.substring(0, 2)// day

	//	e = a.substring(5, 6)// '/'

		f = a.substring(4, 6)// year
	}

	if (f < 50)
	{
		f = "20" + f ;
		f = parseInt(f);
	}
	else
	{
		f = "19" + f ;
		f = parseInt(f);
	}

	if (b<1 || b>12) err = 1

	if (isNaN(b)) err=1

	if (isNaN(d)) err=1
	if (isNaN(f)) err=1

	if (a.length==8 && c != '/') err = 1

	if (d<1 || d>31) err = 1

	if (a.length==8 && e != '/') err = 1

	if (f<1900 || f>3000) err = 1

	//advanced error checking
	// months with 30 days

	if (b==4 || b==6 || b==9 || b==11)
	{
		if (d==31) err=1
	}

	// february, leap year

	if (b==2)
	{
		// feb
		var g=parseInt(f/4)
		if (isNaN(g))
		{
			err=1
		}
		if (d>29) err=1
			if (d==29 && ((f/4)!=parseInt(f/4)))
				err=1
	}

	if (err==1)
	{
		alert("Please Check the Date Format ");
		return false ;
	}
	else
	{
		return true ;
	}
}
/*function winclose()
{
  return true;
}
function winclose()
{
  if( browserVer <= 2 ) { return true; }
  if( msie3 != true && typeof( win ) == 'object' && !win.closed ) { win.close(); } return true;
}
function Dacs_Alert(message,msgCode,height){
	var className="";
	var classMsg="";

	if ( typeof( height) == "undefined" ) { height = 200; }
	if (typeof(msgCode) == "undefined"){msgCode = 1;}
	var winl = (screen.width-300)/2;
	var wint = (screen.height-height)/2;
	var settings  ='height='+height+',';
    settings +='width=300,';
    settings +='top='+wint+',';
    settings +='left='+winl+',';
    settings +='scrollbars=no,';
    settings +='resizable=no';
  	winclose();
	if(msgCode==1){name="Dacs Alert !";className="Alert";classMsg="AlertMessage";}
	if(msgCode==2){name="Dacs Warning !";className="Warning";classMsg="WaningMessage";}
	if(msgCode==3){name="Dacs Info !";className="Info";classMsg="InfoMessage";}

	win=open( "", "dacs_alert",settings);

	if( msie3 == true ) while( typeof( win.document ) == "undefined" );

	win.document.write( "<HTML><HEAD><TITLE>"+ name +"</TITLE><LINK href='/GSA/include/Message.css' rel=stylesheet><LINK href=\"/GSA/include/navigationButton.css\" rel=stylesheet></HEAD>\n<BODY onBlur=\"self.focus()\" >\n" );
  	win.document.write( "<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0><TR class="+className+"><TD WIDTH=300><B>" + name +"</B></TD></TR>" );
  	win.document.write( "<TR><TD ALIGN=CENTER >&nbsp;</TD></TR>" );
  	win.document.write( "<TR><TD ALIGN=CENTER >&nbsp;</TD></TR>" );
  	win.document.write( "<TR><TD ALIGN=CENTER >&nbsp;</TD></TR>" );
	win.document.write( "<TR class="+classMsg+"><TD ALIGN=CENTER >"+ message +"</TD></TR>" );
  	win.document.write( "<TR><TD ALIGN=CENTER >&nbsp;</TD></TR>" );
  	win.document.write( "<TR><TD ALIGN=CENTER >&nbsp;</TD></TR>" );
  	win.document.write( "<TR><TD ALIGN=CENTER><FORM border=0 name=alertWin onSubmit=\"self.close();return false\"><INPUT TYPE=SUBMIT class=dacsButton VALUE=\"&nbsp;&nbsp;OK&nbsp;&nbsp;\"></FORM></TD></TR></TABLE>" );
  	win.document.write( "</BODY></HTML>\n" );
  	win.document.close();
}*/
/*
function Dacs_Alert(message, name, height, msgCode){
	if ( typeof( height) == "undefined" ) { height = 200; }
	if (typeof(name) == "undefined" ){ name = "Dacs Alert ";}
	if (typeof(msgCode) == "undefined"){msgCode = 1;}
  	winclose();

	win=open( "", "dacs_alert", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=" + height);

	if( msie3 == true ) while( typeof( win.document ) == "undefined" );

	win.document.write( "<HTML><HEAD><TITLE>"+ name +"</TITLE><LINK href=\"/GSA/include/Message.css\" rel=stylesheet></HEAD>\n<BODY onBlur=\"self.focus()\" >\n" );
  	win.document.write( "<TABLE CELLPADDING=6 WIDTH=\"100\%\" HEIGHT=\"100\%\" BORDER=0><TR ><TD><B>" + name +"</B></TD></TR>" );
  	win.document.write( "<TR class=\"tableheader\"><TD ALIGN=CENTER>"+ message +"</TD></TR>" );
  	win.document.write( "<TR><TD ALIGN=CENTER><FORM name=alertWin onSubmit=\"self.close();return false\"><INPUT TYPE=SUBMIT VALUE=\"&nbsp;&nbsp;OK&nbsp;&nbsp;\"></FORM></TD></TR></TABLE>" );
  	win.document.write( "</BODY></HTML>\n" );
  	win.document.close();
}
*/
function compareDates(smallerDate, largerDate){
	// dd / mm / yy
	// 01 2 34 5 67
	var date1 = new String(smallerDate);
	var date2 = new String(largerDate);

	var dateSmallYYMMDD = date1.substring(6,8)+date1.substring(3,5)+date1.substring(0,2);
	var dateLargeyymmdd = date2.substring(6,8)+date2.substring(3,5)+date2.substring(0,2);

	if (dateSmallYYMMDD > dateLargeyymmdd) {
		return false;
	}
	else {
		return true;
	}
}

function get_Day(date){
	var datevar = new Date(date);
	var str_day1	=	check_day(datevar.getDay());
	return str_day1;
}

function check_day(day1){
	var v	=	new String(day1);
	if(v  == "1")
		return	"Sun";
	if(v  == "2")
		return	"Mon";
	if(v  =="3")
		return	"Tue";
	if(v  == "4")
		return	"Wed";
	if(v  == "5")
		return	"Thu";
	if(v  == "6")
		return	"Fri";
	if(v  == "7" || v  == "0")
		return	"Sat";
	return "";
}

function getNextElement (field) {
  var form = field.form;
  for (var e = 0; e < form.elements.length; e++)
    if (field == form.elements[e])
		break;
  return form.elements[++e % form.elements.length];
}

function tabOnEnter (field, evt) {
  var keyCode = document.layers ? evt.which : document.all ?
evt.keyCode : evt.keyCode;
	alert("KEY CODE = "+keyCode);
  if (keyCode != 13)
    return true;
  else {
    getNextElement(field).focus();
    return false;
  }
}
// Returns true when enter key pressed
function enterKeyPressed(evt) {
  var keyCode = document.layers ? evt.which : document.all ?evt.keyCode : evt.keyCode;
  if (keyCode == 13) {
    return true;
  } else {
    return false;
	}
}
function toUpperCase(textField){
	var tmp = textField.value;
	textField.value = tmp.toUpperCase();
}
function checkdateFormat(datefield)
{
	if(datefield.value == ""){
		return;
	}
	var datestr = new String(datefield.value);

	if(checkdate(datefield.value))
	{
		if (datestr.length == 6)
			datefield.value = datestr.substring(0,2) + "/" + datestr.substring(2,4) + "/" + datestr.substring(4,6) ;
	}
	else
	{
		datefield.focus();
		datefield.select();
	}
}
// Use this if your date is of the form >221101 or <221101 or =221101
function checkSpecialDateFormat(datefield){

	if(datefield.value == ""){
		return;
	}
	var datestr = new String(datefield.value);
	var firstChar = datestr.charAt(0);

	if ((firstChar == '<') || (firstChar == '>') || (firstChar == '=')){
		datestr = datefield.value.substring(1,datestr.length);
	}else {
		firstChar = '';
	}

	if(checkdate(datestr))
	{
		if (datestr.length == 6)
			datefield.value = firstChar + datestr.substring(0,2) + "/" + datestr.substring(2,4) + "/" + datestr.substring(4,6) ;
	}
	else
	{
		datefield.focus();
		datefield.select();
	}


}
function imposeTextAreaMaxLength(Object, MaxLen)//MAX LENGTH FOR TEXT AREA KPKPKP
	{
	  return (Object.value.length <= MaxLen);
	}
	
function checkLength(textField,req_len){
		if (textField.value.length > req_len) {
	        textField.value =field.value.substring(0,req_len);
		 }
}
function popUp(url, name, options) {
	win=window.open(url, name ,options);
	win.focus();
}

function setFocus(textField){
	if (textField) {
		textField.focus();
		textField.select();
	}
}

function trim(strText) {
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

function checkNaN(textField){
	if(isNaN(textField.value)){
		alert("Please enter numeric value.");
		textField.focus();
		textField.select();
		return false;
	}else
	    return true;
}

function roundFloat(str_pass){
	  var j=0;
	  for(var i=0;i<str_pass.value.length;i++)
	  {
	    if(str_pass.value.charAt(i)=='.')
		 {
			j=i;
		 }
	  }
	 var _input_subvalue = str_pass.value.substring(j+3,j+4);
	  str_pass.value= str_pass.value.substring(0,j+3);
	 if(parseInt(_input_subvalue) >  5 || parseInt(_input_subvalue) == 5 )
	 {
			str_pass.value = parseFloat(str_pass.value) + .01;
	 }


}
function roundOff(value, precision)
{
        // temporary patch
        var initValue = parseFloat(value);
        if (initValue < 1) {
             return value;
        }
        // end temporary patch

        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = whole;
        }
        return result;
}

// rounds the give float number to two deciaml places
function roundFloat2(number){
		//alert ("Inside roundFloat "+number);

		var j=0;
		var counter = number.indexOf('.');
		var fractionPart = "00";

		if (counter == -1 ) {
			//alert ("Is an integer");
			decimalPart = number;
		} else {
			decimalPart = number.substring(0, counter)
			fractionPart = number.substring(counter+1, number.length);
			if (parseInt(fractionPart) < 10 ) {
				//alert (" Fraction part length "+fractionPart.length)
				if (fractionPart.length > 2 )
					fractionPart = fractionPart.substring(0,1) +  "0";
			} else if (parseInt(fractionPart) > 100) {
				roundingBit = fractionPart.substring(2,3)
				if (parseInt(roundingBit) >= 5 ) {
					fractionPart = parseInt(fractionPart.substring(0,2)) + 1;
				} else {
					fractionPart = fractionPart.substring(0,2);
				}
			} else {
				fractionPart = fractionPart.substring(0,2);
			}
		}

		return decimalPart+"."+fractionPart;

	}
// rounds the give float number to one deciaml places
function roundFloat1(number){
		var j=0;
		var counter = number.indexOf('.');
		var fractionPart = "00";

		if (counter == -1 ) {
			//alert ("Is an integer");
			decimalPart = number;
			
		} else {
			decimalPart = number.substring(0, counter)
			fractionPart = number.substring(counter+1, number.length);
			if (parseInt(fractionPart) < 50 ) {
				//alert (" Fraction part length "+fractionPart.length)
                                fractionPart = "50";
			} else if (parseInt(fractionPart) > 50) {
                              fractionPart = "00";
                              decimalPart = parseInt(decimalPart) + 1;
			}
		}
			
		return decimalPart+"."+fractionPart;
	}

function doStringToFloat(str_pass){
	// check if not a number
	if (checkNaN(str_pass)) {
		/*var j=0;
		for(var i=0;i<str_pass.value.length;i++){
		    if(str_pass.value.charAt(i)=='.'){
				j=i;
   	    	}
		}
		if(j==0){
			 str_pass.value = parseFloat(str_pass.value) + .001;
		}else {
			 str_pass.value = parseFloat(str_pass.value) + .000001;
		}*/
		str_pass.value = roundFloat2(roundOff(str_pass.value, 2));
	}

}
function doStringToFloat3(str_pass){
	// check if not a number
	if (checkNaN(str_pass)) {
		str_pass.value = roundOff(str_pass.value, 3);
	}
}
function floatToInt(str_pass){
	var j=0;
	for(var i=0;i<str_pass.value.length;i++) {
	    if(str_pass.value.charAt(i)=='.'){
			j=i;
		}
	}
	if(j!=0){
		var _input_subvalue = str_pass.value.substring(j+1,j+2);
		str_pass.value= str_pass.value.substring(0,j);
		if(parseInt(_input_subvalue) >  5 || parseInt(_input_subvalue) == 5 ){
			str_pass.value = parseFloat(str_pass.value) + 1.0;
		}
	}
}

function isEmpty(textValue) {
	if (trim(textValue)== "")
		return true;
	else
		return false;
}

function isZero(textValue) {
	if (parseFloat(textValue) == 0.0)
		return true;
	else
		return false;
}
function focusText(textField){
		textField.select();
}

function verifydateFormat(datefield){

		if(datefield.value == ""){
			return;
		}
		var datestr = new String(datefield.value);
			if (datestr.length == 6){
				datefield.value = datestr.substring(0,2) + "-" + datestr.substring(2,4) + "-20" + datestr.substring(4,6) ;
			}else if(datestr.length == 8){
				datefield.value = datestr.substring(0,2) + "-" + datestr.substring(3,5) + "-20" + datestr.substring(6,8) ;
			}
			else if (datestr.length == 10){}
			else{
				alert("Check date format ddMMyy or dd/MM/yy");			
				datefield.focus();
				datefield.select();
			}
		}
	
// ************************** AS ON 23-01-2008 WRITTEN BY KP****************************************************************//
function roundToMultipleOfPointFive(num1){

	if (checkNaN(num1)) {
	 	num=num1.value;
		var idx_1=num.indexOf(".");
		if(idx_1>=1){
			var len=num.length;
			var rw_id=num.substring(idx_1,len);
			var actVal=num.substring(0,idx_1);
			
			if(rw_id >0.5){
				actVal=parseFloat(actVal)+1;	
				num1.value=actVal;	
			}else if(rw_id >0){
				actVal=parseFloat(actVal)+0.5;		
				num1.value=actVal;	
			}	 
		} 
	}
}

