function upload_logo(){

	try{
		if($('file_upload_form').style.display == 'block'){
			$('button_label').update("Upload a logo");
			$('button_label').innerHTML
			$('file_upload_form').style.display = 'none';
			$('button_label').up().style.display = 'block';
		}
		else{
			$('button_label').up().style.display = 'none';
			$('file_upload_form').style.display = 'block';
		}
	}
	catch(e) {}
}

function display_logo(){
	img_src = $('logo_id').src;
	$('logo_id').src = http_host+'/images/snake_transparent.gif';
	$('file_upload_form').style.display = 'none';
}

function update_logo(img){
	$('logo_id').src = img;
	$('logo_id').style.display = 'block';
	$('button_label').update("Change");
	$('button_label').innerHTML
	$('button_label').up().style.display = 'block';
}

function undo(){
	$('logo_id').src = http_host+'/images/blank_avatar.gif';
	upload_logo();
}

function enquire_now(){
	var error = 0;
	var field = '';
	var div_id = 'enquire';
	var my_function = 'reload_enquire_now';

	var name;
	if((name = $F('name')) == ''){
		field += 'Name, ';
		error = 1;
	}
	
	var email = $F('email');
	var phone = $F('phone');
	var valid = Validate_Email_Address(email);
	if(valid == false){
		field += 'Email, ';
		error = 1;
	}
	var locationId;
	if((locationId = $F('locationId')) == ''){
		field += 'you have to fill in properly Location, ';
		error = 1;
	}
	
	var message = $F('comment');
	var company_id = $F('company_id');
	
	var url_destination = window.location;

	if(error == 1){
		alert('Please fill in the following field correctly: '+field);
		$('submit').disabled = false;
	}
	else{
		var pars = "name="+escape(name)+"&email="+escape(email)+"&phone="+escape(phone)+"&locationId="+escape(locationId)+"&message="+escape(message)+"&my_function="+escape(my_function)+"&div_id="+div_id+"&company_id="+escape(company_id)+"&url_destination="+escape(url_destination);

		var myAjax_test = new Ajax.Updater(
		div_id,
		http_host+'/ajax/ajax_send_lead.php?'+pars, {
			evalScripts:true
		}
		);
	}
}

function mail(id){
	$('mail_form_'+id).submit();
}
function phone(id){
	$('mail_form_'+id).submit();
}

function reload_enquire_now(){
	var pars;
	var myAjax_test = new Ajax.Updater(
	'enquire',
	http_host+'/tags/enquire_now.php?'+pars, {
		evalScripts:true
	}
	);
}

function check_captcha_enquiry(){
	/* you have to include the content block captcha to get this information */
	var captcha_code = $F('captcha_code');
	var sid = $F('session_id');
	var reload_form = $F('reload_form');
	
	if (reload_form != '1'){
		var url = '/ajax/ajax_check_captcha.php';
		var pars = 'captcha_code='+captcha_code+'&SID='+sid;
		
		var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: function(originalRequest) {check_captcha_response_enquiry(originalRequest); return true}
		});
	}
	else{
		$('submit2').disabled = true;
		send_enquiry();
	}
}


function send_enquiry(){
	var error = 0;
	var field = '';
	var div_id = 'get_quote';
	var my_function = 'reload_enquiry';

	var name;
	if((name = $F('name')) == ''){
		field += 'Name, ';
		error = 1;
	}
	
	var email = $F('email');
	var valid = Validate_Email_Address(email);
	if(valid == false){
		field += 'Email, ';
		error = 1;
	}
	
	var locationId;
	if((locationId = $F('locationId2')) == ''){
		field += 'you have to fill in properly Location, ';
		error = 1;
	}
	var message = $F('comment');

	if(error == 1){
		alert('Please fill in the following field correctly: '+field);
		$('submit2').disabled = false;
		$F('submit2') = "Submit";
	}
	else{
		var content = $(div_id).innerHTML;
		var pars = "name="+escape(name)+"&email="+escape(email)+"&locationId="+escape(locationId)+"&message="+escape(message)+"&my_function="+escape(my_function);
		
		var myAjax_test = new Ajax.Updater(
		div_id,
		http_host+'/ajax/ajax_send_enquiry.php?'+pars, {
			evalScripts:true
		}
		);
	}
}


