function clearthis(id,txt)
{
	if(document.getElementById(id).value == txt)
	{
		document.getElementById(id).value='';
	}
}
function checkthis(id,txt)
{
	if(document.getElementById(id).value == '')
	{
		document.getElementById(id).value = txt;
	}
}


function swapimage(src) 
{
   document.getElementById('p_image').src = src;
   document.getElementById('p_image').style.display = 'inline';
   return(false);
}

function toggle_left_menu(product_category_id,product_category_id_str)
{
	var pc_array = new Array();
	pc_array = product_category_id_str.split('|');
	
	for(x=0;x < pc_array.length;x++)
	{
		document.getElementById('left_category_'+pc_array[x]).style.display = 'none';
	}
	document.getElementById('left_category_'+product_category_id).style.display = 'block';
	return false;
}
function show_product_data(section)
{
	document.getElementById('product_data_summary').style.display = 'none';
	document.getElementById('product_data_contents').style.display = 'none';
	document.getElementById('product_data_features').style.display = 'none';
	document.getElementById('product_data_specification').style.display = 'none';
	document.getElementById('product_data_retail').style.display = 'none';
	
	document.getElementById('summary_button').className='summary_button';
	document.getElementById('contents_button').className='contents_button';
	document.getElementById('features_button').className='features_button';
	document.getElementById('specification_button').className='specification_button';
	document.getElementById('retail_button').className='retail_button';
	
	document.getElementById(section+'_button').className=section+'_button active';
	document.getElementById('product_data_'+section).style.display = 'block';
	return false;
}

function show_feature_tip(txt)
{
	document.getElementById('feature_tip_box').innerHTML = txt; 
}
function process_product_registration()
{
	var error = "";
	if(document.getElementById('title').value=='')
	{
		error+="Please select your title\n";
	}
	if(document.getElementById('first_name').value=='')
	{
		error+="Please enter your first name\n";
	}
	if(document.getElementById('last_name').value=='')
	{
		error+="Please enter your last name\n";
	}
	if(document.getElementById('email').value=='')
	{
		error+="Please enter your email\n";
	}
	if(document.getElementById('address1').value=='')
	{
		error+="Please enter the first line of your address\n";
	}
	if(document.getElementById('postcode').value=='')
	{
		error+="Please enter your postcode\n";
	}
	if(document.getElementById('country').value=='')
	{
		error+="Please enter your country\n";
	}
	if(document.getElementById('product_code').value=='')
	{
		error+="Please enter your product code\n";
	}
	if(document.getElementById('date_of_purchase').value=='')
	{
		error+="Please select the date your purchased your product\n";
	}
	if(document.getElementById('serial_number').value=='')
	{
		error+="Please enter your serial number\n";
	}
	if(document.getElementById('name_of_retailer').value=='')
	{
		error+="Please enter the name of your retailer\n";
	}
	if(document.getElementById('nature_of_use').value=='')
	{
		error+="Please select the nature of use of the product\n";
	}
	
	if(error == "")
	{
		return true;
	}
	else
	{
		alert(error);
		return false;
	}
	
}
function process_trade_account_form()
{
	var error = "";
	switch(document.getElementById('stage').value)
	{
		case "1":
			if(document.getElementById('company_name').value=='')
			{
				error+="Please enter a company name\n";
			}
			if(document.getElementById('company_formation').value=='')
			{
				error+="Please enter the company formation\n";
			}
			if(document.getElementById('trading_name').value=='')
			{
				error+="Please enter a trading name\n";
			}
			if(document.getElementById('main_email').value=='')
			{
				error+="Please enter the primary contact's email address\n";
			}
		break;
		case "2":
			if(document.getElementById('purchasing_contact_name').value=='')
			{
				error+="Please enter a purchasing contact name\n";
			}
			if(document.getElementById('purchasing_contact_tel').value=='')
			{
				error+="Please enter the purchasing contact telephone number\n";
			}
			if(document.getElementById('accounts_contact_name').value=='')
			{
				error+="Please enter a accounts' contact name\n";
			}
			if(document.getElementById('accounts_contact_tel').value=='')
			{
				error+="Please enter the accounts' contact telephone number\n";
			}
		break;
		case "3":
			if(document.getElementById('invoice_country').value=='')
			{
				error+="Please enter your country\n";
			}
		break;
		case "4":
			if(document.getElementById('agree_to_ts_and_cs').checked==false)
			{
				error+="Please indicate that you have read and agree to the terms and conditions of sale\n";
			}
			
		break;
		default:
			error = "";
		break;
		
	}
	if(error == "")
	{
		return true;
	}
	else
	{
		alert(error);
		return false;
	}
}



