<!-- Start

function textCounter(field, countfield, maxlimit) {

    if (field.value.length > maxlimit) 
    field.value = field.value.substring(0, maxlimit);
    else
    countfield.value = maxlimit - field.value.length;
}
// End -->

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function echeck(str) 
{
        var at="@";
        var dot=".";
        var lat=str.indexOf(at);
        var lstr=str.length;
        var ldot=str.indexOf(dot);
        var error_flag = 0;
        if (str.indexOf(at)==-1)
        {           error_flag = 1;          }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
        {           error_flag = 1;          }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
        {     error_flag = 1;        }

         if (str.indexOf(at,(lat+1))!=-1)
         {            error_flag = 1;              }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
         {            error_flag = 1;              }

         if (str.indexOf(dot,(lat+2))==-1)
         {            error_flag = 1;             }
        
         if (str.indexOf(" ")!=-1)
         {            error_flag = 1;              }
        
        if( error_flag == 1 )
        {
            alert("Invalid Email ...........");
            return false;
        }
        else
          return true;                
    }

function validateEmail(emailID)
{
    //var emailID=document.contact_us_form.contact_us_email_from;    
    if ((emailID.value==null)||(emailID.value==""))
    {
        alert("Please Enter your Email ID. Don't leave it BLANK");
        emailID.focus();
        return false;
    }

    if (echeck(emailID.value)==false)
    {
        emailID.focus();
        return false;
    }
    return true;
}

function validateName(fieldname)
{
    if(fieldname.value.length == 0) 
    {
        return false;
    }
    return true;
}

function validateForm()
{
    var submit_flag = 1;    
    var error = "";
    var user = document.frmpost.uid;
    var pass = document.frmpost.pwd;
    var title = document.frmpost.title;
    var url = document.frmpost.url;
    var email = document.frmpost.email;
    var reciprocal_url = document.frmpost.reciprocal_url;
    var captcha_text = document.frmpost.captcha_text;
    
    if(!validateName(user))
    {
        submit_flag = 0;
        error = "User Name Must not be left blank";
        user.focus();
        alert(error);
        return false;        
    }
    
    if(!validateName(pass))
    {
        submit_flag = 0;
        error = "Password must not be left blank";
        pass.focus();
        alert(error);
        return false;        
    }
    
    if(!validateName(title))
    {
        submit_flag = 0;
        error = "Title must not be left blank";
        title.focus();
        alert(error);
        return false;        
    }
    
    if(!validateName(url))
    {
        submit_flag = 0;
        error = "URL must not be left blank";
        url.focus();
        alert(error);
        return false;        
    }
    
    if(!validateName(email))
    {
        submit_flag = 0;
        error = "Email must not be left blank";
        email.focus();
        alert(error);
        return false;        
    }
    
    if(!validateEmail(email))
    {
        submit_flag = 0;
        error = "Email ID must be in proper format.";
        email.focus();
        alert(error);
        return false;        
    }
    
    if(!validateName(captcha_text))
    {
        submit_flag = 0;
        error = "Image Verification Field must not be left blank";
        captcha_text.focus();
        alert(error);
        return false;        
    }
    
// ---------------------------------
    if ((submit_flag == 1)
    {
        if(confirm("Are you sure to submit these data, then press OK ? If not, press CANCEL :"+"\r\n"))
        {
            document.frmpost.submit();
            return true;
        }
        else
            return false;
    }
    else
        return false;
}
 
function test(k)
{
	var val = k.value;
	var regx =  /^[0-9][0-9]*$/;
    var flg = false;
	if(regx.test(val))
	{
		k.style.backgroundColor = "";
		flg = true;
	}
	else
	{
		alert("You have entered : "+ val +"\r\nOnly numeric digits 0 to 9 are allowed here...");
		k.value = "0";
        k.style.backgroundColor = "#41ACE0";
		flg = true;
	}
    if(flg == true)
        return true;
    else
        return false;	
}

function set_focus()
{
	document.frmpost.uid.focus();
	return true;
}