// form validation function //
function validateBuyer(form) {

        
	var firstName=form.firstName.value;
	var lastName=form.lastName.value;
	var userAddress=form.userAddress.value;
    var userCountry=form.userCountry.value;
	var userTowns=form.userTowns.value;
	var userCity=form.userCity.value;
	var userPostal=form.userPostal.value;
	var userTelephone=form.userTelephone.value;
	var userName=form.userName.value;
	var userPass=form.userPass.value;
    var userConpass=form.userConpass.value;
    var userEmail=form.userEmail.value;
    var userConmail=form.userConmail.value;
	var chkTerm=form.chkTerm.checked;
  
if(firstName=="")
	{
		inlineMsg('firstName','You must enter the First Name.',2);
		return false;
	}
if(lastName=="")
	{
		inlineMsg('lastName','You must enter the Last Name.',2);
		return false;
	}
if(userAddress=="")

    {
	inlineMsg('userAddress','You must enter the street address.',2);
     return false;	
	}
	if(userCountry=="")

     {
	inlineMsg('userCountry','You must select  country.',2);
     return false;	
	 }
	 if(userTowns=="")

     {
	inlineMsg('userTowns','You must select  state.',2);
     return false;	
	 }
	 
	if(userCity=="")

     {
	inlineMsg('userCity','You must enter city.',2);
     return false;	
	 }
	 if(userPostal=="")
	{
	inlineMsg('userPostal','You must enter zip.',2);
     return false;	
	 }
	 
	if(isNaN(userPostal))
	{
	inlineMsg('userPostal','You must enter valid zip.',2);
     return false;	
	 }
	
	
	if(userTelephone=="")

     {
	inlineMsg('userTelephone','You must enter telephone.',2);
     return false;	
	 }
	
	if(isNaN(userTelephone))
     {
	inlineMsg('userTelephone','You must enter valid telephone.',2);
     return false;	
	 }
	 
     if(userName=="")
	  {
		inlineMsg('userName','You must enter the User Name.',2);
		return false;
	 }
	   else if(userName.length <6)
	 {
		inlineMsg('userName','Please enter 6 characters.',2);
		return false;
	}
	
	if(userPass=="")
	{
		inlineMsg('userPass','You must enter the Password.',2);
		return false;
	}
	
	else if(userPass.length <6){
		inlineMsg('userPass','Please enter 6 characters.',2);
		return false;
	} 
	
	

if(userConpass=="")
	{
		inlineMsg('userConpass','You must enter the Retype Password.',2);
		return false;
	}
if(userPass!=userConpass)
   {
	    inlineMsg('userConpass','Password are not same .',2);
		return false;
	   
   }	
   
if(userEmail=="")
	{
		inlineMsg('userEmail','You must enter the Email Id.',2);
		return false;
	}else if((userEmail.indexOf('@') <= 0) || ((userEmail.charAt(userEmail.length-4) != '.') && (userEmail.charAt(userEmail.length-3) != '.')))
	{
		inlineMsg('userEmail','Please enter the valid E-mail Id.',2);
		return false;
	}
	
	 if(userConmail=="")

     {
	 inlineMsg('userConmail','You must enter retype email.',2);
     return false;	
	 }
	if(userEmail!=userConmail)
   {
	    inlineMsg('userConmail','Email and Re-Enter email  are not same .',2);
		return false;
	   
   }	
	
	if(chkTerm=="")
   {
	    inlineMsg('chkTerm','Please select checkbox .',2);
		return false;
	   
   }	

}
/////////////////////////////////////////////

/*mange edit account*/

