
function checkNull(x) {
	if(x.value=="") {
		x.className='inputerror';		
	}else{
		x.className='';
	}
}

function checkEmail(x) {
	if(! x.value=="") {
		var y = isEmail(x.value);
		if (!y){
			x.className='inputerror';
		}else{
			x.className='';
		}
	}
}


function focussed(z) {
	if(z.value=="Enter here") {
		z.value=="";
	}
}

function unfocussed(z) {
	if(z.value=="") {
		z.value=="Enter here";
	}
}


function focusOnFirst() {
	//FOCUSSES ON THE FIRST ELEMENT OF THE FORM.. SHOULD BE WRITTEN ON onLoad EVENT OF BODY TAG.
	if(document.forms.length>0) {
		j = document.forms[0].elements.length;
		for (i=0;i<j ;i++ )	{
			if (!(document.forms[0].elements[i].type=="hidden") && !(document.forms[0].elements[i].style.visibility=="hidden")) {
				document.forms[0].elements[i].focus();
				i=j;
			}
		}
	}
}


/*
function forwardFocus(jj) {
	var x = document.forms[0].elements.length;
	var frm = document.forms[0];
	for(i=0;i<x;i++) {
		if(jj.name==frm.elements[i].name) {
			if((i + 1)==x) {
				frm.elements[i].blur();
			}else{
				frm.elements[i+1].focus();
			}
		}
	}
}
*/

function forwardFocus(jj) {
	var x = document.forms[0].elements.length;
	var frmm = document.forms[0];
	for(i=0;i<x;i++) {
		if(jj.name==frmm.elements[i].name) {
			if(frmm.elements[i+1].type=="hidden") {
				for(k=i;k<x;k++) {
					if (!(frmm.elements[k+1].type=="hidden")) {
						frmm.elements[k+1].focus();
						k=i;
						i=x;
					}
				}
			}else{
				frmm.elements[i+1].focus();
				i=x;
			}
		}
	}
}

function makeAllCaps(x) {
	//written on keyPress event of a text box and blur
	x.value = x.value.toUpperCase();
}

function makeAllSmall(x) {
	//written on keypress event of a text box and blur
	x.value = x.value.toLowerCase();
}
 
function shivaKeyPressDate(mfield) {
   keyvalue=event.keyCode; 
   var txtLength = mfield.value.length;
   var txtValue = mfield.value;
   if(keyvalue <48  || keyvalue >58 || txtLength >= 10)   
   {      event.returnValue = false;   }   if((txtLength==2)||(txtLength==5))  {
   mfield.value +='/';   }
   return true
 }

function shivaCheckDates(dt,mon,yr,dtObj) {
//this method checks the leapyear and dates
//THIS IS WHERE I SHD USE..
	var d; var m; var y; var leapy; var ly; var boo=true;
	if (yr.length ==2)
	{
		yr = "20" + "" +  yr;
	}
	if(isNaN(dt) || isNaN(mon) || isNaN(yr)) {
		boo = false;
		alert("Please enter only Numerics");
	}else {
	d = dt;
	m = mon;
	y = yr;
	leapy = y/4;
	ly = leapy - parseInt(leapy);
	//boo = "yes";
	if(d > 31 || d <= 0)  {
	//checking if any date is morethan 31
		boo = false;
		alert("Please Enter Proper Date");
		dtObj.focus();
	}else if(m > 12 || m <= 0) {
		boo = false;
		alert("Please Enter Proper Month");
		dtObj.focus();
	}else if(m==2 && d > 29) {
	//checking if date is more than 29 in feb
		boo = false;
		alert("A Date can't be morethan 29 in February");
		dtObj.focus();
	}else if(m==2 && !(ly==0) && d > 28) {
	//checking leap year
		boo = false;
		nm = dtObj.name;
		alert(nm + " can't be morethan 28 in February, "+ y +" is not a Leap year");
		dtObj.focus();
	}else if((m==4 || m==6 || m==9 || m==11) && (d > 30)) {
	//checking if dates exceed the limit
		boo =false;
		nm = dtObj.name;
		alert("31 can't be the Date in the entered month of " + nm);
		dtObj.focus();
	}else if(y < 1900 || y > 2099) {
		boo = false;
		alert("An Year can't be greater than 2099 or less than 1900..");
		dtObj.focus();
	}
	}
	return boo;
}


