/*
 ' History Header :           Version             - Date                       - Developer Name 
 ' History        :             1.0               - July 08, 2009              - Madhusudhan
 */
 	/**
	  * @funciton		: initilizeEditor
	  * @parameters 	: 
	  * @description	: This function is used to initialize the tinyMce editor
	  ' History Header :           Version             - Date                       - Developer Name
	  ' History        :             1.0               - July 08, 2009              - Madhusudhan
	  */ 
	/* Declare variable for the setting browser based height and width*/
	var editor_title_width="694px";
	var editor_title_height="300px";
	function initilizeEditor(){
		var browserName=navigator.appName; 
		if(browserName=="Microsoft Internet Explorer")
        {
      		editor_title_width="720px";
			editor_title_height="220px";
		}
	   /*Added for the setting Editor's Title*/
		tinyMCE.init({
        // Added by Jason
		forced_root_block : false,
	    force_p_newlines : 'false',
	    remove_linebreaks : false,
	    force_br_newlines : true,
	    remove_trailing_nbsp : false,    
	    verify_html : false,
		// End added by Jason
		theme : "advanced",
        mode : "textareas",
		plugins : "ibrowser,emotions,inlinepopups",
		theme_advanced_buttons1_add : "hr,removeformat,visualaid,|,sub,sup,|,charmap,|,ibrowser",
		theme_advanced_buttons2_add : "|,forecolor,fontselect,fontsizeselect,forecolor,|,emotions",
		theme_advanced_buttons3 : "",
        convert_urls : false,
		width:editor_title_width,
		height :editor_title_height
		});		
	}

	function isValidChar(objValue)
		{
				if(objValue.value!="")
				{
					  var  strError	="";	
					  var charpos = objValue.value.search("[^A-Za-z0-9 ]"); 
					  var At=objValue.value.charAt(0);
					  if(isNaN(objValue.value.charAt(0))==0)
					  {
						  
						  return false;
					  }
					  else if(objValue.value.length > 0 &&  charpos >= 0)  
					  {
							if(!strError || strError.length ==0) 
							{ 
								return false;
								  //strError ="Only alpha-numeric characters allowed !!"; 
							}//if 
							
							return false; 
					  }
				}
				return true;
			
		}

