/**
* Custom functions for the Casandra Redesign v2 project
*
* @author       alexander rinass
* @copyright    triple-i new media system design gmbh
* @version      2.0.0
* @package    	casandra redesign v2
*/

/**
* Product sub groups array used in extended search
*/
var product_subgroups = new Array();

/**
* This function will be called after all page code has been loaded (onload=)
*/
function InitPage()
{
}

function ShowSubNav(li)
{
	if(document.getElementById) {
		var ul 		= li.getElementsByTagName('ul');

		if(ul.length==1){
			ul[0].className	= 'secondlayer';
		}
	}
}

function HideSubNav(li)
{
	if(document.getElementById) {
		var ul 		= li.getElementsByTagName('ul');

		if(ul.length==1){
			ul[0].className	= '';
		}
	}
}


function ShowNav()
{
	if(document.getElementById) {
		var nav 	= document.getElementById('nav');
		var ul 		= nav.getElementsByTagName('ul');
		
		if(ul[0].className=='firstlayer'){
			HideNav();
		}else{
			ul[0].className	= 'firstlayer';
			
			var select 		= document.getElementsByTagName('select');
			for(var i=0;i<select.length;i++){
				select[i].style.visibility = 'hidden';
			}
		}
	}
	
	return false;
}

function HideNav()
{
	if(document.getElementById) {
		var nav = document.getElementById('nav');
		var ul = nav.getElementsByTagName('ul');
		
		for(var i=0;i<ul.length;i++){
			ul[i].className	= '';
		}
		
		var select 		= document.getElementsByTagName('select');
		for(var i=0;i<select.length;i++){
			select[i].style.visibility = 'visible';
		}
	}
}

/**
* show online help in cart modes
*
* @param	mixed		link object
*/
function ShowHelp(link)
{
	if(!document.getElementById) return false;
	
	var span	= link.getElementsByTagName('span');
	
	if(span[0]){
		if(span[0].className!='helpshow'){
			span[0].className	= 'helpshow';
		}else{
			span[0].className	= 'nodisplay'
		}
	}
	
	if(link.blur){
		link.blur();
	}
	
	return false;
}

/**
* simulates target blank in an accessible way
*
* use links: <a href="http://www.triple-i.de" onclick="return TargetBlank(this.href)">Link</a>
*
* @param	string		url
* @return	boolean		always false
*/
function TargetBlank (url) {
	var newwindow	= window.open(url, "newwindow","menubar=yes,location=yes,status=yes,scrollbars=yes,toolbar=yes,resizable=yes");
	newwindow.focus();
	return false;
}

/*
* Changes the current page to the one selected by the
* select field in the product list view
*
* @param    integer  number of page to jump to
*/
function ChangePage(Page,UrlStart,UrlEnd)
{
	document.location.href	= UrlStart+Page+UrlEnd;
}

/**
* Create popup with zoomed product image version
*
* @param    string  	url of zoom
*/
function OpenZoom(url)
{
	var popup	= window.open(url, "popup","width=500,height=550,menubar=yes,location=yes,status=yes,scrollbars=yes,toolbar=yes,resizable=yes");
	popup.focus();
	return false;
}

/*
* Changes the current URL to the one selected by the
* select field in the header
*/
function ChangeUrl()
{
	var url=document.forms['miscpages'].miscpages.value;
	if(url=='') { return; }
	else { document.location.href=url; }
}

/*
* Load sub group of a product group (extended search)
*
* @param    integer  main product group id
*/
function LoadProductSubGroups(id)
{
	var list_name = 'productsubgroups[]';
	_clearList(list_name);
	if(product_subgroups[id]=='') { 
		_addListEntry(list_name,'(Keine weiteren',-1);
		_addListEntry(list_name,'Gruppen verfügbar)',-1);
	} else {
		for (var id_subgroup in product_subgroups[id]) {
			var title = ReconvertHtmlSpecialChars(product_subgroups[id][id_subgroup]);
			_addListEntry(list_name,title,id_subgroup);
		}
	}
}

/*
* Reconverts HTML special chars.
*
* @param    string  string to convert
* @returns  string  converted string
*/
function ReconvertHtmlSpecialChars(str) {
  str=str.replace(/&auml;/g,'ä');
  str=str.replace(/&Auml;/g,'Ä');
  str=str.replace(/&uuml;/g,'ü');
  str=str.replace(/&Uuml;/g,'Ü');
  str=str.replace(/&ouml;/g,'ö');
  str=str.replace(/&Ouml;/g,'Ö');
  str=str.replace(/&lt;/g,'<');
  str=str.replace(/&gt;/g,'>');
  str=str.replace(/&quot;/g,'"');
  str=str.replace(/&szlig;/g,'ß');
  str=str.replace(/&euro/g,'€');
  str=str.replace(/&amp;/g,'&');
  return str;
}

//eof