function check_captcha(){
	/* you have to include the content block captcha to get this information */
	var captcha_code = $F('captcha_code');
	var sid = $F('session_id');
	var reload_form = $F('reload_form');
	
	if (reload_form != '1'){
		var url = '/ajax/ajax_check_captcha.php';
		var pars = 'captcha_code='+captcha_code+'&SID='+sid;
		
		var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: function(originalRequest) {check_captcha_response(originalRequest); return true}
		});
	}
	else{
		$('submit2').disabled = true;
		get_quote();
	}
}

function check_captcha_response(originalRequest){
	if (originalRequest.responseText == 'true'){
		$('submit2').disabled = true;
		get_quote();
	}
	else{		
		alert('The captcha code is incorrect');
		$('submit2').disabled = false;
	}
}

function check_captcha_response_enquiry(originalRequest){
	if (originalRequest.responseText == 'true'){
		$('submit2').disabled = true;
		send_enquiry();
	}
	else{		
		alert('The captcha code is incorrect');
		$('submit2').disabled = false;
	}
}

function get_quote(){
	
	var error = 0;
	var field = '';
	var div_id = 'enquire_now';
	var my_function = 'reload_get_quote';

	var name;
	if((name = $F('name')) == ''){
		field += 'Name, ';
		error = 1;
	}
	
	var email = $F('email');
	var phone = $F('phone');
	var valid = Validate_Email_Address(email);
	if(valid == false){
		field += 'Email, ';
		error = 1;
	}
	
	var locationId;
	if((locationId = $F('locationId2')) == ''){
		field += 'you have to fill in properly Location, ';
		error = 1;
	}
	if($('receive_offer').checked==true)
		var special_offer = 'yes';
	else
		var special_offer = 'no';
	var message = $F('comment');
	
	var url_destination = window.location;

	if(error == 1){
		alert('Please fill in the following field correctly: '+field);
		$('submit2').disabled = false;
	}
	else{
		var content = $(div_id).innerHTML;
		var pars = "name="+escape(name)+"&email="+escape(email)+"&phone="+escape(phone)+"&locationId="+escape(locationId)+"&special_offer="+escape(special_offer)+"&message="+escape(message)+"&my_function="+escape(my_function)+"&div_id="+div_id+"&url_destination="+escape(url_destination);
		var myAjax_test = new Ajax.Updater(
		div_id,
		http_host+'/ajax/ajax_send_lead.php?'+pars, {
			evalScripts:true
		}
		);
	}
}


function reload_enquiry(){
	var pars;
	var myAjax_test = new Ajax.Updater(
	'get_quote',
	http_host+'/tags/enquiry.php?'+pars, {
		evalScripts:true
	}
	);
}

function reload_get_quote(){
	var pars;
	var myAjax_test = new Ajax.Updater(
	'enquire_now',
	http_host+'/tags/get_quote.php?'+pars, {
		evalScripts:true
	}
	);
}