function isValidZip(objValue)
		{
				if(objValue.value!="")
				{
					  var  strError	="";	
					  var charpos = objValue.value.search("[^A-Za-z0-9]"); 
					  var At=objValue.value.charAt(0);
					  if(isNaN(objValue.value.charAt(0))==0)
					  {  
						  return false;
					  }
					  else if(objValue.value.length > 0 &&  charpos >= 0)  
					  {
							if(!strError || strError.length ==0) 
							{ 
								return false;
								  //strError ="Only alpha-numeric characters allowed !!"; 
							}//if  
							 return false; 
					  }
				}
				return true; 
		}

		function isnotValidZipcode(objValue)
			{
				if(objValue.value!="")
				{
					  var  strError	="";	
					  var charpos = objValue.value.search("^[A-Za-z0-9]{1,10}$"); 
					  var At=objValue.value.charAt(0);
					  if(isNaN(objValue.value.charAt(0))==0)
					  {  
						  return false;
					  }
					  else if(objValue.value.length > 0 &&  charpos >= 0)  
					  {
							if(!strError || strError.length ==0) 
							{ 
								return false;
								  //strError ="Only alpha-numeric characters allowed !!"; 
							}//if  
							 return false; 
					  }
				}
				return true; 
		}
		
		function isInteger(objValue)
		{
				if(objValue.value!="")
				{
					  var  strError	="";					
					  var charpos = objValue.value.search("[^0-9]"); 
					  if(objValue.value.length > 0 &&  charpos >= 0) 
					  { 
						if(!strError || strError.length ==0) 
						{ 
							return false;
						 // strError = "Only digits allowed "; 
						} 
						
						return false; 
					  }
				}
				return true;
		}
		function isReferenceNumber(objValue){
			if(objValue.value!="")
				{
					  var  strError	="";					
					  var charpos = objValue.value.search("[^0-9]"); 
					  if(objValue.value.length > 0 &&  charpos >= 0) 
					  { 
						if(!strError || strError.length ==0) 
						{ 
							return false;
						 // strError = "Only digits allowed "; 
						} 
						
						return false; 
					  }
					  if(objValue.value.length < 10){
						  return false;
					  }
				}
				return true;
		}
		
		function isProperText(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";				
				var charpos = objValue.value.search("[^A-Za-z0-9, ]"); 
              	if(objValue.value.length > 0 &&  charpos >= 0) 
              	{ 
                  if(!strError || strError.length ==0) 
                { 
                  strError = "Only alphabetic characters allowed !!"; 
                }//if                             
             //   alert(strError + "\n ( Error character position " + eval(charpos+1)+")"); 
			
                return false; 
              }//if
				
			}
			return true;
		}

        function isProperState(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";				
				var charpos = objValue.value.search("[^A-Za-z0-9,\. \-]"); 
              	if(objValue.value.length > 0 &&  charpos >= 0) 
              	{ 
                  if(!strError || strError.length ==0) 
                { 
                  strError = "Only alphabetic characters allowed !!"; 
                }//if                             
             //   alert(strError + "\n ( Error character position " + eval(charpos+1)+")"); 
			
                return false; 
              }//if
				
			}
			return true;
		}


		function isText(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";				
				var charpos = objValue.value.search("[^A-Za-z]"); 
              	if(objValue.value.length > 0 &&  charpos >= 0) 
              	{ 
                  if(!strError || strError.length ==0) 
                { 
                  strError = "Only alphabetic characters allowed !!"; 
                }//if                             
             //   alert(strError + "\n ( Error character position " + eval(charpos+1)+")"); 
			
                return false; 
              }//if
				
			}
			return true;
		}
		
		
		// added by sriprakash singh for first name & last name --start
		function isText_whitespace(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";				
				var charpos = objValue.value.search("[^A-Z a-z]"); 
              	if(objValue.value.length > 0 &&  charpos >= 0) 
              	{ 
                  if(!strError || strError.length ==0) 
                { 
                  strError = "Invalid characters are not allowed !"; 
                }
		        return false; 
              }//if
			}
			return true;
		}
		
		
		function isText_orgnization(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";				
				var charpos = objValue.value.search("[^A-Za-z0-9 \.'&,!@#$%\*_()`~\^\-]"); 
              	if(objValue.value.length > 0 &&  charpos >= 0) 
              	{ 
                  if(!strError || strError.length ==0) 
                { 
                  return false; 
                }//if                             
             //   alert(strError + "\n ( Error character position " + eval(charpos+1)+")"); 
			
                return false; 
              }//if
				
			}
			return true;
		}
		
		// added by sriprakash singh for first name & last name & orgnaization --end
		
		
		function isText1(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";				
				var charpos = objValue.value.search("[^A-Za-z0-9& ,]"); 
              	if(objValue.value.length > 0 &&  charpos >= 0) 
              	{ 
                  if(!strError || strError.length ==0) 
                { 
                  return false; 
                }//if                             
             //   alert(strError + "\n ( Error character position " + eval(charpos+1)+")"); 
			
                return false; 
              }//if
				
			}
			return true;
		}
		function isValidEmailFormat_(objValue)
		{
			
			if(objValue.value!="")
			{
				var  strError	="";
				 if(!validateEmailv2(objValue.value)) 
           		 { 
				     strError ="Enter a valid Email Address!! "; 
					
					 return false;
				}

			}
			return true;
		}
		
		function isDateMMDDYY(objValue)
		{
			if(objValue.value!="")
			{
				if (isDate(objValue.value)==false){
				
				return false
			}

				
			}
			return true;
		}
		
		function isDateDDMMYY(objValue)
		{
			if(objValue.value!="")
			{
			 	if (isDate2(objValue.value)==false)
				{
					
					return false			
				}
				
			}
			return true;
		}
		
		function isValidCellNo(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";
				var charpos = objValue.value.search(/\d{3}\-\d{3}\-\d{4}/); 
			  
				  if(objValue.value.length > 0 &&  charpos ==-1) 
				 { 
					if(!strError || strError.length ==0) 
					{ 
					  strError = "phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx."; 
					}
					
					return false; 
             	 }//if 
             
				
			}
			return true;
		}
	
		function isValidEmailFormat(email){
			
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value))
			{
				return (true);
			}
			return false;
		}
			
		
		
	function isValidEmailFormat_old(email)
	{
		if(email.length <= 0)
		{
		  return true;
		}
		
		var splitted = email.match("^(.+)@(.+)$");
		if(splitted == null) return false;
		
		if(splitted[1] != null )
		{
		 
			var regexp_user=/^\"?[\w-_\.]*\"?$/;
		  if(splitted[1].match(regexp_user) == null) return false;
		}
		if(splitted[2] != null)
		{
		  var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		  if(splitted[2].match(regexp_domain) == null) 
		  {
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null) return false;
		  }// if
		  return true;
		}
			return false;
	}


