function validate(form) 
{ 
	var fname = form.txtfname.value;
	var lname = form.txtlname.value;
	var uname = form.username.value;
	var pword = form.txtpass.value;
	var cpass = form.txtcpass.value;
    var dob = form.popup_container.value;
    var email = form.txtmail.value;
	var country = form.selcountry.value;
	var recapcha = form.user_code.value;
    var fnameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var usernameRegex = /^[a-zA-Z0-9_]{6,12}$/;
	//var passwordRegex = /^[a-zA-Z0-9]{6,12}$/;
    var lnameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
    var emailRegex = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
	var passlength = pword.length;

  if(fname == "") 
  {
  	inlineMsg('txtfname','Please enter your firstname.');
    return false;
  }
  if(!fname.match(fnameRegex)) 
  {
    inlineMsg('txtfname','Please enter letters only.');
    return false;
  }

   if(lname == "") 
  {
  	inlineMsg('txtlname','Please enter your lastname.');
    return false;
  }
    if(!lname.match(lnameRegex)) 
  {
    inlineMsg('txtlname','Please enter letters only.');
    return false;
  }

    if((uname == "") || (uname == "username")) 
  {
  	inlineMsg('username','Please enter your username.');
    return false;
  }
  
   if(!uname.match(usernameRegex)) 
  {
    inlineMsg('username','A-Z,a-z," _ ",Minimum 6 and not more than 12 characters are allowed.');
    return false;
  }
      
  if((pword == "") || (passlength < 6) || (passlength > 12) || (pword == "password") )
   {	   
    inlineMsg('txtpass','Please enter your password between 6 to 12 Characters');
    return false;
  }      
  
  if(cpass == "" )
  {	  
	  inlineMsg('txtcpass','Please enter your password');
	  return false;
  }
  if(pword!== cpass)
  {
	  inlineMsg('txtcpass','Password didnt match');
	  return false;
  }
  if(dob == "")
   {
    inlineMsg('popup_container','Please select your date of birth.');
    return false;
  }
  if(email == "")
   {
    inlineMsg('txtmail','Please enter your email.');
    return false;
  }
  if(!email.match(emailRegex)) 
  {
    inlineMsg('txtmail','You have entered an invalid email.');
    return false;
  }
 if(country == 0) 
  {
    inlineMsg('selcountry','Please select your country.');
    return false;
   }
    if(recapcha == "") 
  {
    inlineMsg('user_code','Please enter the key.');
    return false;
  }  	
   return true;
}


function validate_mail(form2) 
{	
  var txtinvite = form2.txtinvitemail.value;
  
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var NoRegex = /^[0-9]*$/;
  var invemailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
 
 
  if(txtinvite == "") {
    inlineMsg('txtinvitemail','Please enter email address.',2);
    return false;
  }
 
 if(txtinvite == "Friends email ID") {
    inlineMsg('txtinvitemail','Please enter email address.',2);
    return false;
  }
  
  if(!txtinvite.match(invemailRegex)) {
    inlineMsg('txtinvitemail','You have entered an invalid email.',2);
    return false;
  }     
  return true;
}

function forgot_pwd(form2) 
{	
  var validate = form2.validate.value;
  
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var NoRegex = /^[0-9]*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
 
 
  if(validate == "") {
	alert("Please enter your email id.");
return false;
  }
 
  if(!validate.match(emailRegex)) {
	alert("Invalid Email Address. Please enter valid email id.",2);
	return false;
  }     
  return true;
}


function validate_search(form1) 
{	
  var txt_search = form1.txtsearch.value;
   
  var friendsearchRegex = /^[a-zA-Z]*$/;
 
  if(txt_search == "Friends name" || txt_search =="") {
    inlineMsg('txtsearch','You must enter your Friend name.',2);
    return false;
  }
  
   if(!txt_search.match(friendsearchRegex)) {
    inlineMsg('txtsearch','Alphabets only allowed.',2);
    return false;
  }
  
  return true;
 
}


function validate_settings(frmchangepwd)
{ 
//alert("hi elci");
   var txtoldpassword = frmchangepwd.txtoldpwd.value;
   var txtnpwd = frmchangepwd.txtnewpwd.value;
   var txtcpwd = frmchangepwd.txtcfmpwd.value;
   
   var oldpasslength = txtoldpassword.length;
   var newpasslength = txtnpwd.length;
   
    if(txtoldpassword == "")
	{
    inlineMsg('txtoldpwd','You must enter your old password.',2);
    return false;
    }
  
   if((txtnpwd == "") || (newpasslength < 6) || (newpasslength > 12) || (txtnpwd == "password") ) {
    inlineMsg('txtnewpwd','You must enter your new password[between 6 to 12 characters].',2);
    return false;
  }
  
  if(txtoldpassword == txtnpwd) {
	inlineMsg('txtnewpwd','Please give a new password',2);
    return false;	  
  }
  
  if(txtcpwd == "") {
    inlineMsg('txtcfmpwd','Re-type your new password.',2);
    return false;
  }
  if(txtnpwd != txtcpwd) {
	inlineMsg('txtcfmpwd','Password doesnot match.',2);
    return false;	  
  }
   return true;	
}

function checkfile(pictures)
{
	 var img = pictures.fileimage.value;	
	 
	if(img == "") {
    inlineMsg('fileimage','You must select any file to upload',2);
    return false;
    }	  
  return true;
}

function checkvideos(frmvideos)
{	
	var video = frmvideos.userfile.value;	 	
	
	if(video == "") {
    inlineMsg('userfile','You must select any file to upload',2);
    return false;
    }	  
  return true;
}