function add_your_business(nb_product){
	
	$("processing").style.display = "block";
	
	var error = 0;
	var field = '';
	var product = '';
	var div_id = 'tmp_div';
	var my_function = 'reload_add_your_business';

	var premium_listing = 1;
	
	var logo_url = $("logo_id").src;
	
	var name;
	if((name = $F('name')) == ''){
		field += 'Business Name, ';
		error = 1;
	}
	
	var phone = $F('phone');
	if(phone == '' || IsNumeric(phone)==false || phone.length<10){
		field += 'Phone (need to be 10 numeric characters), ';
		error = 1;
	}
	
	var fax = $F('fax');
	if(fax != ''){
		if(IsNumeric(fax)==false || fax.length<10){
			field += 'Fax (need to be 10 numeric characters), ';
			error = 1;
		}
	}
	
	var email = $F('email');
	var valid = Validate_Email_Address(email);
	if(valid == false){
		field += 'Email, ';
		error = 1;
	}
	
	var street;
	if((street = $F('street')) == ''){
		field += 'street, ';
		error = 1;
	}
	if($F('unit') != '' && $F('street_number') != ''){
		var address = $F('unit')+' / '+$F('street_number')+' '+$F('street');
	}
	else
		var address = $F('unit')+' '+$F('street_number')+' '+$F('street');
		
	var locationId;
	if((locationId = $F('locationId2')) == ''){
		field += 'you have to fill in properly Location, ';
		error = 1;
	}
	var url = $F('url');
	if(url!=''){
		if(url.substr(0, 7) != 'http://'){
			alert("You need to add http:// for your url");
			error = 2;
			$('submit2').disabled = false;
		}
	}
	for(i=1;i<=nb_product;i++){
		if($F('product_'+i) == 1){
			product = product+i+'/';
		}
	}
	if((tag = $F('tag')) == ''){
		field += 'tag, ';
		error = 1;
	}
	
	var description;
	if((description = $F('desc')) == ''){
		field += 'description, ';
		error = 1;
	}
	
	var contact_firstname;
	if((contact_firstname = $F('contact_firstname')) == ''){
		field += 'Firstname, ';
		error = 1;
	}
	
	var contact_lastname;
	if((contact_lastname = $F('contact_lastname')) == ''){
		field += 'Lastname, ';
		error = 1;
	}
	
	var contact_phone = $F('contact_phone')
	if(contact_phone == '' || IsNumeric(contact_phone)==false || contact_phone.length<10){
		field += 'Phone (need to be 10 numeric characters), ';
		error = 1;
	}
	
	var contact_email = $F('contact_email')
	var valid = Validate_Email_Address(contact_email);
	if(valid == false){
		field += 'Email, ';
		error = 1;
	}
	if(error == 1){
		$("processing").style.display = "none";
		field = field.substr(0, (field.length -2))
		alert('Please fill in the following field correctly: '+field);
		$('submit2').disabled = false;
		$('submit2').value = "Go to our secure server";
	}
	if(error == 0){
				
		var pars = "premium_listing="+escape(premium_listing)+"&logo_url="+escape(logo_url)+"&name="+escape(name)+"&email="+escape(email)+"&phone="+escape(phone)+"&fax="+escape(fax)+"&address="+escape(address)+"&locationId="+escape(locationId)+"&url="+escape(url)+"&product="+escape(product)+"&tag="+escape(tag)+"&description="+escape(description)+"&contact_firstname="+escape(contact_firstname)+"&contact_lastname="+escape(contact_lastname)+"&contact_phone="+escape(contact_phone)+"&contact_email="+escape(contact_email)+"&my_function="+escape(my_function);

		var myAjax_test = new Ajax.Updater(
		div_id,
		http_host+'/ajax/ajax_add_your_business.php?'+pars, {
			method: 'post',
			parameters: pars,
			encoding: 'UTF-8',
			evalScripts:true
		}
		);
	}
}

function reload_add_your_business(){
	var pars;
	var myAjax_test = new Ajax.Updater(
	'add_your_business',
	http_host+'/ajax/ajax_add_your_business_form.php?'+pars, {
		evalScripts:true
	}
	);
}

function Validate_String(string, return_invalid_chars){
	var valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var invalid_chars = '';

	if(string == null || string == '')
	return(true);

	//For every character on the string.
	for(index = 0; index < string.length; index++)
	{
		char = string.substr(index, 1);

		//Is it a valid character?
		if(valid_chars.indexOf(char) == -1)
		{
			//If not, is it already on the list of invalid characters?
			if(invalid_chars.indexOf(char) == -1)
			{
				//If it's not, add it.
				if(invalid_chars == '')
				invalid_chars += char;
				else
				invalid_chars += ', ' + char;
			}
		}
	}

	//If the string does not contain invalid characters, the function will return true.
	//If it does, it will either return false or a list of the invalid characters used
	//in the string, depending on the value of the second parameter.
	if(return_invalid_chars == true && invalid_chars != '')
	{
		var last_comma = invalid_chars.lastIndexOf(',');

		if(last_comma != -1)
		invalid_chars = invalid_chars.substr(0, $last_comma) +
		' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);

		return(invalid_chars);
	}
	else
	return(invalid_chars == '');
}

function Validate_Email_Address(email_address){
	//Assumes that valid email addresses consist of user_name@domain.tld
	var at = email_address.indexOf('@');
	var dot = email_address.indexOf('.');

	if(at == -1 ||
	dot == -1 ||
	dot == 0 ||
	dot == email_address.length - 1)
	return(false);

	var user_name = email_address.substr(0, at);
	var domain_name = email_address.substr(at + 1, email_address.length);

	if(Validate_String(user_name) === false ||
	Validate_String(domain_name) === false)
	return(false);

	return(true);
}

