function toggleScroll(idClass)
{
	$.scrollTo(idClass, 1000);
}

function toggleCategory(id)
{	

	test2 = location.hash;
	test2 = test2.replace('#', '');
	if ( test2.indexOf('|') > 0 ) {
		models = test2.split('|');
		
		test2	= models[0];
	}

	test = id.replace('cat_', '');
	createCookie('gpCookie', test2 + '|' + test, 1);

	if ($('#' + id).css('display') == 'none')
	{
		x = $('#' + id).attr('class');
		$('.td_' + x).css('background-image', 'url(images/partcat_panel_desel.gif)');
		$('.link_' + x).css('color', '#464E63');
		$('.' + x).hide();
	}
	
	if ($('#' + id).css('display') == 'none')
	{
		$('#td_' + id).css('background-image', 'url(images/partcat_panel_sel.gif)');
		$('#link_' + id).css('color', '#FFF');
		$('#' + id).show();
	} 
	else 
	{
		$('#td_' + id).css('background-image', 'url(images/partcat_panel_desel.gif)');
		$('#link_' + id).css('color', '#464E63');
		$('#' + id).hide();
	}
}

function toggleModel(id)
{
	if ($('#' + id).css('display') == 'none') {
		$('.goparts-products').hide();
		$('#' + id).show();
	} else {
		$('#' + id).hide();
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setScroll(hash)
{
	if (hash != '')
	{
		model = null;
		makes	= hash.replace('#', '');
		
		createCookie('gpCookie', makes, 1);
		
		if ( makes.indexOf('|') > 0 ) {
			model = makes.split('|');
			
			makes	= model[0];
			model = model[1];
		}
		
		if (model != null) {
			toggleCategory('cat_' + model);
		}
		
		attr = $('.link_' + makes).attr('id');
		attr = attr.replace('a_', '');
		if (attr != '') {
			toggleModel(attr);
		}
		
		toggleScroll('.' + makes);
	}
}

function setRefresh()
{
	setInterval('setAjax()', 60000);
}

function setAjax()
{
		$.ajax({
			type: "GET",
			url: 	window.location.href,
			dataType: "html"
		});
}

function show_edit_form()
{
	$('.form-overlay').show();
	$('.form-content').show();
}

function hide_edit_form()
{
	$('.form-overlay').hide();
	$('.form-content').hide();
}

function show_result()
{
	var val = "";
	$(':checkbox:checked').each(function(i){
		if (val != "")
			val += ",";
		
		val += $(this).val();
	});
}

function submit_products()
{
	show_edit_form();
	$.post("edit_product.php", $("#edit_product").serialize(), function(data) { $('.form-content').html(data); });
}

function confirmEdit()
{
	$.post("edit_product.php", $("#edit_product_form").serialize(), function(data) { $('.form-content').html(data); });	
}

function productSave()
{
	$.post("edit_product.php", $("#edit_product_form_save").serialize(), function(data) { $('.form-content').html(data); });	
}

function openPanel(id)
{
	$("#" + id).slideToggle();
}

function addMetaField()
{
	var field = '<textarea name="meta[]"></textarea>';
	$('.fields').append(field);
}

function saveMetaTag()
{
	$.post("gopart_ajax.php", $("#editmetatag").serialize(), function(data) { openPanel('metaTag'); });
}

function saveProductContent()
{
	$.post("gopart_ajax.php", $("#editproductcontent").serialize(), function(data) { openPanel('productInfo'); });	
}

function saveTitlePage()
{
	$.post("gopart_ajax.php", $("#editpagetitle").serialize(), function(data) { openPanel('titlePage'); });	
}

function saveProductImgAlt()
{
	$.post("gopart_ajax.php", $("#editproductalt").serialize(), function(data) { openPanel('productAltImage'); });	
}