/* start login */
var product_id='';
function set_product_id(id)
{
	product_id=id;
}
jQuery(document).ready(function()
{
	jQuery("#frm_login_modal").submit(function()
	{	
		var flag=0;
		if ($("#code").val() == "") 
		{
			$("#emp_code1").text("Please enter your code...").fadeIn(1000);
			flag=1;
		}
		else if($("#code").val().length<5 || $("#code").val().length>6)
		{
			$("#emp_code1").text("Please contact your distributor to request a sample by email or fax.").fadeIn(1000);
			flag=1;
		}
		else
		{
			  $("#emp_code1").fadeOut(1000);
		}
		if ($("#company_name").val() == "") 
		{
			$("#emp_company_name").text("Please enter Company Name...").fadeIn(1000);
			flag=1;
		}
		else
		{
			  $("#emp_company_name").fadeOut(1000);
		}
		if ($("#email_address").val() == "") 
		{
			$("#emp_email_address").text("Please enter your Email...").fadeIn(1000);
			flag=1;
		}
		else
		{
			  $("#emp_email_address").fadeOut(1000);
		}
		
		if(flag==0)
		{
		//remove all the class add the messagebox classes and start fading
		jQuery("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
		
		//check the username exists or not from ajax
		jQuery.post(root_url+"action.php",{ code:jQuery('#code').val(),email_address:jQuery('#email_address').val(),company_name:jQuery('#company_name').val(),form_name:'frm_login_modal',rand:Math.random() } ,function(data)
        {
			//data=data.replace(" ","");
		//	alert(data);
		  if(data=='true') //if valid response
		  {
		  	jQuery("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  jQuery(this).html('Successfully Logged in! Please Wait...').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	//alert(root_url);
			  	 location.href=root_url+'details.php?product_id='+product_id;
			  });
			  
			});
		  }
		  else
		  {
		  	jQuery("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  jQuery(this).html('Wrong Code/Email!...').addClass('messageboxerror').fadeTo(900,1);
			});		
          }				
        });
 		return false; //not to post the  form physically
		}
		else
		{
			return false;
		}
	});
});		
/* login ends */