function generate_support_filters(basepath)
{

	$.ajax({
		type: "POST",
		url: basepath+"/process/generate_support_filters.php",
		data: $("#support_search_form").serialize(),
		success: function(html){
			document.getElementById('support_search_filter_container').innerHTML = html
		}
	});
}
function process_change_password()
{
	var error = "";
	if(document.getElementById('new_password').value=='')
	{
		error+="Please enter your new password\n";
	}
	if(document.getElementById('confirm_password').value=='')
	{
		error+="Please confirm your new password\n";
	}
	if(document.getElementById('new_password').value!='' && document.getElementById('confirm_password').value!='' && document.getElementById('new_password').value != document.getElementById('confirm_password').value)
	{
		error+="Your passwords do not match\n";
	}
	if(error == "")
	{
		return true;
	}
	else
	{
		alert(error);
		return false;
	}
}

function submit_login_form(basepath,site_section_name)
{
	$.ajax({
		type: "POST",
		url: basepath+"/process/submit_login_form.php",
		data: $("#login_form").serialize(),
		success: function(html){
			if(html == "1")
			{
				location.href=basepath+'/'+site_section_name;
			}
			else
			{
				location.href=basepath+'/'+site_section_name+'/login_error';
			}
		}
	});
	return false;
}

function search_suggest(basepath,site_section_id)
{

	$.ajax({
		type: "POST",
		url: basepath+"/process/live_search.php",
		data: $("#search_text").serialize(),
		success: function(html){
			var a = new Array();
			a = html.split('|');
			if(a[0]==1)
			{		
				document.getElementById('live_search_results').style.display = 'block';
				document.getElementById('live_search_results').innerHTML = a[1]
			}
			else
			{
				document.getElementById('live_search_results').style.display = 'none';
			}
		}
	});
}
function open_login_form(basepath,site_section_name)
{
document.getElementById('login_btn').innerHTML="<a href=\"javascript:void(0);\" onclick=\"close_login_form('"+basepath+"','"+site_section_name+"');\"><img src=\""+basepath+"/image/login_close_"+site_section_name+".gif\" /></a>";
	
	
	$("#login_btn").click(function(){
      $("#login_form_drop_down").animate({ 
        height: "108px"
      }, 200 );
    });
    document.getElementById('login_form_drop_down').style.display = 'block';
    
}
function close_login_form(basepath,site_section_name)
{

document.getElementById('login_btn').innerHTML="<a href=\"javascript:void(0);\" onclick=\"open_login_form('"+basepath+"','"+site_section_name+"');\"><img src=\""+basepath+"/image/login_"+site_section_name+".gif\" /></a>";
    
	$("#login_btn").click(function(){
      $("#login_form_drop_down").slideUp("slow");
    });
    document.getElementById('login_form_drop_down').style.display = 'none';
    jQuery.fx.off = true;
}


function show_home_trans(dir)
{
	$("#home_trans_text_"+dir).slideDown("slow");
}
function hide_home_trans(dir)
{
	$("#home_trans_text_"+dir).slideUp("slow");
}
function get_object(id) {
			var object = null;
			if( document.layers )	{			
				object = document.layers[id];
			} else if( document.all ) {
				object = document.all[id];
			} else if( document.getElementById ) {
				object = document.getElementById(id);
			}
			return object;
		}
		function is_child_of(parent, child) {
			if( child != null ) {			
				while( child.parentNode ) {
					if( (child = child.parentNode) == parent ) {
						return true;
					}
				}
			}
			return false;
		}
		function fixOnMouseOut(element, event, JavaScript_code) {
			var current_mouse_target = null;
			if( event.toElement ) {				
				current_mouse_target 			 = event.toElement;
			} else if( event.relatedTarget ) {				
				current_mouse_target 			 = event.relatedTarget;
			}
			if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
				eval(JavaScript_code);
			}
		}