$(document).ready(function(){


	$(window).scroll(function(){
		if  ($(window).scrollTop() > $(".smartBannerIdentifier").offset({ scroll: false }).top){
		   $(".banner").css("position", "fixed");
		   $(".banner").css("top", "0");
		}
		
		if  ($(window).scrollTop() <= $(".smartBannerIdentifier").offset({ scroll: false }).top){
		   $(".banner").css("position", "relative");
		   $(".banner").css("top", $(".smartBannerIdentifier").offset);
		}
	}); 

	$("#submit_cust_info").click(function(){
		$("#profile_tab").fadeOut();
		$("#preview_customer_tab").fadeOut();
		$("#submit_customer_tab").fadeIn("slow");
	}); 

	$("#backto_sales_person_info").click(function(){
		$("#profile_tab").fadeOut();
		$("#preview_customer_tab").fadeOut();
		$("#submit_customer_tab").fadeIn("slow");
	}); 

	$("#modify_sales_person_info").click(function(){
		$("#submit_customer_tab").fadeOut();
		$("#preview_customer_tab").fadeOut();
		$("#profile_tab").fadeIn("slow");
	}); 


	$("#forgot_password_lnk").click(function(){
		$("#forgot_pass_tab").fadeIn("slow");
	}); 


});

function reflectCity(selObj){
	
	$("#other_city").fadeIn("slow");
		$("#other_city").val("");
		
	$('#feature_tab').hide();
	$('#progress_img').show();
	 getCity(selObj);
	//$('#progress_img').hide();$('#feature_tab').show();
	
}
function getCity(selObj)
{ 
	var frm = document.customer;
	var sitePath=site_url;
	var ajaxPath=sitePath+"/class.front.manipulation.php";
	
	document.getElementById("city").options.length=0;
		$.post(ajaxPath,{"action_type":"get_city","country_id":selObj.value},function(data)
		{	
			var combo_list;
			combo_list = data.split("|");
			for (var j=0;j < combo_list.length;j++)
			{
					var combo = combo_list[j];
					var optn  = document.createElement("OPTION");
					optn.text = combo;
					optn.value = combo;
					document.getElementById('city').options.add(optn);
			}
				
			 
			
		});
}	
function reflectValue(obj){
	obj_id = obj.id;
	var ihtml = $("#"+obj_id).val();
	ihtml = ihtml.replace(/\r/g,''); // removes return character "\r"
	ihtml = ihtml.replace(/\n/g,'<br>'); // replaces line feed character "\n" with <br>
	if (obj_id == "other_city")
		$("#preview_city").html(ihtml);
	else
		$("#preview_"+obj_id).html(ihtml);
}

function reflectOtherValues(){
	scroll(0,0);
	var frm= document.customer;
	$("#submit_customer_tab").fadeOut();
	$("#preview_customer_tab").fadeIn("slow");
	/*for (var i=0;i<frm.belongs_to.length;i++)
	{
		if (frm.belongs_to[i].checked == true)
		{
			$("#preview_belongs_to").html(frm.preview_belongs_to[i].value);break;
		}
	}*/
		var preview_belongs_list = "";
		for (var i=0;i<frm.elements['belongs_to[]'].length;i++)
		{
			if (frm.elements['belongs_to[]'][i].checked == true)
			{
				preview_belongs_list += frm.preview_belongs_to[i].value+"<br>";
			}
		}

	$("#preview_belongs_list").html(preview_belongs_list);
	
	
	var preview_product_list = "";
	for (var i=0;i<frm.elements['products[]'].length;i++)
	{
		if (frm.elements['products[]'][i].checked == true)
		{
			preview_product_list += frm.preview_products[i].value+"<br>";
		}
	}

	$("#preview_product_list").html(preview_product_list);

	var preview_industry_list = "";
	for (var i=0;i<frm.elements['industry_list[]'].length;i++)
	{
		if (frm.elements['industry_list[]'][i].checked == true)
		{
			preview_industry_list += frm.preview_industry[i].value+"<br>";
		}
	}

	$("#preview_industry_list").html(preview_industry_list);
	var country_txt = frm.country.options;
    var old_text = country_txt[country_txt.selectedIndex].text;
	$("#preview_country").html(old_text);
}

function validateLogin()
{ 

	if(document.frm_login.uname.value==''){
		alert("Please enter frm_login  name!");
		document.frm_login.uname.focus();
		return;
	}

	if(document.frm_login.upass.value==''){
		alert("Please enter password!");
		document.frm_login.upass.focus();
		return;
	}

	document.frm_login.submit();
}

function validateForgot()
{ 

	if(document.frm_login.forgot_email.value==''){
		alert("Please enter your email address!");
		document.frm_login.forgot_email.focus();
		return;
	}

	if(!CheckEmail(document.frm_login.forgot_email)) return;

	document.frm_login.submit();
}



function validateCustomer()
{
	var frm= document.customer;
	if(!CheckEmpty(frm.company_name, "Company Name")) return false;
	if(!CheckEmpty(frm.address, "Address")) return false;
	if(!CheckEmpty(frm.other_city, "City")) return false;
	if(!CheckEmpty(frm.state, "State")) return false;
	if(!CheckEmpty(frm.contact_person, "Contact Person")) return false;
	if (frm.email.value != "")
	{
		if(!CheckEmail(frm.email)) return false;
	}
	if (frm.email_2.value != "")
	{
		if(!CheckEmail(frm.email_2)) return false;
	}

	reflectOtherValues(); return false;
}

function validateSalesPerson()
{
	var frm= document.sales_person;

	if(!CheckEmpty(frm.sales_person_login, "User name(Email)")) return false;
	if(!CheckEmail(frm.sales_person_login)) return false;

	if(!CheckEmpty(frm.sales_person_pass, "Password")) return false;
	if(!CheckEmpty(frm.first_name, "First Name")) return false;
	if(!CheckEmpty(frm.last_name, "Last Name")) return false;
	if(!CheckEmpty(frm.other_city, "City")) return false;
	if(!CheckEmpty(frm.state, "State")) return false;
	if(!CheckEmpty(frm.phone, "Phone number")) return false;

	return true;
}


function handleEnter(evt)
{
	
	 var charCode = (evt.which) ? evt.which : event.keyCode	
	 if (charCode == 13)
	 {
		document.getElementById('search').click();
	
	}
}


function selectCity(obj, oth_obj){
	if (obj.selectedIndex==0)
	{
		$("#"+oth_obj+"").fadeIn("slow");
		$("#"+oth_obj+"").val("");
	}else {
		$("#"+oth_obj+"").fadeOut("slow");
		$("#"+oth_obj+"").val(""+obj.value+"");
		$("#preview_city").html(""+obj.value+"");
	}

}

function CheckEmail(email)
{
	if(!RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(email.value))
    {
		alert("Please enter the valid email address");
        email.focus();
        return false;
    }
	else
		return true;
}

function CheckEmpty(cntrl,field_title)
{
	if(cntrl.value == "")
	{
		alert("Please enter "+field_title);
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}


