//var siteURL = '/northlandconstruction.com/';
var siteURL = '/';
var idDiv;
	
function fnHide(id)
{
	idDiv=document.getElementById(id);
	idDiv.style.display="none";
}

function fnDisplay(id)
{
	idDiv=document.getElementById(id);
	idDiv.style.display="block";
}


function doCategories()
{

	var selectlist = document.getElementById("section");
	var sect = selectlist.options[selectlist.selectedIndex].value;

	if ((sect == null) || (sect == 0)) return;

	var url = 'cats.php?sect=' + sect;

	$("#catselect").load(url);
	
}

function doSubCategories()
{

	var selectlist = document.getElementById("category");
	var sect = selectlist.options[selectlist.selectedIndex].value;

	if ((sect == null) || (sect == 0)) return;

	var url = 'cats.php?sub=true&sect=' + sect;

	$("#subcatselect").load(url);
	
}



function gotoCat()
{

	var submitbtn = document.getElementById("searchbtn");
	submitbtn.disabled = true;


	var selectlist = document.getElementById("category");
	var cat = selectlist.options[selectlist.selectedIndex].value;

	if ((cat == null) || (cat == 0)) return;

	var url = siteURL + cat + '/';

	window.location= url;	
}


function gotoMan()
{

	var selectlist = document.getElementById("supplier");
	var man = selectlist.options[selectlist.selectedIndex].value;

	if ((man == null) || (man == 0)) return;

	var url = 'product.php?man=' + man;

	window.location= url;	
}

function gotoSubcat()
{

	var submitbtn = document.getElementById("searchbtn");
	submitbtn.disabled = true;


	var catselectlist = document.getElementById("category");
	var cat = catselectlist.options[catselectlist.selectedIndex].value;

	var subselectlist = document.getElementById("thesubcat");
	var subcat = subselectlist.options[subselectlist.selectedIndex].value;

	if ((subcat == null) || (subcat == 0)) return;


	if(subcat == "ALL")
	{
		var url = siteURL + cat + '/?p=ALL';
	
	} else {

		//var url = 'product.php?cat=' + cat + '&sub=' + subcat;
		var url = siteURL + cat + '/' + subcat + '/';
	}

	window.location= url;
	
	
}


function confirmDelete()
{
	var agree = confirm("Are you sure you want to DELETE this record?");

	if (agree)
		return true ;
	else
		return false ;
}




$(document).ready(function() {


	$('a[rel=external]').click(function(){
		window.open( $(this).attr('href') );
		return false;
	});


	if($('.alertsitems').length>0)
	{
		$('.alertsitems').cycle({
			timeout: 4000,
			speed: 500,
			pause: true	
		});

	}


	$(".expand a").click(function() {
		return false;
	});


	$("#morelink").toggle(function() {
		$("#moreprod").show('fast');
	},function(){
		$("#moreprod").hide('slow');
	});


	$("ul.sectioninfo").hide();
	
	$(".expandcat a").toggle(function() {
		$(this).parent().parent().parent().next("ul.sectioninfo").show();
	},function(){
		$(this).parent().parent().parent().next("ul.sectioninfo").hide();
	});
		

	$("#allmap a:eq(0)").click(function() {
		$("ul.sectioninfo").show();
	});

	$("#allmap a:eq(1)").click(function() {
		$("ul.sectioninfo").hide();
	});



	$('.categories ul li :checkbox').click(function(){

		var catid;
		var action;

		if($(this).is(':checked'))
		{
			//alert("Please feature id => " + $(this).attr('value'));
			catid = $(this).attr('value');
			action = 'feature';
		} else {
			//alert("Please UNfeature id => " + $(this).attr('value'));
			catid = $(this).attr('value');
			action = 'unfeature';
		}


		$.post("/admin/featured.php", 
			{ catid: catid, action: action }		
		);
			
			
	});




	$('a[rel=inspirations]').click(function(){
		window.open(this.href,'newwindow','status=1,toolbar=0,scrollbars=0,resizable=1,width=860,height=580');
		return false;
	}); 




	if($('#sidebanner').length > 0)
	{
		$.getScript(siteURL + "js/swfobject.js", function() {

		
			if (swfobject.hasFlashPlayerVersion("9.0.0")) 
			{
				
				var flash_vars = {  };
				var params = {  };
				var attributes = {  };
			
				swfobject.embedSWF(siteURL + "flash/sidebanner.swf", "sidebanner", "100%", "100%", "9.0.0", siteURL + "flash/expressInstall.swf", flash_vars, params, attributes);
		
			}



		
		});

	}



});


function formatItem(row) {
	return row[0] + "<br><i>" + row[1] + "</i>";
}

function selectItem(li) {
	if (li.extra) {

		$('#related').append('<p><input type="text" name="related[]" class="autocomplete" size="40"><input type="hidden" name="relatedid[]" value="' + li.extra[1] + '">&nbsp;[&nbsp;<a href="javascript:void(0)" onclick="$(this).parent(\'p\').remove();">del</a>&nbsp;]</p>');

		$(".autocomplete").autocomplete("moreprod.php",{ minChars:2, matchContains:1, maxItemsToShow:20, formatItem:formatItem, onItemSelect:selectItem, width:400 });

	}
	
}


function addFlash(flashfile,divid,extra) {
	document.getElementById(divid).innerHTML = "<object type='application/x-shockwave-flash' data='flash/" + flashfile + "' width='100%' height='100%' /><param name='movie' value='flash/" + flashfile + "' /><param name='menu' value='false' /><param name='quality' value='high' />" + extra + "</object>";
}


function PopUp(url,width,height) {
	var PopWindow = window.open(url,"PopWindow","height=" + height + ",width=" + width + ",directories=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes");
	PopWindow.focus();
}





