function axc(enviar, idrecibir, btn){
	var divrecibir=$(idrecibir);
	var botonsub=$(btn);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {divrecibir.innerHTML='<img src="images/loader.gif" />'; botonsub.disabled=true;}, 
		onSuccess: function(texto, xmlrespuesta){divrecibir.innerHTML = texto; botonsub.disabled=false;},
		onFailure: function(){ alert('Could not complete the operation, try again later\nDetails:\n\nDatabase conection failed.');return 0;}
	}).send(); 
}

function accion(enviar, idrecibir, btn){
	var divrecibir=$(idrecibir);
	var botonsub=$(btn);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {divrecibir.innerHTML='<img src="images/loading.gif" />';botonsub.style.display='none';}, 
		onSuccess: function(texto, xmlrespuesta){divrecibir.innerHTML = texto; botonsub.style.display='inline';},
		onFailure: function(){ alert('No se pudo completar la operacion, intentelo otra vez');return 0;}
	}).send(); 
}

function axcountry(value, div_state, state_id, div_city, city_id){
	axc('ajax/states.php?name='+state_id+'&country='+value+'&name2='+city_id+'&recibir='+div_city, div_state, 'bsubmit');
	//only USA shows cities
	$(div_city).innerHTML="<select name='"+city_id+"' id='"+city_id+"'><option value=''>--- Select a City ---</option></select>";
	
}

function axstate(div_city, value, city_id, country){
	axc('ajax/cities.php?name='+city_id+'&state='+value+'&country='+country, div_city, 'bsubmit');
}

function check_availability(login){	
	axc('ajax/check.php?login='+login,'check_username','available');
	/*document.getElementById('check_username').innerHTML = '<img src="images/check.png" height="15" width="15"/>';*/
}
function check_pass(pass){
	if(pass==""){
		document.getElementById('check_pass').innerHTML = '<span class="mensaje">Required field cannot be left blank </span>';		
	}
	else{
		if(pass.length>=3){
			document.getElementById('check_pass').innerHTML = '<img src="images/check.png" height="15" width="15"/>';		
		}
		else{
			document.getElementById('check_pass').innerHTML = '<span class="mensaje">Your password is not secure</span>';		
		}
	}
}
function check_pass_confirm(pass1,pass2){
	
		if(pass1==pass2)	
			if(pass1==""){
				document.getElementById('check_pass_confirm').innerHTML = '';
			}
			else{	document.getElementById('check_pass_confirm').innerHTML = '<img src="images/check.png" height="15" width="15"/>';}
		else{		
				document.getElementById('check_pass_confirm').innerHTML = '<span class="mensaje">The passwords do not match</span>';
		}
}
function check_email_confirm(email1,email2){	
		if(email1==email2)	
			if(email1==""){
				document.getElementById('check_email_confirm').innerHTML = '';
			}
			else{	document.getElementById('check_email_confirm').innerHTML = '<img src="images/check.png" height="15" width="15"/>';}
		else{		
				document.getElementById('check_email_confirm').innerHTML = '<span class="mensaje">The email do not match</span>';
		}
}
function validate_email(v) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3,4})+$/.test(v)){
		return true;
	} else {
		return false;
	}
}
function check_email(value){
	if(value=="")
		document.getElementById('check_email').innerHTML = '<span class="mensaje">Required field cannot be left blank </span>';		
	else {
			document.getElementById('check_email').innerHTML = '<img src="images/check.png" height="15" width="15"/>';					
	}
}
function check_firstname(value){
	if(value=="")
		document.getElementById('check_firstname').innerHTML = '<span class="mensaje">Required field cannot be left blank </span>';		
	else
		document.getElementById('check_firstname').innerHTML = '<img src="images/check.png" height="15" width="15"/>';				
}
function check_lastname(value){
	if(value=="")
		document.getElementById('check_lastname').innerHTML = '<span class="mensaje">Required field cannot be left blank </span>';		
	else
		document.getElementById('check_lastname').innerHTML = '<img src="images/check.png" height="15" width="15"/>';				
}
function check_partner(value){
	if(value=="")
		document.getElementById('check_partner').innerHTML = '<span class="mensaje">Required field cannot be left blank </span>';		
	else
		document.getElementById('check_partner').innerHTML = '<img src="images/check.png" height="15" width="15"/>';				
}
function check_response(value){
	if(value=="")
		document.getElementById('check_response').innerHTML = '<span class="mensaje">Required field cannot be left blank </span>';		
	else
		document.getElementById('check_response').innerHTML = '<img src="images/check.png" height="15" width="15"/>';				
}
function check_squestion(value){
	if(value=="")
		document.getElementById('check_squestion').innerHTML = '<span class="mensaje">Required field cannot be left blank </span>';		
	else
		document.getElementById('check_squestion').innerHTML = '<img src="images/check.png" height="15" width="15"/>';				
}

function addFeature(idrecibir, idProduct){
	accion('controllers/agregarcar.php?id='+idProduct,idrecibir,'boton');
	
}
function deleteFeature(idrecibir, idProduct){
	accion('controllers/borrarcar.php?id='+idProduct,idrecibir,'boton');
	
}

/*======================== Scripts para partner system =====================*/
function add_invoice(idrecibir,idProduct){
	accion('ajax/agregar_invoice.php?id='+idProduct,idrecibir,'boton');
	}
function delete_invoice(idrecibir,idProduct){
	accion('ajax/borrar_invoice.php?id='+idProduct,idrecibir,'boton');
	}
	
function show_description(divrecibir,value)
{
	if(value=="receive_check")
	{
		if($(divrecibir).style.display=='none')
			dplieg(divrecibir);
		$(divrecibir).innerHTML="<span style='font-weight:bold;font-size:0.9em;color:#464646'> With this option BigJobsBoard.com will send your comission payment via check to the address on file for your account.</span>";
		plieg(divrecibir);
		}
	else if(value=="advertising_credit")
	{
		if($(divrecibir).style.display=='none')
			dplieg(divrecibir);
		$(divrecibir).innerHTML="<span style='font-weight:bold;font-size:0.9em;color:#464646'> With this option BigJobsBoard.com will credit your comission payment to your account for advertising purchases.</span>";
		plieg(divrecibir);
		}
	else if(value=="")
		dplieg(divrecibir);
	}
function update_options(value)
{
	if(value=='sales-partner')
	{
		//ocultar la otra opcion
		jQuery('#options_salespartner').show();
		//mostrar las variables de customer
		jQuery('#options_customer').hide();
		
		}
	else if(value=='customer')
	{
		//mostrar las variables de customer
		jQuery('#options_customer').show();
		//ocultar la otra opcion
		jQuery('#options_salespartner').hide();
		}
	else if(value=='reseller')
	{
		//redirect to AMC site
		if(confirm("You are about to be redirected to AdManangementCenter.com to login.  Is this Ok?"))
		{
			document.location="http://www.admanagementcenter.com/";
			return false;
			}
		else
		{
			//resetear el combo
			document.forms[0].elements['type_user'].selectedIndex = 0;
			}
		}
	}