var dtCh= "/";
var minYear=1900;
var maxYear=2200;

function isInteger2(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger2(stripCharsInBag(dtStr, dtCh))==false){
		
		return false
	}
return true
}




function isDate2(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger2(stripCharsInBag(dtStr, dtCh))==false){
	
		return false
	}
return true
}

//FOR HIDE AND SHOW 
function toggleSearch(whichLayer)
{
	if (document.getElementById)
	{
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
		
		if(style2.display == "block"){
			style2.display = "none";
		}else{
			style2.display = "block";
		}
	}
}
//COMPARE PASSWORDS FIELDS
function chkPWD(first, second) {
	var el, msg = '';
		if (document.getElementById(first).value == '' || /^\s+$/.test(document.getElementById(first).value)) {
		msg = 'Please enter a password.';
		el = first;
		}
		else if (document.getElementById(second).value == '' || /^\s+$/.test(document.getElementById(second).value)) {
		msg = 'Please re-enter your password.';
		el = second;
		}
		else if (document.getElementById(second).value != document.getElementById(first).value) {
		msg = 'Please ensure that your password & confirmed password are the same.';
		el = second;
		}
		if (msg) {		
		return false;
		}
	return true;
}
function chkEmail(first,second){
	if (document.getElementById(second).value != document.getElementById(first).value) {
		msg = 'Please ensure that your password & confirmed password are the same.';
		alert(msg);
		el = second;
		}
		if (msg) {
		//alert(msg);
		el.focus();
		el.select();
		return false;
		}
}
//Check file extention
    //extArray = new Array(".jpg", ".png", ".bmp"); //example file extentions
    extArray = new Array(".csv");
    
    function limitAttach(file) {
	    allowSubmit = false;
	    file	= file.value;
	    
	    if (!file) return;
		    while (file.indexOf("\\") != -1)
			    file = file.slice(file.indexOf("\\") + 1);
			    ext = file.slice(file.indexOf(".")).toLowerCase();
			    
			    for (var i = 0; i < extArray.length; i++) {
			    	if (extArray[i] == ext) { allowSubmit = true; break;
			    }
		    }
	    if (allowSubmit) return true;
	    else
	    alert("Please only upload files that end in types:  "
	    + (extArray.join("  ")) + "\nPlease select a new "
	    + "file to upload and submit again.");
	    return false;
    }
	/* Add by Sunil*/
	function isFloat(objValue)
		{
				if(objValue.value!="")
				{
					var  strError	="";					
					var charpos = objValue.value.search("[^0-9.]"); 
					// var charpos = is_float(27.25);
					// alert(charpos);
					  if(objValue.value.length > 0 &&  charpos >= 0) 
					  { 
						if(!strError || strError.length ==0) 
						{ 
							return false;
						 // strError = "Only digits allowed "; 
						} 
						
						return false; 
					  }
				}
				return true;
		}
		function chkspace(objValue){

				if(objValue.value!="")
				{
					  var  strError	="";	
					  var charpos = objValue.value.search("[  ]"); 
					  var At=objValue.value.charAt(0);
					
					  if(isNaN(objValue.value.charAt(0))==0)
					  {    
						   if(charpos>0){							 
							  return false;   
						   }else { return true; } 
					  }
					  else if(objValue.value.length > 0 &&  charpos >= 0)  
					  {
							if(!strError || strError.length ==0) 
							{  	
								return false;
								  //strError ="Only alpha-numeric characters allowed !!"; 
							}//if 
							 
							return false; 
					  }
				}



		}
		function TrimSTR(strValue) {
		// REMOVE leading spaces.
		while (true) {
			if (strValue.value.indexOf(" ") == 0) {								// a leading space has been found so...
				strValue.value = strValue.value.substring(1, strValue.value.length)			// slice it off.
			} else {														// the first character in the string is no longer a space so...
			return false;
				// exit the loop.
			}
		}

		// REMOVE trailing spaces.
		if (strValue.value.length > 0) {	// the string is not null.
			while (true) {
				if (strValue.value.lastIndexOf(" ") == strValue.value.length - 1) {			// a trailing space has been found so...
					strValue.value = strValue.value.substring(0, strValue.value.length - 1)	// slice it off.
				} else {													// the last character in the string is no longer a space so...
					return false;													// exit the loop.
				}
			}
		}

	// ASSIGN return value
	return strValue.value
}


