function $() 
	{   
		if (arguments.length>1) 
			{
				return false;
			}
		if (arguments.length<1) 
			{
				return false;
			}
		var element = arguments[0];
		if (typeof element == 'string') 
			{
				if (document.getElementById) 
					{
						element = document.getElementById(element);           
					}
				else if (document.all) 
					{
						element = document.all[element];
					}
			}
		return element;
	}

function focusOn(elem)
	{
		elem.style.border = "1px #FEB400 solid";
	}

function focusOff(elem)
	{
		elem.style.border = "1px #939393 solid";
	}

function setFocus(elem)
	{
	    try {
		document.getElementById(elem).focus();
		} 
		catch(ex){
		}
	}

//<![CDATA[
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
//]]>

function changeLanguage( lang )
{
    
    if($("ctrlHeader_hLang")!=lang)
    {
        $("ctrlHeader_hLang").value = lang;
        $("ctrlHeader_hAction").value = "ChangeLanguage";
        $("frmMain").submit();
    }

}

function toggleMenuSelection(subl)
	{
		var i=1;
		if (document.getElementById(subl).className=='lisub dB') 
			{
				document.getElementById(subl).className='lisub dN';
			}
		else if (document.getElementById(subl).className!='lisub dB')
				{
					while (document.getElementById("subl"+i)!=null) 
					{ 					   
					    document.getElementById('subl'+i).className='lisub dN';
						i++;
					}
					document.getElementById(subl).className='lisub dB';		
				}
	}

function doSearch()
{
	/*if($("txCautare") && $("txCautare").value.replace(/[\s]+$/g,"") != "" )
        searchText = $("txCautare").value.replace(/[\s]+$/g,"");
    else*/
        searchText = $("txSearch").value.replace(/[\s]+$/g,"");
    if(searchText != "")
       document.location = "cautare.aspx?search="+searchText;
}

function doSearchPage()
{
	//if($("txCautare") && $("txCautare").value.replace(/[\s]+$/g,"") != "" )
        searchText = $("txCautare").value.replace(/[\s]+$/g,"");
   /* else
        searchText = $("Header_txCautare").value.replace(/[\s]+$/g,"");*/
  if(searchText != "")
        document.location = "cautare.aspx?search="+searchText;
}

function search_clearText() {
    if ($("txSearch").value=="cerca" ) {
        $("txSearch").value = "";
        search_wasCleared = true;
    }
}

function search_showText() {
    if (search_wasCleared && trim($("txSearch").value).length == 0) {
        $("txSearch").value = "cerca";
        search_wasCleared = false;
    }
}

function searchPage_clearText() {
    if ($("txCautare").value=="cerca" ) {
        $("txCautare").value = "";
        searchPage_wasCleared = true;
    }
}

function searchPage_showText() {
    if (searchPage_wasCleared && trim($("txCautare").value).length == 0) {
        $("txCautare").value = "cerca";
        searchPage_wasCleared = false;
    }
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function ChangeFont(font,id) {
    document.getElementById(id).value = font;
    document.getElementById('frmMain').submit();
}

function changePicture(idx, path, alt, title, largePhotoPath)
{
    $("photo0").className = 'thumbnail';	
	$($("hSelectedPhoto").value).className = 'thumbnail';
	$("hSelectedPhoto").value = 'photo' + idx;
	$($("hSelectedPhoto").value).className = 'thumbnail selected';
	if(idx == 3){	$($("hSelectedPhoto").value).className = 'thumbnail last selected';}
	else { if ($("photo3") != null) {$("photo3").className = 'thumbnail last';}}
	
	$("productImgLarge").src = path;
    $("productImgLarge").alt = path;
    $("productImgLarge").title = path;
    $("photoLarge").href = largePhotoPath;
}

//jQuery.noConflict();

jQuery(function($) { 
	
	/*
	 * Navigation Animation
	 */
	var nav = $('#menu');
	var active = nav.find('li.selected');
	
	//Setting active classes
	active.parents('li').addClass('selected');
	
	//Hiding non active elements
	nav.find('li').not('.selected').find('>ul').hide();
	
	//Hiding empty ul tags
	nav.find('ul:has(a)').addClass('full');
	nav.find('ul').not('.full').hide();
	
	//Setting a click event on level 1 & 2 links
	//which will return false as only lvl 3 links are real
	var a = nav.find('>li>a');
	a.click(function(){
		var li = $(this).parent();
		
		if (li.is('.selected')) {
		    $('ul',li).slideUp('fast');
		    li.removeClass('selected');
		} else {
		
		    //Hiding other branches
		    var siblings = li.siblings();
		    siblings.find('>ul').slideUp('fast');
    		
		    //Removing the 'active' class from the other branches
		    siblings.removeClass('selected');
    		
//	   		li.find('>ul:has(a)').addClass('full');	
    		
		    //Showing this particular branch
		    if (li.find('>ul').is('.full')) {
		        li.find('>ul').slideDown('fast');
		    } else {
		        li.find('>ul').hide();
		    }
    		
		    //Setting the 'active' class
		    li.addClass('selected');	    
		}
		
		//Returning false as this link has only animation purposes
		var children = li.find('a');
		if (children.length != 1) {
		    return false;    		
		}
	});

});
