
//****************************************************************************************************************************************
		// AUTHOR:       Dheeraj Gupta
		// COMPANY:      design DYNAMICS
		// CODE TYPE:	javascript  code
//****************************************************************************************************************************************														
		// function to remove leading & trailing spaces
		function mytrim(str)
		{
			var s;
		  	s=str;
		   	// trailing spaces
			while(''+ s.charAt(s.length-1)==' ')s=s.substring(0,s.length-1);
			// leading spaces
				while(''+ s.charAt(0)==' ')s=s.substring(1,s.length);
				// return the new string
					return (s);
		} // end of function mytrim
		//--------------------------------------------------
		
		// function to remove leading & trailing spaces of &nbsp
		/*function mytrimnbsp(str)
		{
			var s;
		  	s=str;
		   	// trailing spaces
			while(''+ s.charAt(s.length-1)=='&nbsp;')s=s.substring(0,s.length-1);
			// leading spaces
				while(''+ s.charAt(0)=='&nbsp;')s=s.substring(1,s.length);
				alert ("In nbsp function : " + s);
				// return the new string
					return (s);
		} // end of function mytrim
		//--------------------------------------------------
		*/
						
		// function to enter
		function mytrimenter(str)
		{
			var s;
		  	s=str;
		   	// trailing spaces
			while(''+ s.charAt(s.length-1)=='\r')s=s.substring(0,s.length-1);
			// leading spaces
				//s=str;
				while(''+ s.charAt(0)=='\r')s=s.substring(1,s.length);
				// return the new string
					return (s);
		} // end of function mytrimenter
		
		//--------------------------------------------------				
						
		// checking for number of characters
		function chkLen(mstr,fLen)
		{
			if (mstr.value.length>0)
			{	if (mstr.value.length>fLen)
				{
					//alert("Address cannot exceed 1000 characters");
					return false;
				}
			}	
				return true;
		}
		//--------------------------------------------------
		
		//--------------------------------------------------				
						
		// checking for number of characters of the Text Area
		/*function chkLenTxtArea(mstr)
		{
			//alert("@ function.........");
			//fLen=5000;
			var mystr;
				mystr= mstr.value;				 
			if (mystr.length>fLen)
			{
					//if (mystr.length>fLen)
				//{
					//alert("Address cannot exceed 1000 characters");
					return false;
				//}
			}	
				//return true;
		}*/
		//----------------------------------------------
		
					
		// function to validate phone/fax
		function checkphone(ph)
		{
		  var len=ph.value.length;
		  for(i=0;i<len;i++)
		  {
				if((ph.value.charAt(i)>='0' && ph.value.charAt(i)<='9') || ph.value.charAt(i)=='(' || ph.value.charAt(i)==')' || ph.value.charAt(i)=='/')
					continue;
				else
				   break;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}
		//----------------------------------------------
						
		// checking for only alphanumeric characters
		function alphaNum(mstr)
		{
		  var len=mstr.value.length;
		  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='0' && mstr.value.charAt(i)<='9') || (mstr.value.charAt(i)>='a' && mstr.value.charAt(i)<='z') || (mstr.value.charAt(i)>='A' && mstr.value.charAt(i)<='Z') || (mstr.value.charAt(i)==' '))
					continue;
				else
				   break;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}
		//-------------------------------
		
		// checking for only alphabets only
		function isAlpha(mstr)
		{
		  var len=mstr.value.length;
		  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='a' && mstr.value.charAt(i)<='z') || (mstr.value.charAt(i)>='A' && mstr.value.charAt(i)<='Z') || (mstr.value.charAt(i)==' ') || (mstr.value.charAt(i)=='.') )
					continue;
				else
				   break;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}
		//-------------------------------
		

		// checking for only numbers only
		function isNumber(mstr)
		{
		  var len=mstr.value.length;
		  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='0' && mstr.value.charAt(i)<='9') || (mstr.value.charAt(i)==' '))
					continue;
				else
				   break;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}
		//-------------------------------
		
		// validating reconfirmed password
		function chkPassword(passObj,confirmObj)
		{
		
			var pass,pwd
			pass=passObj.value;
			pwd=confirmObj.value;

			if( pass!= pwd)
			{   alert("New Password and Confirm Password is not same.");
				confirmObj.focus();
				return false; }
			else
				return true;
		}
		//------------------------------------
		
		
		// function to validate email
		function checkmail(s) {
		var str=s.value
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var cnt=0
		if (str.indexOf(at)==-1){
	   		alert("Invalid E-mail ID")
	        return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Invalid E-mail ID")
			return false
		}

	 	if (str.indexOf(at,(lat+1))!=-1){
			alert("Invalid E-mail ID")
			return false
		 }

	 	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Invalid E-mail ID")
			return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			alert("Invalid E-mail ID")
			return false
		 }

		 if (str.indexOf(" ")!=-1){
			alert("Invalid E-mail ID")
			return false
		 }

		for(var i=0;i<lat;i++)
		{
			if(str.charAt(i)==dot)
			{	cnt=cnt+1;
			}	
		}
		if(cnt>1 )
		{
			alert("Invalid E-mail ID");
			return false;
		}
		return true;					
	}
	//-----------------------------------
	//validation FCK editor 
	function validateHeadingAdd(formobj)
				{
					var s=FCKeditorAPI.GetInstance(formobj).GetXHTML()
					 if( s == ""){
					   return false;
					 }
					 return true;
				}
	//------------------------------------
	function removeSpace(formobj,fieldRequired)
	{
		var s=new String;
		//var shidden = new String;
		for (var i = 0; i < fieldRequired.length; i++){
			var obj = formobj.elements[fieldRequired[i]];
			if (obj){
				switch(obj.type){
					case "text":
					case "hidden":						
						s=obj.value;
						s=mytrim(s);
						obj.value=s;
						//alert("In Remove space function."+ obj.value)
						break;
					case "textarea":
						s=obj.value;
						s=mytrim(s);
						obj.value=s;
						break;							
					}
			
				}
		}
	}
	
	function removeEnter(formobj,fieldRequired)
	{
		var s=new String;
		for (var i = 0; i < fieldRequired.length; i++){
			var obj = formobj.elements[fieldRequired[i]];
			if (obj){
				switch(obj.type){
					case "text":
					case "textarea":
						s=obj.value;
						s=mytrimenter(s);
						obj.value=s;
						break;	
					}
			
				}
		}
	}
	
	// This function checks for empty fields.			
	function isEmpty(formobj,fieldRequired,fieldDescription){
		var alertMsg = "Please enter \n";
		
		var l_Msg = alertMsg.length;
		
		for (var i = 0; i < fieldRequired.length; i++){
			var obj = formobj.elements[fieldRequired[i]];
			if (obj){
					
				switch(obj.type){
				case "select-one":
					if (obj.selectedIndex <= 0 || obj.options[obj.selectedIndex].text == "" ){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "select-multiple":
					if (obj.selectedIndex == -1){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "text":
				case "textarea":
				case "hidden":				
					if (obj.value == "" || obj.value == null){
						//alert("Hidden : " + obj.value);
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				//case "textarea":
				default:
					if (obj.value == "" || obj.value == null){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
				}
			}
		}
	
		if (alertMsg.length == l_Msg){		
			return true;
		}else{
			alert(alertMsg);
			return false;
		}
		
	}				
	

function isNumberdot(mstr)
{
		  var len=mstr.value.length;
		  var arrtext=new Array('~','`','!','@','#','%','^','&','*','(',')','{','}','[',']',':',';',',','?','/','<','>','=','|','-','_','+','\\','\'');
		  var l=arrtext.length;
		  var found=0;
		  for(i=0;i<len;i++)
		  {
			  found=0;
			  for(j=0;j<l;j++)
			  {
				if(mstr.value.charAt(i)==arrtext[j])
				{
					found=1;
					break;
				}
				else{
				   continue;
				}
			 }
			 if(found==1){
				 break;
			 }
		  }
		  if(found==1)
			return false;
		  else
		 	return true;
}
// checking dots and number
		function isDotNum(mstr)
		{
		  var len=mstr.value.length;
		  var cnt=0;
		  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='0' && mstr.value.charAt(i)<='9') || (mstr.value.charAt(i)=='.'))
					continue;
				else
				   break;
		  }
		  if(i<len)
			return(false);
		  else
			return(true);
		}
		//-------------------------------


//checking for valid price
function isPrice(mstr)
		{
		  var len=mstr.value.length;
		  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='0' && mstr.value.charAt(i)<='9')||(mstr.value.charAt(i))=='.')
					continue;
				else
				   break;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}