function contact_us_or_advertise_form(id){
	
	var error = 0;
	var field = '';
	var div_id = 'contact_us';
	if(id == 1) {var my_function = "reload_contact_us";}
	else {var my_function = "reload_advertise";}
	
	var name;
	if((name = $('name4').value) == ''){
		field += 'Name, ';
		error = 1;
	}
	
	var phone;
	if((phone = $('phone4').value) == ''){
		field += 'Phone, ';
		error = 1;
	}
	
	var email = $('email4').value;
	var valid = Validate_Email_Address(email);
	if(valid == false){
		field += 'Email, ';
		error = 1;
	}
	//subject = $('subject4').value;
	var message = $('comment4').value;
	if(error == 1){
		alert('Please fill in the following field correctly: '+field);
	}
	if(error == 0){		
		if(id == 1){
			var pars = "name="+escape(name)+"&phone="+escape(phone)+"&email="+escape(email)+"&message="+escape(message)+"&my_function="+escape(my_function);
		}
		if(id == 2){
			var pars = "name="+escape(name)+"&phone="+escape(phone)+"&email="+escape(email)+"&message="+escape(message)+"&my_function="+escape(my_function);
		}
		var myAjax_test = new Ajax.Updater(
				div_id, 
				http_host+'/ajax/ajaxSendMail.php?'+pars, {
					evalScripts:true
				}
			);
	}	

}
function check_captcha_expert_question(){
	/* you have to include the content block captcha to get this information */
	var captcha_code = $F('captcha_code');
	var sid = $F('session_id');
	var reload_form = $F('reload_form');

	if (reload_form != '1'){
		var url = '/ajax/ajax_check_captcha.php';
		var pars = 'captcha_code='+captcha_code+'&SID='+sid;

		var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: function(originalRequest) {check_captcha_response_expert_question(originalRequest); return true}
		});
	}
	else{
		$('submit_expert_question').value='Sending';
		$('submit_expert_question').disabled = true;
		send_expert_question();
	}
}

function check_captcha_response_expert_question(originalRequest){
	if (originalRequest.responseText == 'true'){
		$('submit_expert_question').value='Sending';
		$('submit_expert_question').disabled = true;
		send_expert_question();
	}
	else{
		alert('The captcha code is incorrect');
		$('submit_expert_question').value='Post your Question';
		$('submit_expert_question').disabled = false;
	}
}

function send_expert_question(){
	
	var error=0;
	var field = '';
	
	var name;
	if((name = $F('name_contact')) == ''){
		field += 'Name, ';
		error = 1;
	}
	
	var email = $F('email');
	var valid = Validate_Email_Address(email);
	if(valid == false){
		field += 'Email, ';
		error = 1;
	}
	
	var locationId;
	if((locationId = $F('locationId')) == ''){
		field += 'you have to fill in properly Location, ';
		error = 1;
	}
	
	var message;
	if((message = $F('message')) == ''){
		field += 'Message, ';
		error = 1;
	}
	if(error == 1){
		$('submit_expert_question').value='Post your Question';
		$('submit_expert_question').disabled = false;
		alert('Please fill in the following field correctly: '+field);
	}
	if(error == 0){
		var pars = "name="+escape(name)+"&email="+escape(email)+"&locationId="+escape(locationId)+"&message="+escape(message);
		
		var myAjax = new Ajax.Updater(
				'expert_question', 
				http_host+'/ajax/ajax_send_expert_question.php?'+pars, {
					evalScripts:true
				}
			);
	}
}

function reload_contact_us(){
	var pars;	
	var myAjax_test = new Ajax.Updater(
		'contact_us', 
		http_host+'/tags/contact_us_page.php?'+pars, {
			evalScripts:true
		}
	);
}

function reload_advertise(){
	var pars;	
	var myAjax_test = new Ajax.Updater(
		'contact_us', 
		http_host+'/tags/advertise.php?'+pars, {
			evalScripts:true
		}
	);
}
// ########################################################################################################
// PHONE
function IsNumeric(sText){
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
 
	for (i = 0; i < sText.length && IsNumber == true; i++){ 
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1){
			IsNumber = false;
		}
	}
	return IsNumber;
}