function shivaChanged(x) {
	document.forms[0].action=x;
	document.forms[0].submit();
}

function getTodayDateString() {
				d = new Date();
			dd = d.getDate() + "";
			mm = (d.getMonth() + 1)+"";
			yyyy = d.getFullYear() + "";
			if (dd.length < 2) {
				dd = "0" + dd;
			}
			if (mm.length < 2) {
				mm = "0" + mm;
			}
			dtStr = dd + "/" + mm + "/" + yyyy;
			return dtStr;
}

function modifyDateString(str){
	arr = str.split("/");
	d = arr[0];
	m = arr[1];
	y = arr[2];
	if (d.length < 2){
		d = "0" + d;
	}
	if (m.length < 2)	{
		m = "0" + m;
	}
	if (y.length == 2)	{
		y = "20" + y;
	}
	if (y.length==3) {
		y="2" + y;
	}
	if (y.length==1){
		y="200" + y;
	}
	mdt = d + "/" + m + "/" + y;
	return mdt;
}

function checkShivaDate(dObj) {
	//write on OnBlur event..
	k = dObj.value;
	if (k!="")	{
		a = k.split("/");
		if (a.length < 3) {
			alert("Please enter the Complete date.. in DD/MM/YYYY format..");
			dObj.focus();
		} else {
			k = modifyDateString(k);
			dObj.value = k;
			arr = k.split("/");
			h = shivaCheckDates(arr[0],arr[1],arr[2],dObj);
		}
	}
}

function fnOnlyNumbers(x,mxLength,dot) {
		//SHOULD BE WRITTEN ON KEYPRESS EVENT
keyvalue=event.keyCode;
//alert(keyvalue);

var txtLength =x.value.length;
var txtValue =x.value;

if (dot=='Y') {
		if (keyvalue <45  || keyvalue >58 ||  keyvalue ==58){
				event.returnValue = false;
			}
		if (keyvalue == 45  || keyvalue == 47){
				event.returnValue = false;
			}
		if (txtLength == mxLength && keyvalue!=46 && txtValue.indexOf(".") == -1)	{
				event.returnValue = false;
			}
		if (keyvalue==46)  {
				if (txtValue.indexOf(".") != -1) {
						event.returnValue = false;
					}
			}
		if (txtValue.indexOf(".") != -1)	{
				var nextlength=txtValue.substr(txtValue.indexOf(".")+1,4).length;
			}
		if (nextlength==2) {
				event.returnValue = false;
			}
	}
	
if (dot=='N') {
		if (keyvalue <45  || keyvalue >58) {
				event.returnValue = false;
			}
		
		if (keyvalue == 45  || keyvalue == 47 || keyvalue == 46) {
				event.returnValue = false;
			}
			
		if (mxLength!='') {
				if (txtLength == mxLength) {
						event.returnValue = false;
					}
			}	
	}	
}


function checkNumeric(n) {
     hit=true;
	if (isNaN(n.value)) {
	   alert("Please enter only numeric values");
   		n.focus();
		n.select();
	   hit = false;
	   }
	else if(n.value <= 0  ){
		alert("Please enter Proper numeric values");
		n.focus();
		n.select();
      hit=false;
	}
		return hit;
}

function makeAllCaps(x) {
	x.value = x.value.toUpperCase();
}

function makeAllSmall(x) {
	x.value = x.value.toLowerCase();
}


function makeProperWord(x) {
	//IF U GIVE A WORD TO THIS METHOD.. IT MAKES THE FIRST LETTER OF 
	//THE GIVEN WORD A CAPITAL LETTER
	if (x=="") {
		return x;
	}else{
		str = new String(x);
		return str.charAt(0).toUpperCase() + str.slice(1);
	}
}

