function validateEmail(form) {
	var mail = $(form).find('input[name*=email]').val();
	if (mail.indexOf('@') > -1 && mail.indexOf('.') > -1) {
		return true;
	} else {
		alert('Please enter a valid e-mail address!');
		return false;
	}
}
/*
function ajax_process_banner_type_onchange() {

}
*/
function login_popup(url) {
	var obj = window.open(url,"register_window","width=480, height=360, scrollbars=0, menubar=0, status=0, location=0, resizable=0");
	x = (screen.width - 400) / 2;
	y = (screen.height - 250) / 2;
	obj.moveTo(x, y);
}
function ajax_clients_by_category(filter_category_id,recurse) {
	var ProductClientId=document.getElementById('ProductClientId');
	if(recurse==undefined){
		recurse=true;
	}
	if(filter_category_id == '0'){
		ProductClientId.selectedIndex=0;
		if(recurse) {
			ajax_categories_by_client('0');
		}
	}
	if(ProductClientId.value=='0'){
		$.post(
			"/products/ajax_clients_by_category/"+filter_category_id,
			{form_name:'Product'},
			function(ajax_result){
//				alert(ajax_result);
				ajax_populate_client_select(ajax_result,'Product');
			}
		);
	}
}
function ajax_populate_client_select(ajax_result,form_name) {
	var client_select_div=document.getElementById('client_select_div');
	client_select_div.innerHTML=ajax_result;
}
function ajax_categories_by_client(filter_client_id) {
	var ProductCategoryId=document.getElementById('ProductCategoryId');
	if(filter_client_id == '0'){
		ProductCategoryId.selectedIndex=0;
		ajax_clients_by_category('0',false);
	}
	if(ProductCategoryId.value=='0'){
		$.post(
			"/products/ajax_categories_by_client/"+filter_client_id,
			{form_name:'Product'},
			function(ajax_result){
//				alert(ajax_result);
				ajax_populate_category_select(ajax_result);
			}
		);
	}
}
function ajax_populate_category_select(ajax_result) {
	var category_select_div=document.getElementById('category_select_div');
	category_select_div.innerHTML=ajax_result;
}
function ajax_products_by_client(filter_client_id,app_form_name) {
//	alert(app_form_name);
	var ClientId=document.getElementById(app_form_name+'ClientId');
	$.post(
		"/products/ajax_products_by_client/"+filter_client_id,
		{form_name:app_form_name},
		function(ajax_result){
			ajax_populate_products_select(ajax_result,app_form_name);
		}
	);
	if(ClientId.options[ClientId.selectedIndex].value=='0'){
		$.post(
			"/products/ajax_client_by_product/0",
			{form_name:app_form_name},
			function(ajax_result){
				ajax_populate_client_select(ajax_result,app_form_name);
				ajax_set_client_selected(0,app_form_name);
			}
		);
	}
}
function ajax_populate_products_select(ajax_result,form_name) {
	var ProductId=document.getElementById('product_select_div');
	ProductId.innerHTML=ajax_result;
}
function ajax_client_by_product(filter_product_id,app_form_name) {
	var ClientId=document.getElementById(app_form_name+'ClientId');
//	alert('ajax_client_by_product form:'+app_form_name);
	if(ClientId.options[ClientId.selectedIndex].value=='0'){
		$.post(
			"/products/ajax_client_by_product/"+filter_product_id,
			{form_name:app_form_name},
			function(ajax_result){
				ajax_populate_client_select(ajax_result,app_form_name);
				ajax_set_client_selected(filter_product_id,app_form_name);
			}
		);
	} else {
		ajax_set_client_selected(filter_product_id,app_form_name);
	}
}
function ajax_set_client_selected(filter_product_id,form_name){
	var ClientId=document.getElementById(form_name+'ClientId');
//	alert('set client selected form:'+form_name);
	$.get(
		"/products/ajax_product_client_id/"+filter_product_id,
		function(client_id){
//			alert('set client selected client_id:'+client_id);
//			alert(ClientId.options.length);
			for(i=0;i<ClientId.options.length;i++){
				if(ClientId.options[i].value==client_id){
					ClientId.selectedIndex=i;
				}
			}
		}
	);
}