function checkgroup(frmcreategroup)
{	
	var groupname = frmcreategroup.txtgname.value;	
	var groupnameRegex = /^[a-zA-Z_]*$/;
	var grouptype = frmcreategroup.selgtype.value;
	var groupimg = frmcreategroup.filegroup.value;
	
	if(groupname == "" ) {
    inlineMsg('txtgname','You must enter a group name',2);
    return false;
    }	  
	
	if(!groupname.match(groupnameRegex)) 
    {
    inlineMsg('txtgname','Alphabets and " _ " only allowed.',2);
    return false;
    }
  
	if(grouptype == 0) {
    inlineMsg('selgtype','You must select any group type',2);
    return false;
    }	  
	
//	if(groupimg == "") {
//    inlineMsg('filegroup','You must ',2);
//    return false;
//    }	  
	
  return true;
}

function checksearch(frmfrndsearch)
{	
	var friendname = frmfrndsearch.txtfrname.value;	 	
	var frndnameRegex = /^[a-zA-Z]*$/;
	
	if(friendname == "") {
    inlineMsg('txtfrname','You must enter a keyword to search',2);
    return false;
    }
	
	if(!friendname.match(frndnameRegex)) 
    {
    inlineMsg('txtfrname','Alphabets only allowed.',2);
    return false;
    }
	
  return true;
}

function checkgroupsearch(frmgroupsearch)
{	
	var grpsearch = frmgroupsearch.txtgroupsrch.value;	 	
	var grpnameRegex = /^[a-zA-Z]*$/;
	
	if(grpsearch == "") {
    inlineMsg('txtgroupsrch','You must enter a keyword to search',2);
    return false;
    }
	
	/*if(!grpsearch.match(grpnameRegex)) 
    {
    inlineMsg('txtgroupsrch','Alphabets only allowed.',2);
    return false;
    }*/
	
  return true;
}



function adminvalidate(frmadmin) 
{ 
	var fname = frmadmin.txtaduname.value;
//	var lname = frmadmin.txtadusername.value;
	var uname = frmadmin.txtadusername.value;
	var pword = frmadmin.txtadpassword.value;
//	var cpass = frmadmin.txtcpass.value;
//    var dob = frmadmin.popup_container.value;
    var email = frmadmin.txtademail.value;
	var status = frmadmin.selstatus.value;
//	var recapcha = frmadmin.user_code.value;
	
    var fnameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var usernameRegex = /^[a-zA-Z0-9_]{6,12}$/;
	//var passwordRegex = /^[a-zA-Z0-9]{6,12}$/;
    var lnameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
    var emailRegex = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
	var passlength = pword.length;

  if(fname == "") 
  {
  	inlineMsg('txtaduname','Please enter your firstname.');
    return false;
  }
  /*if(!fname.match(fnameRegex)) 
  {
    inlineMsg('txtfname','Please enter letters only.');
    return false;
  }*/

  /* if(lname == "") 
  {
  	inlineMsg('txtlname','Please enter your lastname.');
    return false;
  }
    if(!lname.match(lnameRegex)) 
  {
    inlineMsg('txtlname','Please enter letters only.');
    return false;
  }*/

    if((uname == "") || (uname == "username")) 
  {
  	inlineMsg('txtadusername','Please enter your username.');
    return false;
  }
  
   /*if(!uname.match(usernameRegex)) 
  {
    inlineMsg('username','A-Z,a-z," _ ",Minimum 6 and not more than 12 characters are allowed.');
    return false;
  }*/
      
  if((pword == "") || (passlength < 6) || (passlength > 12) || (pword == "password") )
   {	   
    inlineMsg('txtadpassword','Please enter your password between 6 to 12 Characters');
    return false;
  }      
  
 /* if(cpass == "" )
  {	  
	  inlineMsg('txtcpass','Please enter your password');
	  return false;
  }
  if(pword!== cpass)
  {
	  inlineMsg('txtcpass','Password didnt match');
	  return false;
  }
  if(dob == "")
   {
    inlineMsg('popup_container','Please select your date of birth.');
    return false;
  }*/
  
  if(email == "")
   {
    inlineMsg('txtademail','Please enter your email.');
    return false;
  }
  if(!email.match(emailRegex)) 
  {
    inlineMsg('txtademail','You have entered an invalid email.');
    return false;
  }
  
 if(status == 0) 
  {
    inlineMsg('selstatus','Please select your country.');
    return false;
   }
   
   /* if(recapcha == "") 
  {
    inlineMsg('user_code','Please enter the key.');
    return false;
  }  	*/
   return true;
}

function validate_login(home_login)
{	
	var uname = document.home_login.txtuname.value;	 	
	var password = document.home_login.txtpass_show.value;
	
	if(uname == "" || uname == "username") {
    inlineMsg('txtuname','You must enter username',2);
    return false;
    }
	
	if(password == "" ) { 
    inlineMsg('txtpass_show','You must enter password',2);
    return false;
    }
	
  return true;
}


function validate_scraps(frmscraps)
{
	//alert("scraps");
	var scrap = frmscraps.txt_yaps.value;	 	
		
	if(scrap == "" ) { 
    inlineMsg('txt_yaps','You must specify the scraps for your friends',2);
    return false;
    }
	
  return true;
}








// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(15,100); 
  arrow.src = "images/msg_arrow_red.gif"; 
}



function validateFileExtension(fld) {
	if(!/(doc)$/i.test(fld.value)) {
		alert("Please Upload .doc file format.");
		document.getElementById("resume").value='';
		fld.focus();
		return false;
	}
	return true;
}

