// JavaScript Document
// 	Usage <script type="text/javascript" src="<?php echo $config['site_url']; ?>js/validation.js">
// 	Usage <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/validation.js">
//	<form action="" name="newsletter" method="post" enctype="multipart/form-data" onsubmit="return validate_form(this);">
// 	title="NameRequired::Please enter Name."
//	title="EmailRequired::Please enter Email."
//	title="Mandatory::Please enter Comment."
function Global_validate(obj)
  {
    var len=obj.length;
	for(i=0;i<len;i++)
	  {
	    if(obj.elements[i].title!='' && obj.elements[i].value=='' && obj.elements[i].disabled==false)
		  {
		    alert(obj.elements[i].title);
			obj.elements[i].focus();
			return false;
		  }
	  }
	return true;
  }

  function trimspaces(str)
	{
		while((str.indexOf(' ',0) == 0) && (str.length > 1))
		{
			str = str.substring(1, str.length);
		}
		while((str.lastIndexOf(' ') == (str.length - 1) && (str.length > 1)))
		{
			str = str.substring(0,(str.length - 1));
		}
		if((str.indexOf(' ',0) == 0) && (str.length == 1)) str = '';
		return str;
	}
		
function check_name(value) {
  return value.match( /^[A-Za-z][A-Za-z0-9 ]*/ );
}		
	function validate_form(Obj)
		{
var blots=new Array();
var blots=new Array("cryM5K","78cn","4J2MMM","Gpp6A","2F6Asd","2LHX","pZrFTM","72nK6H","6FJF","WreF","eGAKT3","cz42LA","X7TBJ3","rX67u","Xs4J2p","MV4W","V8uJ","yG5Ty","YYKBA5","r7G8","8Y27P6G7","ZW7Y28V9","PEDXLE3G","GAB4MZ92","N6MRAWUE","KTnXA","AACZ","Gcc786","Vc8KA","cryM5K");	
				
				for ( i = 0; i < Obj.elements.length; i++) 
				{
					formElem = Obj.elements[i];
					//alert(formElem.type);
					//alert(formElem.value);
					
					switch (formElem.type) {
								case 'text':
								case 'password':
								case 'select-one':
								case 'textarea':
								case 'file':
								case 'checkbox':
								case 'radio':
								case 'select-multiple':
										
								split_title=formElem.title.split("::");
										//alert(split_title[0]+"="+formElem.value);
										
						// validations by vaseem starts
										
								// field must not left blank, validation for blank field/text box
										if(split_title[0]=='Mandatory' && trimspaces(formElem.value)=='')
										{
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										
								// Required : Email validation function
										if(split_title[0]=='EmailRequired' )
										{		
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(formElem.value))
											{}
											else{
												alert('Invalid E-mail Address, Please re-enter correct E-mail.');
												formElem.focus();
												return false;
												}
										}
								///////// Date Validations  
								
								if(split_title[0]=='currentdate')
                                    {
										if(trimspaces(formElem.value)!='')
										{
											 //Total time for one day
                                            var one_day=1000*60*60*24;
                                            var currentTime = new Date();
                                            var month = currentTime.getMonth() + 1;
                                            var day = currentTime.getDate();
                                            var year = currentTime.getFullYear();

                                            var date1 = day + "/" + month + "/" + year;
                                            var date2 = formElem.value;

                                            var x=date1.split("/");
                                            var y=date2.split("/");
                                            //date format(date,month,Fullyear)

                                            var date1=new Date(x[0],(x[1]-1),x[2]);

                                            var date2=new Date(y[0],(y[1]-1),y[2]);

                                            var month1=x[1]-1;
                                            var month2=y[1]-1;

                                            //Calculate difference between the two dates, and convert to days

                                            var diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day));
                                            //_Diff gives the diffrence between the two dates.

                                            if(diff<0)
                                            {
                                                alert("Please select either today\'s or future date ");
                                                formElem.focus();
                                                return false;
                                            }

										}	
                                      	/*else
                                        {
                                            //Total time for one day
                                            var one_day=1000*60*60*24;
                                            var currentTime = new Date();
                                            var month = currentTime.getMonth() + 1;
                                            var day = currentTime.getDate();
                                            var year = currentTime.getFullYear();

                                            var date1 = day + "/" + month + "/" + year;
                                            var date2 = formElem.value;

                                            var x=date1.split("/");
                                            var y=date2.split("/");
                                            //date format(date,month,Fullyear)

                                            var date1=new Date(x[0],(x[1]-1),x[2]);

                                            var date2=new Date(y[0],(y[1]-1),y[2]);

                                            var month1=x[1]-1;
                                            var month2=y[1]-1;

                                            //Calculate difference between the two dates, and convert to days

                                            var diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day));
                                            //_Diff gives the diffrence between the two dates.

                                            if(diff<0)
                                            {
                                                alert("Please select date greater or equal to date!");
                                                formElem.focus();
                                                return false;
                                            }
                                        }*/
                                    } 
								
								
								//	Not Required : Email validation function
								
									if(split_title[0]=='Email'  && trimspaces(formElem.value)!='')
									{		
										if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(formElem.value))
										{}
										else{
											alert('Invalid E-mail Address, Please re-enter correct E-mail.');
											formElem.focus();
											return false;
											}
									}
								
								// UserName vaseemansari1984
										if(split_title[0]=='UserNameRequired' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='UserNameRequired')
										{
											if (/^[a-zA-Z0-9']+$/.test(formElem.value))		// spaces are not allowed
											{}
											else
											{
												alert('Username should contain only Alpha Numeric(Characters+Numbers) values.');
												formElem.focus();
												return false;
											}
										}
										
								
								
								//  Required : Name validation like Vaseem's Ansari 
										if(split_title[0]=='NameRequired' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='NameRequired')
										{
											if (/^[a-zA-Z ']+$/.test(formElem.value))		// spaces can also come 
											{}
											else
											{
												alert('Name should contain only Characters.');
												formElem.focus();
												return false;
											}
										}
										
										//  Name validation like Vaseem's Ansari 
										if(split_title[0]=='Name'  && trimspaces(formElem.value)!='')
										{
											if (/^[a-zA-Z ']+$/.test(formElem.value))		// spaces can also come 
											{}
											else
											{
												alert('Name should contain only Characters.');
												formElem.focus();
												return false;
											}
										}
								//validation for the name for accept only character
										
										
										if(split_title[0]=='NameSpl' && trimspaces(formElem.value)=='') {
										alert(split_title[1]);
										  formElem.focus();
										    return false;
										}
									if(split_title[0]=='NameSpl' )
										{
											if(formElem.value !='')
											{
													var strLength = formElem.value.length;
													//var iChars = "!@$%^&*()+=-[]\\\';,/{}|\":<>?~_"; 
													var iChars = "!@$%^&*()+=[]\\\;/{}|\":<>?~_"; 
													for (var j = 0; j < strLength; j++) 
													{
														
														
														if (iChars.indexOf(formElem.value.charAt(j)) != -1) 
														{
															alert ("Special characters not allowed in name.");
															formElem.focus();
															return false;
														}
													}	
											}
											if(!check_name(formElem.value))
											{
												alert("Invalid entry! Please re-enter name.");
												formElem.focus();
												return false;
											}
											
										}
										
										// end validation for name
										
								
								//  Pincode Validation 		
								
								if(split_title[0]=='Pincode')
								{
									if(trimspaces(formElem.value)=='')
									{
										alert(split_title[1]);
										formElem.focus();
										return false;
									}
									else
									{
										if (/^[0-9]+$/.test(formElem.value)){
										}else{
											alert('Pincode can contain only Numeric Values.');
											formElem.focus();
											return false;
										}
									}
								}
										
								// Required : Phone no (+ - . allowed)	validation in this format +91-230.123.123
									var phoneid =/^[\+]?[0-9(\-)?(\.)?]+$/;
										if(split_title[0]=='PhoneNoMandatory' && trimspaces(formElem.value)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='PhoneNoMandatory' && trimspaces(formElem.value)!='')
										{
											if(phoneid.exec(formElem.value))
												{
													
												}
											else{
												alert("Please enter valid Phone No!");
												formElem.focus();
												return false;
												}
										}
								
								// Phone no (+ - . allowed)	validation in this format +91-230.123.123
								var phoneid =/^[\+]?[0-9(\-)?(\.)?]+$/;
									if(split_title[0]=='PhoneNo' && trimspaces(formElem.value)!='')
									{
										if(phoneid.exec(formElem.value))
											{
												
											}
										else{
											alert("Please enter valid Phone No!");
											formElem.focus();
											return false;
											}
											
									}
									
								// Phone no validation in this format 123-456-1234	
									if(split_title[0]=='PhoneNoFormat' ){
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if (/^\d{3}-\d{3}-\d{4}$/.test(formElem.value)){
												}else{
													alert('Please enter valid phone number.');
													formElem.focus();
													return false;
											}
										}
										
								// Mobile no validation in this format 0 to 9 - and it should be 6 to 20 chracters long
								
									if(split_title[0]=='Mobile')
										{
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if (/^[0-9\-]{6,20}$/.test(formElem.value)){
												}else{
												alert('Please enter valid mobile no.');
												formElem.focus();
												return false;	
											}
										}
										if(split_title[0]=='notreqMobile' && trimspaces(formElem.value)!='')
										{
											if (/^[0-9\-]{6,20}$/.test(formElem.value)){
												}else{
												alert('Please enter valid mobile number.');
												formElem.focus();
												return false;	
											}
										}
										
								// field must have numeric value
										if(split_title[0]=='MandatoryNumeric' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false; 
										}
										if(split_title[0]=='MandatoryNumeric'  && isNaN(formElem.value)){
										alert('Please enter Numeric value.');
										formElem.focus();
										return false;
										}
										if(split_title[0]=='MandatoryNumeric'  && formElem.value!="")
										{
											if (/\./.test(formElem.value)) 
											{
												alert('Decimal values are not allowed');
												 formElem.focus();
												 return false;		
											}
										}
										if(split_title[0]=='MandatoryNumeric'  && parseInt(formElem.value)<=0)
										{
										alert('Please enter positive value grater than zero');
										formElem.focus();
										return false;
										}
										
							// validation for image file that is mandatory field, browse button must have valid image files in it.
										if(split_title[0]=='ImageFileMandatory' && trimspaces(formElem.value)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										
										if(split_title[0]=='ImageFileMandatory' && trimspaces(formElem.value)!='')
										{
											if(trimspaces(formElem.value)!='')
											{
												if (/(.jpg|.jpeg|.gif|.png|.JPG|.JPEG|.GIF|.PNG)$/.test(formElem.value))
												{}
												else
												{
													alert("Please select image in valid format [.jpg, .jpeg, .gif, .png].");
													formElem.focus();
													return false;
												}
											}
										}
										
									// validation for image file that is mandatory field, browse button must have valid image files in it.
										if(split_title[0]=='resumeFileMandatory' && trimspaces(formElem.value)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										
										if(split_title[0]=='resumeFileMandatory' && trimspaces(formElem.value)!='')
										{
											if(trimspaces(formElem.value)!='')
											{
												if (/(.pdf|.doc|.docx|.PDF|.DOC|.DOCX)$/.test(formElem.value))
												{}
												else
												{
													alert("Please select file in valid format [.pdf, .doc, .docx].");
													formElem.focus();
													return false;
												}
											}
										}
											
										
										
							// validation for image file that is not a mandatory field but browse button must have valid image files in it.
										if(split_title[0]=='ImageFileNM' && trimspaces(formElem.value)!='')
										{
											if(trimspaces(formElem.value)!='')
											{
												if (/(.jpg|.jpeg|.gif|.png|.JPG|.JPEG|.GIF|.PNG)$/.test(formElem.value))
												{}
												else
												{
													alert("Please select image in valid format [.jpg, .jpeg, .gif, .png].");
													formElem.focus();
													return false;
												}
											}
										}
										
								// validation for tiny editor
										if(split_title[0]=='TinyDesc')
										{
											 tinyMCE.triggerSave(true,true);
  											  var mytextarea = tinyMCE.getContent();
											  if(mytextarea==''){
												alert(split_title[1]);
												formElem.focus();
												return false;	
											  }
											  /*if(mytextarea.length>280)
											  {
												  alert("Your maximum limit of character exceeds from "+split_title[2]);
													return false;	
											  }*/
										}
										
								// validation for pdf file in browse button
										if(split_title[0]=='PdfFile' && trimspaces(formElem.value)!='')
										{
											var img_file2=formElem.value;
											if(img_file2.lastIndexOf(".pdf")==-1 && img_file2.lastIndexOf(".PDF")) {
  								 			alert("Please upload pdf file only.");
 								  			return false;
											}
										}
									
								// valid website url in correct format	www.facebook.com or http://www.facebook.com
										if(split_title[0]=='CorrectUrl' && trimspaces(formElem.value)!='')
										{
											var urlvalidation= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
											if(!urlvalidation.test(formElem.value.toLowerCase()))
											{
												alert('Url should be in valid format');
												formElem.focus();
												return false;
											}
										}
										
										
								// valid website url in correct format Required field
										if(split_title[0]=='ValidUrlRequired' && trimspaces(formElem.value)=='')
										{
												alert(split_title[1]);
												formElem.focus();
												return false;
										}
										
										
										if(split_title[0]=='ValidUrlRequired' && trimspaces(formElem.value)!='' )
										{
			// for url like http://www.facebook.com/
			//var	urlvalidation=/^(http:\/\/)+[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)\/$/;
			
			// for url like http://www.facebook.com/ansari.vaseem
			//var urlvalidation= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
			
			// Change by suman
			var urlvalidation= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2,8}/;
											if(!urlvalidation.test(formElem.value.toLowerCase()))
											{
												alert('Url should be in valid format');
												formElem.focus();
												return false;
											}
										}
										
	
								// valid website url in correct format non mandatory will accept only http://www.facebook.com
										if(split_title[0]=='ValidUrlNM' && trimspaces(formElem.value)!='')
										{
										var	urlvalidation=/^(http:\/\/)+[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)$/;
											if(!urlvalidation.test(formElem.value.toLowerCase()))
											{
												alert('URL should be in valid format \n(http://www.google.com)');
												formElem.focus();
												return false;
											}
										}
								
								
								// password and confirm password
										if(split_title[0]=='Password' && trimspaces(formElem.value)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='Password' )
										{
											if(formElem.value !='')
											{
												var strLength = formElem.value.length;
												var spaceindex = formElem.value.lastIndexOf(' ');
												if(strLength < 6)
												{
													alert("Please enter Password of at least 6 characters.");
													formElem.focus();
													return false;
												}
												if(spaceindex!='-1')
												{
													alert("Please remove space(s) from Password.");
													formElem.focus();
													return false;
												}
												else
												{
													var passwordVal=formElem.value;
												}
											}
										}
										
										if(split_title[0]=='ConfirmPassword' )
										{	//alert('test');
											if(trimspaces(formElem.value)!='')
											{
												var confirmPasswordVal=formElem.value; 
												if(passwordVal!=confirmPasswordVal)
												{
													alert("Password and Confirm password does not match.");
													return false;
												}
											}
											else 
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
										}
										
							// validation when user change his password, then we will check old password != new password 
										if(split_title[0]=='OldPassword' && trimspaces(formElem.value)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='OldPassword' ){
											if(formElem.value !='')
											{
												var strLength = formElem.value.length;
												var spaceindex = formElem.value.lastIndexOf(' ');
												if(strLength < 6)
												{
													alert("Please enter Old Password of at least 6 characters.");
													formElem.focus();
													return false;
												}
												if(spaceindex!='-1')
												{
													alert("Please remove space from Old Password.");
													formElem.focus();
													return false;
												}
												else
												{
													var OldPasswordVal=formElem.value;
												}
											}
										}
										
										if(split_title[0]=='NewPassword' && trimspaces(formElem.value)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='NewPassword' )
										{
											if(formElem.value !='')
											{
												var strLength = formElem.value.length;
												var spaceindex = formElem.value.lastIndexOf(' ');
												if(strLength < 6)
												{
													alert("Please enter New Password of at least 6 characters.");
													formElem.focus();
													return false;
												}
												if(spaceindex!='-1')
												{
													alert("Please remove space from New Password.");
													formElem.focus();
													return false;
												}
												// check if new password is same as old password
												var NewPasswordVal=formElem.value; 
												if(NewPasswordVal==OldPasswordVal)
												{
													alert("Old Password and New password can not be same.");
													return false;
												}
											}
										}
										
										
										if(split_title[0]=='ConfirmNewPassword' && trimspaces(formElem.value)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='ConfirmNewPassword' )
										{
											if(formElem.value !='')
											{
												var strLength = formElem.value.length;
												var spaceindex = formElem.value.lastIndexOf(' ');
												if(strLength < 6)
												{
													alert("Please enter Confirm Password of at least 6 characters.");
													formElem.focus();
													return false;
												}
												if(spaceindex!='-1')
												{
													alert("Please remove space from Confirm Password.");
													formElem.focus();
													return false;
												}
												// check if new password and confirm new password are same or not
												var ConfirmNewPasswordVal=formElem.value; 
												if(NewPasswordVal!=ConfirmNewPasswordVal)
												{
													alert("New Password and Confirm Password does not match.");
													return false;
												}
											}
										}
										
									
								// Radio button checked checking Mandatory, if there are multiple checkbox 
								// <input name="power" id="power" type="radio" title="RadioM::Please check Power." value="Yes" />
								var rdok='n';
									if(split_title[0]=='RadioM' && formElem.type=='radio')
									{
										var rdlen = Obj.elements[formElem.name].length; 
										for (var j=0; j <rdlen; j++) 
										{
											if(Obj.elements[formElem.name][j].checked) 
											{
												rdok='y';
												break;
												//return true;
											}
										}
										if(rdok=='n')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;	
										}
									}
									var chkok='n';
									if(split_title[0]=='checkbxchk' && formElem.type=='checkbox')
									{
										
										var totchk=Obj.elements[formElem.name].length;
										for (m=0; m < totchk; m++) 
										{
											if(Obj.elements[formElem.name][m].type == 'checkbox')
											{
												if(Obj.elements[formElem.name][m].checked) 
												{
													chkok='y';
													break;
													//return true;
												}	
											}
										}
										if(chkok=='n')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;	
										}
									}
										
										
								// validation for imei code of 16 digit, this function can be used for string length validatoin with proper chracters
										if(split_title[0]=='IMEI' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='IMEI' ){
											if(formElem.value !='')
												{
														if (/\./.test(formElem.value)) 
														{
															alert('Invalid formate for IMEI code.');
															 formElem.focus();
															 return false;		
														}
														
														if (/\-/.test(formElem.value)) 
														{
															alert('Invalid formate for IMEI code.');
															 formElem.focus();
															 return false;		
														}
											
													var strLength = formElem.value.length;
													var spaceindex = formElem.value.lastIndexOf(' ');
													if(strLength != 16)
													{
														alert("Please enter 16 digit IMEI code.");
														formElem.focus();
														return false;
													}
													if(spaceindex!='-1')
													{
														alert("Please remove space from IMEI code.");
														formElem.focus();
														return false;
													}
												}
										}
										
								// Not Mandatory - validation for price should be greater than 0
									if(split_title[0]=='Price'  && trimspaces(formElem.value)!='')
									{
										if(split_title[0]=='Price'  && parseInt(formElem.value)<0)
										{
											alert('Please enter positive value for Price.');
											formElem.focus();
											return false;
										}
										if(isNaN(formElem.value))
										{
											alert('Please enter numeric value for Price.');
											formElem.focus();
											return false;
										}
									}
								
										
						// validations by vaseem ends
						
						
										
									
										
										if(split_title[0]=='chkphone' && trimspaces(formElem.value)!='')
										{
											for (k = 0; k < formElem.value.length; k++)
											{   
												// Check that current character is number.
												var c = formElem.value.charAt(k);
												
												if (((c < "0") || (c > "9"))) 
												{
													alert('Please enter valid phone number.');
													formElem.focus();
													return false;
												}	
											}	
										}
										
										if(split_title[0]=='mandatorychkphone')
										{
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;	
											}
											
											for (j=0; j<formElem.value.length;j++)
											{
													// Check that current character is number.
												var c = formElem.value.charAt(j);
												
												if (((c < "0") || (c > "9"))) 
												{
													alert('Please enter valid phone number.');
													formElem.focus();
													return false;
												}	
											}
										}
										
										
								
										
										
									
										
					
										
									
										if(split_title[0]=='numriconly')
										{
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;	
											}
											
											for (s=0; s<formElem.value.length;s++)
											{
													// Check that current character is number.
												var p = formElem.value.charAt(s);
												
												if (((p < "0") || (p > "9"))) 
												{
													alert('Please enter valid number.');
													formElem.focus();
													return false;
												}	
											}
										}
										
								
										
										}
		
				}//end of for loop
				return true;
		}  
		
		
/* usage onKeyUp="validation4number(this,'notnumbers')"	(- symbol is allowed)
if required use this in page only */

var r2={ 'notnumbers':/[^\d\-]/g}		
function validation4number(o,w)
{
  o.value = o.value.replace(r2[w],'');
}


// Value greater that 0 (not .decimal allowed)		// function to validate typed chracters must be only numeric
var r3={ 'notnumbers':/[^\d]/g}
function validation4numeric(o,w)
{
  o.value = o.value.replace(r3[w],'');
}

// it counts the no of chracters typed in textarea and show it below the textarea in input box
// Usage

/*<textarea name="txtDescription" id="txtDescription" cols="50"  title="Content::Please enter Description." rows="6" 
onKeyDown="textCounter(document.frm_name.txtDescription,document.frm_name.remLen,280)"
onKeyUp="textCounter(document.frm_name.txtDescription,document.frm_name.remLen,280)"><?php echo $productDescription; ?></textarea>
<br />
<input readonly type="text" name="remLen" size="3" maxlength="3" value="280">
(Max Character: 280)
<script language="javascript">
textCounter(document.frm_name.txtDescription,document.frm_name.remLen,280);
</script>*/
                  

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}