function isValidDate(dateStr) {
// 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.")
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.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
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!");
return false;
   }
}
return true;  // date is valid
}
//function used in category name validation

function isAlphaCat(mstr)
		{
		  var len=mstr.value.length;
		  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='0' && mstr.value.charAt(i)<='9') || (mstr.value.charAt(i)>='a' && mstr.value.charAt(i)<='z') || (mstr.value.charAt(i)>='A' && mstr.value.charAt(i)<='Z') || (mstr.value.charAt(i)==' ') || (mstr.value.charAt(i)=='(') || (mstr.value.charAt(i)==')') || (mstr.value.charAt(i)=='-') || (mstr.value.charAt(i)=='/'))
					continue;
				else
				   break;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}


// checking for only alphabets only
		function noAlpha(mstr)
		{
		  var len=mstr.value.length;
		  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='a' && mstr.value.charAt(i)<='z') || (mstr.value.charAt(i)>='A' && mstr.value.charAt(i)<='Z'))
					break;
				else
				   continue;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}

function isCurname(mstr)
{
		  var len=mstr.value.length;
		  var arrtext=new Array('~','`','!','@','#','%','^','&','*','(',')','{','}','[',']',':',';',',','?','/','<','>','=','|','-','_','+','\\','\'');
		  var l=arrtext.length;
		  var found=0;
		  for(i=0;i<len;i++)
		  {
			  found=0;
			  for(j=0;j<l;j++)
			  {
				if(mstr.value.charAt(i)==arrtext[j])
				{
					found=1;
					break;
				}
				else{
				   continue;
				}
			 }
			 if(found==1){
				 break;
			 }
		  }
		  if(found==1)
			return false;
		  else
		 	return true;
}