function isHTML(val)
{
        if(val.match(/([\<])([^\>]{1,})*([\>])/i)==null)
         return true;
        else
         return false;
}

function error(a_errors)
{
	e_errbox = get_element('divMessageJS');
	s_message = '';
	s_message = '<div align="center" id="error_js" ><div id="instrs">'+JS_BLOCK_ERROR+':</div>';
	for (n_i = 0; n_i < a_errors.length; n_i++){
	s_message += '<div align="center" style="color:red;padding-left:250px !important;font-family:Arial,Helvetica,sans-serif;font-size:13px;text-align:left;">' + a_errors[n_i]['t'] + '</div>';
	}
	s_message += '</div>';
	if (e_errbox && e_errbox.innerHTML != null)
	{
		
		e_errbox.innerHTML =s_message;
		e_errbox.style.display = 'inline';
		window.scrollTo(0,0);
	}
	for (n_i = 0; n_i < a_errors.length; n_i++)
		if (a_errors[n_i]['f'])
		{
			e_caption = get_element(a_errors[n_i]['f']);
			if (!e_caption)
				continue;
			e_caption.className = 'error';
		}
}

/*** STARTS::: FORM LEVEL VALIDATIONS - FUNCTIONS ***/
function clear_errors(frmLabels)
{
	var errorboxes = ['divMessageJS'];
	for (var index = 0; index < errorboxes.length; index++)
	{
		e_errbox = get_element(errorboxes[index]);
		if (!e_errbox)
			continue;
		
		if (e_errbox && e_errbox.innerHTML)
		{
			e_errbox.style.display = 'none';
			e_errbox.innerHTML = '';
		}
	}

	for (var i = 0; i < frmLabels.length; i++)
	{
		e_caption = get_element(frmLabels[i]);
		if (!e_caption)
			continue;
		e_caption.className = 'normal';
	}
}

function report (heading, s_message)
{
	e_msgbox = get_element('divErrMsgJS');
	if (e_msgbox && e_msgbox.innerHTML != null)
	{
		e_msgbox.innerHTML =
		  '<table cellpadding="0" cellspacing="0" border="0" width="100%">'
		+ '<tr><td bgcolor="#CCCC33">'
		+ '<table cellpadding="6" cellspacing="1" border="0" width="100%">'
		+ '<tr><td bgcolor="#FFFFCC" style="font-size: 11.5px; color: green;">'
		+ '<b>' + heading + '</b> <span style="color: black">' + s_message + '</span>'
		+ '</td></tr>'
		+ '</table>'
		+ '</td></tr>'
		+ '<tr><td><img src="/img/pixel.gif" width="1" height="4px" border="0"><br></td></tr>'
		+ '</table>';
		e_msgbox.style.display = 'inline';
	}
}


function get_element (s_id)
{
	return (document.all ? document.all[s_id] : (document.getElementById ? document.getElementById(s_id) : null));
}
// ENDS  : FORM LEVEL VALIDATIONS - FUNCTIONS

// STARTS: following code is to remove the error message which is displayed in the DIV section in .tpl file...
	var secs
	var timerID = null
	var timerRunning = false
	var delay = 1000
	
	function InitializeTimer()
	{
		// Set the length of the timer, in seconds
		secs = 15
		StopTheClock()
		StartTheTimer()
	}
	
	function StopTheClock()
	{
		if(timerRunning)
			clearTimeout(timerID)
		timerRunning = false
	}
	
	function StartTheTimer()
	{
		if (secs==0)
		{
			StopTheClock()
			// Here, we make the DIV:
			document.getElementById("divMessageJS").style.display = 'none';
			document.getElementById("divMessagePHP").style.display = 'none';
		}
		else
		{
	//      self.status = secs
			secs = secs - 1
			timerRunning = true
			timerID = self.setTimeout("StartTheTimer()", delay)
		}
	}