function makeProperSentence(x) {
	//IF U GIVE A SENTENCE TO THIS METHOD.. IT MAKES THE FIRST LETTER OF 
	//THE GIVEN WORD A CAPITAL LETTER
	if(x!=""){
		str = new String(x);
		arr = str.split(" ");
		y="";
		for(i=0;i<arr.length;i++){
			y=y +" " + makeProperWord(arr[i]);
		}
		return y.slice(1);
	}else{
		return x;
	}
}

function makeThisAProperWord(x) {
	//IF U GIVE A WORD TO THIS METHOD.. IT MAKES THE FIRST LETTER OF 
	//THE GIVEN WORD A CAPITAL LETTER
	//THIS SHOULD BE WRITTEN ON BLUR EVENT..
	if (x.value!="") {
		str = new String(x.value);
		x.value=str.charAt(0).toUpperCase() + str.slice(1);
	}
}

function makeThisAProperSentence(x) {
	//IF U GIVE A SENTENCE TO THIS METHOD.. IT MAKES THE FIRST LETTER OF ALL 
	//THE WORDS IN THAT SENTENCE A CAPITAL LETTER..
	//THIS SHOULD BE WRITTEN ON BLUR EVENT..
	if(x.value!=""){
		str = new String(x.value);
		arr = str.split(" ");
		y="";
		for(i=0;i<arr.length;i++){
			if (arr[i]!=""){
				y = y + " " + arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
			}
		}
		x.value=y.slice(1);
	}
}


function checkPromotionDate(dt1,dt2) {
	//dt1 should be From Date..
	//dt2 should be To Date..
	//both the date should n't be nulls and should be complete..and should be in dd/mm/yyyy format only.
	hit= true;
	if(dt1=="" || dt2=="" || dt1.length < 10 || dt2.length < 10) {
		alert("Both the Dates submitted shouldn't be empty or partially filled..");
		hit = false;
	}else{
		arr1 = dt1.split("/");
		arr2 = dt2.split("/");
		date1 = new Date();
		date2 = new Date();
		today = new Date();
		date1.setDate(arr1[0]);
		date1.setMonth(parseInt(arr1[1]) - 1);
		date1.setYear(arr1[2]);
		date2.setDate(arr2[0]);
		date2.setMonth(parseInt(arr2[1]) - 1);
		date2.setYear(arr2[2]);
		if (date1 > date2)
		{
			alert("Sorry.. To Date should be greater than OR equal to  From Date for the Promotion..");
			hit = false;
		}else if (date1 < today)
		{
			alert("Sorry.. From Date should be greater than or Equal To Today's Date for Promotion..");
			hit = false;
		}
	}
	return hit;
}


function checkPODateDiff(dt1,dt2) {
	//dt1 should be From Date..
	//dt2 should be To Date..
	//both the date should n't be nulls and should be complete..and should be in dd/mm/yyyy format only.
	hit= true;
	if(dt1=="" || dt2=="" || dt1.length < 10 || dt2.length < 10) {
		hit = false;
		alert("Both the Dates submitted shouldn't be empty or partially filled..");
	}else{
		arr1 = dt1.split("/");
		arr2 = dt2.split("/");
		date1 = new Date();
		date2 = new Date();
		date1.setDate(arr1[0]);
		date1.setMonth(parseInt(arr1[1]) - 1);
		date1.setYear(arr1[2]);
		date2.setDate(arr2[0]);
		date2.setMonth(parseInt(arr2[1]) - 1);
		date2.setYear(arr2[2]);
		if (date1 >= date2){
			hit = false;
		}else{
			hit = true;
		}
	}
	//alert("Date1 " + date1 + "; Date2 " + date2 + hit);
	return hit;
}

function isGThanToday(dt1) {
	hit= true;
	if(dt1=="" || dt1.length < 10) {
		hit = false;
		alert("The Date submitted shouldn't be empty or partially filled..");
	}else{
		arr1 = dt1.split("/");
		date1 = new Date();
		today = new Date();
		date1.setDate(arr1[0]);
		date1.setMonth(parseInt(arr1[1]) - 1);
		date1.setYear(arr1[2]);
		if (today > date1){
			hit = true;
		}else{
			hit = false;
		}
	}
	return hit;
}


function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}