function isCharonly(mstr)
		{
		  var len=mstr.value.length;
		  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='0' && mstr.value.charAt(i)<='9') || (mstr.value.charAt(i)==' ') || (mstr.value.charAt(i)=='.'))
					break;
				else
				   continue;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}
//checking for the user name only allowing _ and no special character		
	function isAlpha1(mstr)
		{
		  var len=mstr.value.length;
		  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='a' && mstr.value.charAt(i)<='z') || (mstr.value.charAt(i)>='A' && mstr.value.charAt(i)<='Z') || (mstr.value.charAt(i)==' ') || (mstr.value.charAt(i)=='_') )
					continue;
				else
				   break;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}
//this function is to validate the url

function isUrl(mstr)
		{
		  var len=mstr.value.length;
		  if((mstr.value.charAt(0)>='a')&& (mstr.value.charAt(0)<='z'))
		  {
		 	  for(i=0;i<len;i++)
		  {
				if((mstr.value.charAt(i)>='0' && mstr.value.charAt(i)<='9') || (mstr.value.charAt(i)>='a' && mstr.value.charAt(i)<='z') || (mstr.value.charAt(i)>='A' && mstr.value.charAt(i)<='Z') || (mstr.value.charAt(i)=='/') || (mstr.value.charAt(i)=='-') || (mstr.value.charAt(i)==':') || (mstr.value.charAt(i)=='?') || (mstr.value.charAt(i)=='&') || (mstr.value.charAt(i)=='.') || (mstr.value.charAt(i)=='%') || (mstr.value.charAt(i)=='=') || (mstr.value.charAt(i)=='_'))
					continue;
				else
				   break;
		  }

		  if(i<len)
			return(false);
		  else
			return(true);
		}
	
	//else
	//return false;
}	

//validation to accept the special character in comany name
function isCompname(mstr)
{
		 
		  var len=mstr.value.length;
		  var arrtext=new Array('~','`','!','@','#','%','^','&','*','(',')','{','}','[',']',':',';',',','?','/','<','>','=','|','-','_','+','\\','\'');
		  var l=arrtext.length;
		  var found=0;
  if((mstr.value.charAt(0)>='a')&&(mstr.value.charAt(0)<='z') || (mstr.value.charAt(0)>='A')&&(mstr.value.charAt(0)<='Z'))
	{
		  for(i=0;i<len;i++)
		  {
			  found=0;
			  for(j=0;j<l;j++)
			  {
				if((mstr.value.charAt(i)==arrtext[j]) || (mstr.value.charAt(i)>='0' && mstr.value.charAt(i)<='9') || (mstr.value.charAt(i)>='a' && mstr.value.charAt(i)<='z') || (mstr.value.charAt(i)>='A' && mstr.value.charAt(i)<='Z') || (mstr.value.charAt(i)==' '))
				{
					found=1;
					continue;
				}
				else{
				   break;
				}
			 }
			 if(found==1){
				break;
			 }
		  }
		  if(found==1)
			return true;
		  else
		 	return false;

}
else
return false;
}
// Change Form Element Colour
function makefocus(txtobject){
document.getElementById(txtobject).style.backgroundColor = "#FFFFCC";
}
function removefocus(txtobject2){
document.getElementById(txtobject2).style.backgroundColor = "";
}

// Funstion add by prashant
//replace special character using java script
// this use to validate data while entering in text box
//var r={'special':/[\W]/g}

//var r={'special':/\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\|\<|\>|\?|\||\|\!/g}
var r={'special':/\$|,|@|#|~|`|\%|\*|\^|\+|\=|\[|\]|\[|\}|\{|\;|\:|\|\<|\>|\?|\||\|\!/g}																	 
function valid(o,w)
{
  o.value = o.value.replace(r[w],'');
}
//call of function valid
//onkeyup="valid(this,'special')" onblur="valid(this,'special')"

//Remove special characters from a string.

function clearText() {
     document.formname.fieldname.value=filterNum(document.formname.fieldname.value)

     function filterNum(str) {
//          re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
          re = /\$|,|@|#|~|`|\%|\*|\^|\+|\=|\[|\]|\[|\}|\{|\;|\:|\|\<|\>|\?|\||\|\!/g;																   
          // remove special characters like "$" and "," etc...
          return str.replace(re, "");
     }
}

//