// ENDS  : following code is to remove the error message which is displayed in the DIV section in .tpl file.....



		/**
		* Function		: isValidPhone
		* Created By	: Shyam Thakur
		* Created On	: 3-Mar-2009
		* Description	: This function is for checking valid phone number.
		* @param		: $objValue(string)
		* @access 		: public
		* @return 		: boolean True on success, false on failure
		*/		
		function isValidPhone(objValue)
		{
			var regex = /^(\()?(\d{3})([\)-\. ])?(\d{3})([-\. ])?(\d{4})$/;
			return regex.test(objValue.value);			
		}



		/**
		* Function		: chkValidDob
		* Created By	: Shyam Thakur
		* Created On	: 4-Mar-2009
		* Description	: This function is for checking if date of birth exceeds current date.
		* @param		: inputDate(Date)
		* @access 		: public
		* @return 		: boolean True on success, false on failure
		*/		
		function chkValidDob(inputDate) {
		
			var today=new Date();
			var inputDate 	= inputDate;
			var currentDate = "";
			
			if(today.getMonth()<9)
				currentDate = "0" + (today.getMonth()+1);
			else
				currentDate = (today.getMonth()+1);


			if(today.getDate()<10)
				currentDate += "/0" + today.getDate();
			else
				currentDate += "/" + today.getDate();

				
			currentDate += "/" + today.getFullYear()

			// Set input date
			var inputDate_mm  = parseInt(inputDate.substring(0,2),10);
			var inputDate_dd  = parseInt(inputDate.substring(3,5),10);
			var inputDate_yy  = parseInt(inputDate.substring(6,10),10);
			
			// Set current date
			var currentDate_mm  = parseInt(currentDate.substring(0,2),10);
			var currentDate_dd  = parseInt(currentDate.substring(3,5),10);
			var currentDate_yy  = parseInt(currentDate.substring(6,10),10);
			
			
			var inputDate 	= 	new Date(inputDate_yy, inputDate_mm, inputDate_dd);
			var currentdate = 	new Date(currentDate_yy, currentDate_mm, currentDate_dd);
			
			if(inputDate>currentdate)
				return false;
			else
				return true;

			return true;
			
		}
		
		<!-- This script and many more are available free online at -->
		<!-- The JavaScript Source!! http://javascript.internet.com -->
		<!-- Original:  Torsten Frey (tf@tfrey.de) -->
		<!-- Web Site:  http://www.tfrey.de -->
		
		<!-- Begin
		
		
		/**
		* Function		: check_date
		* Created By	: Shahvez Alam
		* Created On	: 5-Mar-2009
		* Description	: This function is for checking valid date and format it.
		* @param		: field
		* @access 		: public
		* @return 		: boolean True on success, false on failure
		*/		
		
		function check_date(field){
		var checkstr = "0123456789";
		var DateField = field;
		var Datevalue = "";
		var DateTemp = "";
		var seperator = "/";
		var day;
		var month;
		var year;
		var leap = 0;
		var err = 0;
		var i;
		   err = 0;
		   DateValue = DateField.value;
		   /* Delete all chars except 0..9 */
		   for (i = 0; i < DateValue.length; i++) {
			  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
				 DateTemp = DateTemp + DateValue.substr(i,1);
			  }
		   }
		   DateValue = DateTemp;
		   /* Always change date to 8 digits - string*/
		   /* if year is entered as 2-digit / always assume 20xx */
		   if (DateValue.length == 6) {
			  DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
		   if (DateValue.length != 8) {
			  err = 19;}
		   /* year is wrong if year = 0000 */
		   year = DateValue.substr(4,4);
		   if (year == 0) {
			  err = 20;
		   }
		   /* Validation of month*/
		   month = DateValue.substr(0,2);
		   if ((month < 1) || (month > 12)) {
			  err = 21;
		   }
		   /* Validation of day*/
		   day = DateValue.substr(2,2);
		   if (day < 1) {
			 err = 22;
		   }
		   /* Validation leap-year / february / day */
		   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
			  leap = 1;
		   }
		   if ((month == 2) && (leap == 1) && (day > 29)) {
			  err = 23;
		   }
		   if ((month == 2) && (leap != 1) && (day > 28)) {
			  err = 24;
		   }
		   /* Validation of other months */
		   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
			  err = 25;
		   }
		   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
			  err = 26;
		   }
		   /* if 00 ist entered, no error, deleting the entry */
		   if ((day == 0) && (month == 0) && (year == 00)) {
			  err = 0; day = ""; month = ""; year = ""; seperator = "";
		   }
		   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
		   if (err == 0) {
			  DateField.value = month+ seperator + day  + seperator + year;
			  return true;
		   }
		   /* Error-message if err != 0 */
		   else {
			  DateField.value = month+ seperator + day  + seperator + year;
			  return false;
		   }
		}
