// Charecter Decleration
//............................................................................
var SPECIAL_CHARACTERS_NUMBERS = "`~!@#$%^&*()_-+=|\\}}{{\"':;<,>.?/0123456789"
var ALL_SPECIAL_CHARACTERS = "`~!@#$%^&*()_-+=|\\}}{{\"':;<,>.?/"
var ALL_NUMBERS = "0123456789"
var ALL_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var SP_CHAR_DOT = "`~!@#$%^&*()_-+=|\\}[{]\"':;<,>?/0123456789"
var VALID_APP_NO = "`~!@#$%^&*()+=|\\{[}]\"':;<,>.?"
var VALID_RECEIPT_NO = "`~!@#$%^&*()+=\|{[}]\"':;<,>.?"

//sadashiv
var TAKEONLY_NUMBER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`~!@#$%^&*()=\\|}]{[\"':;?><"


//...............................................................................
// These charecters are not allowed
var VALID_NAME_CHAR="`~!@#$%^&*()_-+=|\\}[{]\"':;<,>?/0123456789";
var ADDRESS_CHAR="\"'";
var NAME_CHAR="`~@#$%^&*()_-+=|\\}]{[\"':;?/><,";
var STATE_CHAR="`~!@#$%^*+=|\\}{\"':;?><";
var CITY_CHAR="`~!@#$%^*+=|\\}{\"':;?><";
var PHONE_CHAR="`~!@#$%^*=|\\]}[{\"':;?/><"
var UPLINE_CHAR="`~!@#$%^&*()_+=\\|]}{[\"':;?/>.<,/";
var USERID_CHAR="`~!@#$%^&*()+=\\|}]{[\"':;?><,";
var FREE_DAYS="Free Days should be numeric"
//alert messages
var FIRST_NAME="Please enter the First Name"
var VALID_NAME="Please enter the Valid Name"
var LAST_NAME="Please enter the Last Name"
var CONTACT_PHONE="Please enter the Contact Phone Number"
var VALID_CONTACT="Contact Number should be Numeric"
var PAY_PAL_ID="Please enter the Pay Pal ID"
var VALID_PAY_PAL_ID="Please enter the Valid Pay Pal ID"
//var LOGIN_NAME="Please enter the Login Name"
var VALID_LOGIN_NAME="Please enter a valid Login Name"


var TITLE = "Please enter the Website Title"
var KEYWORDS="Please enter the keywords"
var EMAIL="Please enter the Email Address"
var COMPANY_NAME="Please enter the Company Name"
var VALID_EMAIL = "Please enter valid Email Address"
var DOUBLE_QOUTE="Double Qoutes are not allowed"
var C_DOUBLE_QOUTE="Double Qoutes and Comma are not allowed"
var VALID_URL="Please enter valid URL"
var KEY_WORD="Please enter the Keyword"
var LOGIN_NAME="Please enter the Login Name"
var VALID_LOGIN_NAME="Please enter the Valid Login Name"
var PASSWORD="Please enter the password"
var SPACE="Spaces are not allowed"
var OLD_PASSWORD="Please enter the old password"
var NEW_PASSWORD="Please enter the New password"
var CONF_PASSWORD="Please enter the Confirm password"
var CONF_PW_WRONG="Check your Confirm password"
var DESCRIPTION="Please enter the Description"
var EXP_DAYS="Please enter the Expires days"
var VALID_EXP_DAYS="Expires days should be Numeric"
var AMOUNT="Please enter the Amount"
var VALID_AMOUNT="Amount should be Numeric"


var IE = document.all? true : false;
var NN = document.layers? true : false;


//..............................................................................
//To check for special characters.