function validate_editBuyer(form) {

        
	var firstName=form.firstName.value;

	var lastName=form.lastName.value;
	var userAddress=form.userAddress.value;
    var userCountry=form.userCountry.value;
	var userCity=form.userCity.value;
	var userPostal=form.userPostal.value;
	var userTelephone=form.userTelephone.value;
	/*var userName=form.userName.value;
	var userPass=form.userPass.value;
    var userConpass=form.userConpass.value;
    var userEmail=form.userEmail.value;
    var userConmail=form.userConmail.value;
	var chkTerm=form.chkTerm.checked;*/
  
if(firstName=="")
	{
		inlineMsg('firstName','You must enter the First Name.',2);
		return false;
	}
if(lastName=="")
	{
		inlineMsg('lastName','You must enter the Last Name.',2);
		return false;
	}
if(userAddress=="")

    {
	inlineMsg('userAddress','You must enter the street address.',2);
     return false;	
	}
	if(userCountry=="")

     {
	inlineMsg('userCountry','You must select  country.',2);
     return false;	
	 }
	if(userCity=="")

     {
	inlineMsg('userCity','You must enter city.',2);
     return false;	
	 }
	if(userPostal=="")

     {
	inlineMsg('userPostal','You must enter zip.',2);
     return false;	
	 }
	
	
	if(userTelephone=="")

     {
	inlineMsg('userTelephone','You must enter telephone.',2);
     return false;	
	 }


}


//////////////////////////////////////////////


/*Forgot password */
function forgotValid(form) {

   var forgotEmail=form.forgotEmail.value;
   
   if(forgotEmail=="")
	{
		inlineMsg('forgotEmail','You must enter the Email Id.',2);
		return false;
	}else if((forgotEmail.indexOf('@') <= 0) || ((forgotEmail.charAt(forgotEmail.length-4) != '.') && (forgotEmail.charAt(forgotEmail.length-3) != '.')))
	{
		inlineMsg('forgotEmail','Please enter the valid E-mail Id.',2);
		return false;
	}
	
}
/*loging User*/

function loginValid() {
   
   if(document.loginName.userNames.value=="")
	{
		inlineMsg('userNames','Please enter the user name.',2);
		return false;
	}
   if(document.loginName.userPasss.value=="")
	{
		inlineMsg('userPasss','Please enter the password.',2);
		return false;
	}
}


/*Advertisement of the user*/

