// Copyright 2006-2007 javascript-array.com
var timeout	= 200;
var closetimer	= 0;
var ddmenuitem	= 0;
var store = "category";

$(document).ready(function() {

	$(".minicartBottom").corner(
			{  tl:{radius:0}, tr:{radius:0}, bl:{radius:5}, br:{radius:5}, antiAlias:true, autoPad:false, validTags: ["div"] } );

	$(".headSearchBox").corner(
			{  tl:{radius:5}, tr:{radius:5}, bl:{radius:5}, br:{radius:5},antiAlias:true, autoPad:false, validTags: ["div"]  } );
	
	$(".headSearchBoxCont").corner(
			{  tl:{radius:6}, tr:{radius:6}, bl:{radius:6}, br:{radius:6},antiAlias:true, autoPad:false, validTags: ["div"]  } );

	$("#menu").corner(
			{  tl:{radius:4}, tr:{radius:4}, bl:{radius:0}, br:{radius:0},antiAlias:true, autoPad:false, validTags: ["div"]  } );

	if(document.getElementById('searchInput').value!=searchInputDefaultText )
	{
		$("#searchInput").removeClass('search_off');
		$("#searchInput").addClass('search_on');
	}
});

//open hidden layer
function menuopen(id, cate_cd)
{
	/*if(cate_cd == 0)
		document.getElementById("innerd").innerHTML = document.getElementById("generatedMenu_brands").innerHTML; 
	else
		document.getElementById("innerd").innerHTML = document.getElementById("generatedMenu_"+cate_cd).innerHTML;
	*/
	var x = document.getElementById("ddd_"+cate_cd).offsetLeft;

	document.getElementById("innerc").style.left = x+"px";
	document.getElementById("submenu_configs").style.width = document.getElementById("main").offsetWidth - 2 + "px";
	document.getElementById("submenu_configs").style.left = 0+"px";

	var cate_cdW = document.getElementById("ddd_"+cate_cd).offsetWidth + 3;

	document.getElementById("innerc").style.width = cate_cdW + "px";
	document.getElementById('innerc').innerHTML = document.getElementById('ddd_'+cate_cd).innerHTML;

	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem)
		ddmenuitem.style.display = 'none';

	setTimeout( "fixSize("+x+")" , 85);

	ddmenuitem = document.getElementById(id);
//	$("#"+ddmenuitem.id).fadeIn(128);
}

//===================
function fixSize(xval) {
	var wtest = xval + document.getElementById("innerd").offsetWidth;

	if(wtest > document.getElementById("main").offsetWidth) {
		lcorrect = wtest - document.getElementById("main").offsetWidth;
		document.getElementById("innerd").style.right ="0px";
		document.getElementById("innerd").style.left ="auto";
	} else {
		document.getElementById("innerd").style.left =xval+"px";
		document.getElementById("innerd").style.right ="auto";
	}
}

// close showed layer
function mclose()
{
	if(ddmenuitem)
		$("#"+ddmenuitem.id).hide();
}

//go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

//cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

var aBgAreas=new Array();
aBgAreas[0]="Loja";
aBgAreas[1]="Outlet";
aBgAreas[2]="Escalada";
aBgAreas[3]="Festas";
aBgAreas[4]="Viagens";
aBgAreas[5]="VendaCorporativa";
//====================
function buttonOver(area, classSuffix )
{
	$(area).removeClass('spr_menu_'+classSuffix);
	$(area).addClass('spr_menu_'+classSuffix+'_off');
}
//====================
function buttonOut(area, classSuffix )
{
	$(area).removeClass('spr_menu_'+classSuffix+'_off');
	$(area).addClass('spr_menu_'+classSuffix);
}
//================
function resetArea( areaBgImg, areaname )
{
	areaBgImgElement = "AreaBg"+areaBgImg;
	var atext = "#AreaText"+ areaBgImg;
	document.getElementById( areaBgImgElement ).src = webpath+"/themes/"+theme+"/images/header/menu/"+areaname+"/bg_button.png";
	$(atext).toggleClass("btTextLinkb");
}
function toogleCart()
{
	if( stricter.accessCSS( "popCart" ).display=="none" ) {
		$("#popCart").slideDown( 250 );
		stricter.ajax.get(webpath+'/cart/show/','popCart');
	} else {
		$("#popCart").slideUp( 180 );
	}
}
function resetSearch(inp)
{
	if(inp.value == searchInputDefaultText){
		inp.value="";
		$(inp).removeClass('search_off');
		$(inp).addClass('search_on');
	}
}
function checkSearch(inp)
{
	if(inp.value==""){
		inp.value = searchInputDefaultText;
		$(inp).removeClass('search_on');
		$(inp).addClass('search_off');
	}	
}
function cep() {
	stricter.ajax.post(webpath+'/customer/addressByPostalCode', 'ajaxaddr', 'usrform');
}
function toogleUserType(type){
	if(type==1){
		$("#flabel_user_nm").html("Nome completo *:");
		$("#flabel_user_alias").html("Apelido:");
		$("#flabel_user_code1").html("CPF *:");
		$("#flabel_user_code2").html("RG *:");
		$('#fbox_genre_born').show(300);
	} else{
		$("#flabel_user_nm").html("Razão Social *:");
		$("#flabel_user_alias").html("Nome Fantasia:");
		$("#flabel_user_code1").html("CNPJ *:");
		$("#flabel_user_code2").html("IE *:");
		$('#fbox_genre_born').hide(300);
	}
}
function printBill(id)
{
	window.open(webpath+'/orders/printBill/'+id,'orderwindow', 'width=816,height=500,addressbar=no,scrollbars=yes');
}
function printOrder(id)
{
	window.open(webpath+'/orders/printOrder/'+id,'orderwindow', 'width=816,height=500,addressbar=no,scrollbars=yes');
}

