/*****
GCN Media Corp.
http://gcnmediacorp.com

date-update: 2009.06.02
*****/
function gcn_msg (obj, type, txt) {
	if (type.length > 0) {
		$(obj+'_msg').attr('class', type);
		$(obj+'_msg').hide().html(txt).show('slow');
	}
	else {
		$(obj+'_msg').hide();
	}
}

function isEmailAddress (s)
{
	//var s = theElement.value;
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
	{
		return true;
	}
	return false;
}

function gcn_input_error (obj) {
	//$(obj).attr('class', 'input_error');
	$(obj).addClass('input_error');
}
function gcn_input_reset (obj) {
	//$(obj).attr('class', '');
	$(obj).removeClass('input_error');
}



$(document).ready(function(){
	/*$('#f_names').focus();
	$('#f_b_send').click(function(){
		form_verify();
	});*/
	$('#f_resolution').val(screen.width+'x'+screen.height);
	
	$('#f_logo_a').click(function(){
		$('#upload_logo').show();
	});
	$('#f_logo_b').click(function(){
		$('#upload_logo').hide();
	});
	$('#f_web_site_a').click(function(){
		$('#my_web_site').show();
	});
	$('#f_web_site_b').click(function(){
		$('#my_web_site').hide();
	});
	
	$('#f_pack_basic').click(function(){
		form_pack('basic');
	});
	$('#f_pack_professional').click(function(){
		form_pack('professional');
	});
	$('#f_pack_commercial').click(function(){
		form_pack('commercial');
	});
	$('#f_pack_corporate').click(function(){
		form_pack('corporate');
	});
	
	$('#b_send').click(form_verify);
	
	$('#b_reset').click(form_reset);
	
	$('#f_sectors_extra_option').click(function(){
		$('#f_sectors_extra').toggle('slow');
	});	
});


function form_pack (type) {
	$('.pack').hide();
	$('#pack_'+type).show();
}

function form_logo () {
	//a = document.form_query.
	//$('#f_logo_msg').html('as');
	//document.getElementById('checkbox' + i).checked;
	// document.getElementById('radio' + i).checked
	
	
	var i 
    for (i=0;i<document.form_query.f_logo.length;i++){ 
       if (document.form_query.f_logo[i].checked) 
          break; 
    } 
    alert(document.form_query.f_logo[i].value);
	
}

function form_verify () {

	errors_txt = new Array();

	objId = '#f_client_name';
	objTxt = $(objId).val();
	if (objTxt.length == 0) {
		errors_txt.push('Empty client name');
		gcn_input_error(objId);
	} else {
		gcn_input_reset(objId);
	}
	
	objId = '#f_client_product';
	objTxt = $(objId).val();
	if (objTxt.length == 0) {
		errors_txt.push('Empty product / service that sells');
		gcn_input_error(objId);
	} else {
		gcn_input_reset(objId);
	}
	
	objId = '#f_client_product_description';
	objTxt = $(objId).val();
	if (objTxt.length == 0) {
		errors_txt.push('Empty description of product / service');
		gcn_input_error(objId);
	} else {
		gcn_input_reset(objId);
	}
	/*
	objId = '#f_client_competition';
	objTxt = $(objId).val();
	if (objTxt.length == 0) {
		errors_txt.push('Vacio competencia');
		gcn_input_error(objId);
	} else {
		gcn_input_reset(objId);
	}
	
	objId = '#f_client_colors';
	objTxt = $(objId).val();
	if (objTxt.length == 0) {
		errors_txt.push('Vacio colores');
		gcn_input_error(objId);
	} else {
		gcn_input_reset(objId);
	}
	*/
	objId = '#f_client_directions';
	objTxt = $(objId).val();
	if (objTxt.length == 0) {
		errors_txt.push('Empty address');
		gcn_input_error(objId);
	} else {
		gcn_input_reset(objId);
	}
	
	objId = '#f_client_phones';
	objTxt = $(objId).val();
	if (objTxt.length == 0) {
		errors_txt.push('Empty phone');
		gcn_input_error(objId);
	} else {
		gcn_input_reset(objId);
	}

	
	objId = '#f_client_email';
	objTxt = $(objId).val();
	if (objTxt.length == 0) {
		errors_txt.push('Empty Email');
		gcn_input_error(objId);
	}
	else {
		if (!isEmailAddress(objTxt)) {
			errors_txt.push('Invalid Email');
			gcn_input_error(objId);
		}
		else {
			gcn_input_reset(objId);
		}
	}
	
	if (errors_txt.length == 0) {
		//form_send();
		$('.control').hide();
		$('.form_loading').show();
		return true;
	} else {
		$('#control_2').show();
			
		var txt = '';
		for (i=0; i < errors_txt.length; i++) {
			txt += errors_txt[i]+"<br>";
		}
		$.alerts.dialogClass = 'style_box'; // set custom style class
		jAlert(txt, 'Alert Form', function() {
			$.alerts.dialogClass = null; // reset to default
		});
	}
	return false;	
}

function form_send () {
	$('#f_b_send').hide();
	$('#form_loading').show();
	$.ajax({
		type: "POST",
		url: "ajax/ajax_contact.php?lang=en",
		data: $('#form_contact_company').serialize(),
		success: function(data) {
			//$('#form_loading').hide();
			$('#form_contact').html(data);
		}
	});
}

function form_reset () {
	//$('#form_query').reset();
	$('#f_sectors_extra').hide();
	document.form_query.reset();	
}

function empty_obj (objId) {
	$('#'+objId).val('');
}

function form_end () {
	$('#form_query').hide();
	$('.form_loading').hide();
	$('#form_success').show();
}
function form_error(text) {
	$('.form_loading').hide();
	$('.control').show();
	$.alerts.dialogClass = 'style_box'; // set custom style class
	jAlert(text, 'Error Form', function() {
		$.alerts.dialogClass = null; // reset to default
	});	
}

function gcn_sector (url) {
	window.location.href = url;
}