function advertiseValid(form) {

    var yourName	=	form.yourName.value;
    var compName	=	form.compName.value;
    var busiSec 	=	form.busiSec.value;
    var yourEmail	=	form.yourEmail.value;
	var yourContact =	form.yourContact.value;
    var yourTime	=	form.yourTime.value;
	var yourComments=	form.yourComments.value;
	
	if(yourName=="")
	{
		inlineMsg('yourName','You must enter the Your Name.',2);
		return false;
	} 
	if(compName=="")
	{
		inlineMsg('compName','You must enter the Company Name.',2);
		return false;
	} 
	if(busiSec=="")
	{
		inlineMsg('busiSec','You must enter the Business Sector.',2);
		return false;
	} 
	
   if(yourEmail=="")
	{
		inlineMsg('yourEmail','You must enter the Email Id.',2);
		return false;
	}else if((yourEmail.indexOf('@') <= 0) || ((yourEmail.charAt(yourEmail.length-4) != '.') && (yourEmail.charAt(yourEmail.length-3) != '.')))
	{
		inlineMsg('yourEmail','Please enter the valid E-mail Id.',2);
		return false;
	}

	if(yourContact=="")
	{
		inlineMsg('yourContact','You must enter the Contact Number.',2);
		return false;
	} 
	
	if(yourTime=="")
	{
		inlineMsg('yourTime','Please select the preferred time to call.',2);
		return false;
	} 
	
	if(yourComments=="")
	{
		inlineMsg('yourComments','You must enter the Comments.',2);
		return false;
	} 
	
	
}
/////////////////////////////
/*Client Contact Details*/
function contactValid(form) {

    var conName		=	form.conName.value;
    var conEmail	=	form.conEmail.value;
    var conInquiry 	=	form.conInquiry.value;
    var conHelp		=	form.conHelp.value;
	
	
	if(conName=="")
	{
		inlineMsg('conName','You must enter  your contact name.',2);
		return false;
	} 
	 if(conEmail=="")
	{
		inlineMsg('conEmail','You must enter the Email Id.',2);
		return false;
	}else if((conEmail.indexOf('@') <= 0) || ((conEmail.charAt(conEmail.length-4) != '.') && (conEmail.charAt(conEmail.length-3) != '.')))
	{
		inlineMsg('conEmail','Please enter the valid E-mail Id.',2);
		return false;
	}
	
	
	if(conInquiry=="")
	{
		inlineMsg('conInquiry','You must enter the Inquiry regarding.',2);
		return false;
	} 
	if(conHelp=="")
	{
		inlineMsg('conHelp','You must enter the How can we help you?.',2);
		return false;
	} 
	
}
///////////////////////////////
/*Client Contact Details*/
function feddbackValid(form) {

    var feedName		=	form.feedName.value;
    var feedComments	=	form.feedComments.value;
	
	if(feedName=="")
	{
		inlineMsg('feedName','You must enter  your name.',2);
		return false;
	} 
	 if(feedComments=="")
	{
		inlineMsg('feedComments','You must enter the comments.',2);
		return false;
	}
	
}
/*postProject_valid*/
function feddpostJob(form) {

     var pro_title		=	form.pro_title.value;
     var pro_cat		=	form.pro_cat.value;
	 var subcid			=	form.subcid.value;
	 var PPdescript		=	form.PPdescript.value;
	
	if(pro_title=="")
	{
		//alert(pro_title);
		inlineMsg('pro_title','You must enter the job title.',2);
		return false;
	} 
	if(pro_cat=="")
	{
		//alert(pro_title);
		inlineMsg('pro_cat','You must select the category.',2);
		return false;
	} 
	if(subcid=="")
	{
		//alert(pro_title);
		inlineMsg('subcid','You must select the subcategory.',2);
		return false;
	} 
	
	if(PPdescript=="")
	{
		//alert(pro_title);
		inlineMsg('PPdescript','You must enter the project description.',2);
		return false;
	} 
}
////////////////////////////////////
/*Provider Valid*/
function providerValid(form) 
{
     var userName		=	form.userName.value;
     var passWord		=	form.passWord.value;
	 var repassWord		=	form.repassWord.value;
	 
	 var companyName	=	form.companyName.value;
     var firstName		=	form.firstName.value;
	 var lastName		=	form.lastName.value;
	 
	 var userEmail		=	form.userEmail.value;
     var phoneNumber	=	form.phoneNumber.value;
	 var address1		=	form.address1.value;
	 
	 var address2		=	form.address2.value;
     var city			=	form.city.value;
	 var country		=	form.country.value;
	 var userTowns		=	form.userTowns.value;
	 var zipCode		=	form.zipCode.value;
	 var chkTerm		=	form.chkTerm.checked;
	 
	if(userName=="")
	{
		//alert(pro_title);
		inlineMsg('userName','You must enter the user name.',2);
		return false;
	} 
	else if(userName.length <6)
	 {
		inlineMsg('userName','Please enter 6 characters.',2);
		return false;
	}
	
	
	
	if(passWord=="")
	{
		//alert(pro_title);
		inlineMsg('passWord','You must enter the password.',2);
		return false;
	} else if(passWord.length <6)
	 {
		inlineMsg('passWord','Please enter 6 characters.',2);
		return false;
	} 
	
	if(repassWord=="")
	{
		//alert(pro_title);
		inlineMsg('repassWord','You must enter the retype password.',2);
		return false;
	} 
	
	if(passWord!=repassWord)
   {
	    inlineMsg('repassWord','Password are not same .',2);
		return false;
	   
   }
	
	if(companyName=="")
	{
		//alert(pro_title);
		inlineMsg('companyName','You must enter the company name.',2);
		return false;
	} 
	
	if(firstName=="")
	{
		//alert(pro_title);
		inlineMsg('firstName','You must enter the first name.',2);
		return false;
	} 
	
	
	if(lastName=="")
	{
		//alert(pro_title);
		inlineMsg('lastName','You must enter the last name.',2);
		return false;
	} 
	
	if(userEmail=="")
	{
		//alert(pro_title);
		inlineMsg('userEmail','You must enter the email id.',2);
		return false;
	} else if((userEmail.indexOf('@') <= 0) || ((userEmail.charAt(userEmail.length-4) != '.') && (userEmail.charAt(userEmail.length-3) != '.')))
	{
		inlineMsg('userEmail','Please enter the valid E-mail Id.',2);
		return false;
	}
	
	if(phoneNumber=="")
	{
		//alert(pro_title);
		inlineMsg('phoneNumber','You must enter the phone number.',2);
		return false;
	} 
	
	if(isNaN(phoneNumber))
	{
		inlineMsg('phoneNumber','You must enter the valid phone number.',2);
		return false;
		
	}
	
	
	if(address1=="")
	{
		//alert(pro_title);
		inlineMsg('address1','You must enter the address.',2);
		return false;
	} 
	
	if(city=="")
	{
		//alert(pro_title);
		inlineMsg('city','You must enter the city.',2);
		return false;
	} 
	
	if(country=="")
	{
		//alert(pro_title);
		inlineMsg('country','You must select the country.',2);
		return false;
	} 
	if(userTowns=="")
	{
		//alert(pro_title);
		inlineMsg('userTowns','You must select the state.',2);
		return false;
	} 
	
	if(zipCode=="")
	{
		//alert(pro_title);
		inlineMsg('zipCode','You must enter the zip code.',2);
		return false;
	} 
	if(isNaN(zipCode))
	{
		//alert(pro_title);
		inlineMsg('zipCode','You must enter the valid zip code.',2);
		return false;
	} 
	
 if(chkTerm=="")
   {
	    inlineMsg('chkTerm','Please select checkbox .',2);
		return false;
	   
   }	
	
}
function bidProjectValidForm(form) 
{
     var bid_pmb			=	form.bid_pmb.value;
     var bid_descrip		=	form.bid_descrip.value;
	 var bid_amount			=	form.bid_amount.value;
	 var ddline				=	form.ddline.value;
	  
	  
	if(bid_pmb=="")
	{
		inlineMsg('bid_pmb','You must enter ask the buyer a question.',2);
		return false;
	} 
	if(bid_descrip=="")
	{
		inlineMsg('bid_descrip','You must enter your proposals.',2);
		return false;
	} 
	
	if(bid_amount=="")
	{
		inlineMsg('bid_amount','You must enter bid amount.',2);
		return false;
	} 
	if(isNaN(bid_amount))
	{
		inlineMsg('bid_amount','You must enter valid bid amount.',2);
		return false;
	} 
	
	
	if(bid_descrip=="")
	{
		inlineMsg('bid_descrip','You must enter create your proposal.',2);
		return false;
	} 
	
	if(ddline=="")
	{
		inlineMsg('ddline','Select the approximate delivery Date.',2);
		return false;
	} 
	
	
	
}