function fnIsValidChar(txtfld, spChar, mes)
{
	var txtString= fnTrim(txtfld.value);
	for(var i=0; i<txtString.length; i++)
	{
	if(spChar.indexOf(txtString.charAt(i))!= -1)
	{
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	}
	return false;
		
}

//..............................................................................
//To allow the passed characters.

function fnAllowThisChar(txtfld, spChar, mes)
{
	var txtString= fnTrim(txtfld.value);
	for(var i=0; i<txtString.length; i++)
	{
	if(spChar.indexOf(txtString.charAt(i))== -1)
	{
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	}
	return false;
		
}

//----------------------------------------------------------------------------------------------
//To check single and double quotes.

function fnIsQuotes(txtfld, mes){
	var a_strString = fnTrim(txtfld.value)
	if(a_strString.indexOf('"') != -1)
	  {
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	if(a_strString.indexOf("'") != -1)
	{
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	
	return false
}


// function for checking for double qoutes

function fnIsDquotes(txtfld, mes){
	var a_strString = fnTrim(txtfld.value)
	if(a_strString.indexOf('"') != -1)
	{
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	return false
}

//--------------------------------------------------------------------------------------------------------------------

// Validates email id.

function fnIsEmail(txtfld, mes)
{
	var strString=fnTrim(txtfld.value);
	if(strString.length==0)
	{
	return false
	}
	else if(strString.search(/^\w+((-\w+)|(\.\w+))*\@[a-z0-9]+((\.|-_)[a-z0-9]+)*\.[a-z0-9]+$/)== -1)
    {
	alert(mes);
	txtfld.select();
	txtfld.focus()
	return true;		
	}
	return false;
	
}
//---------------------------------------------------------------------------------------------------
//Validates website.
function fnIsWebsite(txtfld, mes)
{
	var strString=fnTrim(txtfld.value);
	if(strString.length==0)
	{
		return false
	}
	else if(strString.search(/^(\bwww\b)*\.[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9/]+$/)== -1)
    {
	alert(mes);
	txtfld.select();
	txtfld.focus();
	return true;		
	}
	return false;
	
}
//---------------------------------------------------------------------------------------------------

// Trims the input string of leading and trailing spaces and returns the new string

function fnTrim(string)
{
	var cnt;	
	len = string.length;
	str = string;
	begin = -1;
	for(cnt=0;cnt<len;cnt++)
	{
		if (str.charAt(cnt) == " ")
		{	
			begin = cnt;
		}	
		else
		break;
		
	}
	str = str.slice(begin+1,len);
	len = str.length;
	end = len;
	for(cnt=len-1;cnt>=0;cnt--)
	{
		if (str.charAt(cnt) == " ")
		{	
			end = cnt;
		}	
		else
		break;
	}
	str = str.slice(0,end);
	return str;
}
//---------------------------------------------------------------------------------------------------
//To trim leading and trialing spacing whiling submitting.

function fnTrimOnSumbit()
{
	frm=document.forms[0]
	for(i=0; i<frm.length; i++)
	{
		if(frm.elements[i].type=="text")
		{
			frm.elements[i].value=fnTrim(frm.elements[i].value);
		}
	}
}
//---------------------------------------------------------------------------------------------------

// Checks if the input string is null or blanks

function fnIsNull(txtfld, mes)
{
	   var string=txtfld.value;
       if (fnTrim(string) == null || fnTrim(string) == "" )
       {
	   	alert(mes);
		txtfld.focus();
		txtfld.select();
     	return true;
       }
		return false;
}

//---------------------------------------------------------------------------------------------------
function fnCheckAllNew(chkName, chkList)
{
	frm=document.forms["cetdocumentsubmitentry"]
	if(chkName.checked==true)
	{
		chkList.checked=true;
	}
	if(chkName.checked==true)
	{
		for(var i=0; i<chkList.length; i++)
			{
			chkList[i].checked=true;
			}
	}
	if(chkName.checked!=true)
	{
		for(var i=0; i<chkList.length; i++)
			{
			if(chkList[i].checked==true)
			{
			chkList[i].checked=false;
			}
			}
	}
		
}
function fnUnCheckNew(chkName)
{
	//alert(chkName.name)
	frm=
		document.forms["cetdocumentsubmitentry"]
	chkName.checked=false;
}

//---------------------------------------------------------------------------------------------------

//For phone and fax validation
function fnIsPhone(txtfld, mes)
{
var string=txtfld.value;
if(fnIsValidPhoneNumber(string))
{
alert(mes);
txtfld.select();
txtfld.focus();
return true;
}
else
return false;
}

//---------------------------------------------------------------------------------------------------

//sadashiv

function checkPw(pw1,pw2,mes) {
var x=pw1.value;
var y=pw2.value;
if (x != y) {
alert (mes);
return true;
}
else return false;
}


//---------------------------
//check Passwords are same or not
function fnSamePassword(pw1,pw2,mes) {
var x=pw1.value;
var y=pw2.value;
if (x == y) {
alert (mes);
return true;
}
else return false;
}


//-------------------------------------
function dropDownMenu(menu, mes) 
   {
   var myindex=menu.selectedIndex;
   if (myindex==0)
      {
      alert(mes);
      menu.focus();
	  return true;
	  }
	else 
		{
		return false;
		}
   }

// checks the valid email id

function emailcheck(q)
{
	var mes="Please enter a Valid Email Id."
	var strString=fnTrim(q.value);
	if(strString.length==0)
	{
	alert("Email Id cannot be blank");
	q.focus();
	return true;
	}
	else if(strString.search(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)== -1)
    {
	alert(mes);
	q.select();
	q.focus();
	return true;		
	}
	return false;
	
}

// Trims the input string of leading and trailing spaces and returns the new string

function fnTrim(string)
{
	var cnt;	
	len = string.length;
	str = string;
	begin = -1;
	for(cnt=0;cnt<len;cnt++)
	{
		if (str.charAt(cnt) == " ")
		{	
			begin = cnt;
		}	
		else
		break;
		
	}
	str = str.slice(begin+1,len);
	len = str.length;
	end = len;
	for(cnt=len-1;cnt>=0;cnt--)
	{
		if (str.charAt(cnt) == " ")
		{	
			end = cnt;
		}	
		else
		break;
	}
	str = str.slice(0,end);
	return str;
}

//for accepting only alphabets
function CheckKeys(obj)
{
if ((event.keyCode>=65 && event.keyCode<=90)||(event.keyCode>=97 && event.keyCode<=122)||(event.keyCode==32))
return true;
else
return false;
}

// for accepting only numbers
function CheckKeys1(obj)
{
if (event.keyCode>=48 && event.keyCode<=57)
return true;
else
return false;
}


// another function for stop word

function checkword(field)
{
worda=field.value;
worda=worda.split(",");
for(j=0; j<worda.length; j++)
	{
       	word=worda[j].split(" ");
		//alert(word[0]);
		for(i=0; i<word.length; i++)
		{
		var text=word[i].toLowerCase();
		if(text==("a" || "an" ||"and"||"are" || "as" || "at" || "be" || "by" || "com" || "for" || "from" || "how" || "I" || "in" || "is" || "it" || "of" || "on" || "or" || "that" || "the" || "this" || "to" || "us" || "what" || "where" || "who" || "with"))
		{
		alert("'a, an, and, are, as, at, be, by, com, for, from, how, I, in, is, it, of, on, or, that, the, this, to, us, what, where, who, with' "+"these words are not allowed")
		field.select();
		return true;
		break;
		}
		}
		
	}
}

// checks stop word
function checks(str,dex)
{
	//frm=document.form1.str;
	form=str;
	//alert(dex);
	var blocklist = new Array ( "a","an","and","are","as","at","be","by","com", "for","from","how","I","in","is","it","of","on","or","that","the","this","to","us","what","where","who","with" );
	//alert(blocklist.length);
	var blockstr="";
	for( i=0;i < blocklist.length ;i++)
	{	
	var sand=blocklist[i];
	var pos = (form.value.length)-(blocklist[i].length)-1;
	var land=form.value.indexOf(" "+sand+" ");
	var land1=form.value.indexOf(sand+" ");
	var exstr=form.value+".";
	var land2=exstr.indexOf(" "+sand+".");
	var land3=form.value
	var land4=exstr.indexOf(" "+sand+",");
	if ( (land != -1) || (land1 == 0) || (land2 != -1) || (land4 != -1) ||(land3 == sand))
		{
			//alert("yes ther");
			if(blockstr == "")
			{
				blockstr=blockstr+blocklist[i];
			}
			else
			{
				blockstr=blockstr+", "+blocklist[i];
			}
			//return false;
		 }
	//else
		//{
		//	alert("not ther");
		//	return false;
		//}
	 }
	 if ( blockstr != "")
	 {
		alert( " You have typed some of the blocked words in "+dex+" such as : " + blockstr);
		form.focus();
		return true;
		}
	 else
	 return false;
}

//-------------------------------------
//comparedropdown menu
function fncomparedropDownMenu(menu1, menu2, mes) 
   {
     if (menu1.selectedIndex>menu2.selectedIndex)
      {
      alert(mes);
      menu1.focus();
	  menu1.select();
	  return true;
	  }
	else 
		{
		return false;
		}
   }


   //----------------------------
   //Allow Numbers only to enter

function fnNumberOnly(txtfld, mes)
{
	var Num="0123456789";
	var txtString= fnTrim(txtfld.value)
	for(var i=0; i < txtString.length; i++)
	{
	if(Num.indexOf(txtString.charAt(i))== -1)
	{	
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	return false;
	}
			
}

//---------------------------------------
//check atleast one check box

function fnchekbox(chekbox, mes)
	{
     
     for (var i = 0; i <chekbox.length; i++)
	  {
      checked =chekbox[i].checked;
      if (!checked)
	   {
       alert(mes);
	   return true;
	   }
	   return false;
	  }
  
}

//-----------------------------------
//check atleast one rediobutton box

function fnchekrdiobutton(chekbox, mes){
	
	 var a=1;
	 for (var i = 0; i<chekbox.length; i++)
	  {
      checked =chekbox[i].checked;
      if (checked)
	   {
       a=a+1;
	   }
	   }


	   if(a>1)
	   {
	 return false;
	   }
	    else
		 {
	   alert(mes);
	   return true;
	    }

}

//--------------------------------------------------------
// validate URL
function fnvalidateURL(txtfld, mes)
{
	var strString=fnTrim(txtfld.value);
	if(strString.length==0)
	{
		return false
	}
	else if(strString.search(/^(\http\:\/\/)[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9/]+$/)== -1)
  
	{
	alert(mes);
	txtfld.select();
	txtfld.focus()
	return true;		
	}
	return false;
	
}

//-----------------------------------
//check the spaces

function fnCheckSpace(txtfld, mes)
{
	var string = txtfld.value;
	for(i=0; i<=string.length; i++)
	{
	if(string.charAt(i)==" ")
	{
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	}
	return false;
		
}


//----------------------------------------------------
// validate URL
function fnvalidateURL(txtfld, mes)
{
	var strString=fnTrim(txtfld.value);
	if(strString.length==0)
	{
		return false
	}
	else if(strString.search(/^(\http\:\/\/)[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9/]+$/)== -1)
  
	{
	alert(mes);
	txtfld.select();
	txtfld.focus()
	return true;		
	}
	return false;
	
}

//---------------------------------------------------------------------------------------------------
//Validates website.
// here value is removed in txtfld becoz its consider as variable
function fnIsWebsite(txtfld,Fname,mes)
{
	var strString=fnTrim(txtfld);
	if(strString.length==0)
	{
		return false
	}
	//else if(strString.search(/^(\bwww\b)*\.[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9/]+$/)== -1)
    else if(strString.search(/^(\bwww\b)*\.[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9/]+$/)== -1)
	{
	alert(mes);
	Fname.select();
	Fname.focus()
	return true;		
	}
	return false;
	
}

//----------------------------------------------------------------------------------------------
//To check double quotes.

function fnIsQuotes(txtfld, mes){
	var a_strString = fnTrim(txtfld.value)
	if(a_strString.indexOf('"') != -1)
	  {
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}	
	return false
}


//---------------------------------------------------
//check double quote and ','

function CheckCommaANDQuotes(txtfld, mes){
	var a_strString = fnTrim(txtfld.value)
	if(a_strString.indexOf('"') != -1)
	  {
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	if(a_strString.indexOf(",") != -1)
	{
	alert(mes)
	txtfld.focus();
	txtfld.select();
	return true;
	}
	
	return false
}



//----------------------------------
//regarding EXP date
function DateAdd(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth()	+ numMonths;
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	
	return returnDate;

}

function YearAdd(startDate, numYears)
{
		return DateAdd(startDate,0,0,numYears);
}

function MonthAdd(startDate, numMonths)
{
		return DateAdd(startDate,0,numMonths,0);
}

function DayAdd(startDate, numDays)
{
		return DateAdd(startDate,numDays,0,0);
}



//---------------------------------

//check wheter its numeric or text

function checkInt(txtfld,msg)
{
	var val=txtfld.value;
	if(isNaN(val))
	{
		alert(msg);
		txtfld.focus();
		txtfld.select();
		return true;
	}
	return false;
}

//--------------------------------