//  End -->


		/**
		* Function		: chkValidDob
		* Created By	: Shyam Thakur
		* Created On	: 6-Mar-2009
		* Description	: This function is for checking if user is less then 18 years.
		* @param		: inputDate(Date)
		* @access 		: public
		* @return 		: boolean True on success, false on failure
		*/
		function isValidAge(inputDate)
		{
			var today	=	new Date();
			var dtDate = 	new Date(inputDate)
			if (dtDate.getTime() > (today.getTime() - (JS_AGE_LIMIT * 31556926000)))
			{
				return false;
			}
			else
			{
				return true;
			}
		}


		/**
		* Function		: chkValidDob
		* Created By	: Shyam Thakur
		* Created On	: 9-Mar-2009
		* Description	: This function is for checking valid URL.
		* @param		: value(URL)
		* @access 		: public
		* @return 		: boolean True on success, false on failure
		*/
		function checkURL(value) 
		{
			var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
			if(urlregex.test(value))
			{
				return(true);
			}
		  return(false);
		}
		
		/**
		* Function		: checkValidCsv
		* Created By	: Shahvez Alam
		* Created On	: 22-May-2009
		* Description	: This function is for checking valid csv file.
		* @param		: fname(String)
		* @access 		: public
		* @return 		: boolean True on success, false on failure
		' History       :             1.3               - May  22, 2009              - Shahvez Alam
		*/
		
		function checkValidCsv(fname){
			extArray = fname.split('.');
			ext = extArray[extArray.length - 1];
			ext=ext.toLowerCase();
			if(ext!='csv'){
				return false;
			}
			return true;
		}
		
		/**
		* Function		: isValidTaxid
		* Created By	: Madhusudhan
		* Created On	: 11-July-2009
		* Description	: This function is for checking valid taxId.
		* @param		: TaxId(String)
		* @access 		: public
		* @return 		: boolean True on success, false on failure
		*/
		function isValidTaxid(objValue)
		{
			if(objValue.value!="")
			{
				var  strError	="";				
				var charpos = objValue.value.search("[^A-Za-z0-9]"); 
              	if(objValue.value.length > 0 &&  charpos >= 0) 
              	{ 
                  if(!strError || strError.length ==0) 
                { 
                  return false; 
                }//if         
                return false; 
              }//if
				
			}
			return true;
		}
		
		//  function used for check username 
		function checkUsername(username){
				username=username.toUpperCase();
				var position=username.indexOf("REF-");
				if(position==0){
					return true; 
				 }else{
				  return false;	 
			}
		}

 function IsNumeric(sText)
  {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
  for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

  function isAlphabet(elem){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		return false;
	}
}


function isValidTree(elem){
	var alphaExp = /^[a-z A-Z 0-9]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		return false;
	}
}

function isValidReferrercode(objValue){
	if(objValue.value!="")
	{
		var strError = "";				
		var charpos = objValue.value.search("[^A-Za-z0-9\-]"); 
		if(objValue.value.length > 0 &&  charpos >= 0) 
		{ 
		  if(!strError || strError.length ==0) 
		{ 
		  return false; 
		}	
		return false; 
	  }
		
	}
	return true;	
}

//  function used for trim
function trim(str, chars) {

            return ltrim(rtrim(str, chars), chars);

}
function ltrim(str, chars) {

            chars = chars || "\\s";

            return str.replace(new RegExp("^[" + chars + "]+", "g"), "");

}
function rtrim(str, chars) {

            chars = chars || "\\s";

            return str.replace(new RegExp("[" + chars + "]+$", "g"), "");

}