/*Invite Friends Links*/

function inviteValidForm(form) 
{
     var textarea			=	form.textarea.value;
     var textmessage		=	form.textmessage.value;
	  
	if(textarea=="")
	{
		inlineMsg('textarea','You must enter your friends email id.',2);
		return false;
	} 
	var userEmail = textarea.split(",");
	//alert(userEmail.length);
	for(i=0; i<userEmail.length; i++){
		//alert(userEmail[i])
		
		if((userEmail[i].indexOf('@') <= 0) || ((userEmail[i].charAt(userEmail[i].length-4) != '.') && (userEmail[i].charAt(userEmail[i].length-3) != '.')))
		{
			inlineMsg('textarea','You must enter valid email id.',2);
		     return false;
		}
		
	}
	
	
	if(textmessage=="")
	{
		inlineMsg('textmessage','You must enter the description.',2);
		return false;
	} 
	
}
/////////////////////////////////

/*Invite Friends Links*/

function reportValidForm(form) 
{
     var report_text				=	form.report_text.value;
     var report_textarea			=	form.report_textarea.value;
	  
	if(report_text=="")
	{
		inlineMsg('report_text','You must enter the subject of the report.',2);
		return false;
	} 
	if(report_textarea=="")
	{
		inlineMsg('report_textarea','You must enter the description of the report.',2);
		return false;
	} 
	
}
/////////////////////////////////

/*Password Forms Validation*/

function passValid(form) 
{
	//alert("tt");
     var cpass				=	form.cpass.value;
     var npass				=	form.npass.value;
	 var nnpass 			=	form.nnpass.value;
	  
	if(cpass=="")
	{
		inlineMsg('cpass','You must enter  current password.',2);
		return false;
	} 
	if(npass=="")
	{
		inlineMsg('npass','You must enter  new password.',2);
		return false;
	} 
	if(nnpass=="")
	{
		inlineMsg('nnpass','You must enter  cofirm new password.',2);
		return false;
	} 
	
	if(npass!=nnpass)
	{
			inlineMsg('nnpass','Password are not same.',2);
		    return false;
	}
}
/////////////////////////////////

// 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(7,80); 
  arrow.src = "../images/msg_arrow.gif"; 
}
