// JavaScript Document

var site_url = "http://esperanza.ch/";

function getVar(name)
{
	get_string = document.location.search;         
	return_value = '';

	do { //This loop is made to catch all instances of any get variable.
		name_index = get_string.indexOf(name + '=');       
		if(name_index != -1)
		{
			get_string = get_string.substr(name_index + name.length 
				+ 1, get_string.length - name_index);

				end_of_value = get_string.indexOf('&');
				if(end_of_value != -1)                
				value = get_string.substr(0, end_of_value);                
				else                
				value = get_string;                

				if(return_value == '' || value == '')
				return_value += value;
				else
				return_value += ', ' + value;
			}
			} while(name_index != -1)

			//Restores all the blank spaces.
			space = return_value.indexOf('+');
			while(space != -1)
			{ 
				return_value = return_value.substr(0, space) + ' ' + 
				return_value.substr(space + 1, return_value.length);

				space = return_value.indexOf('+');
			}

			return(return_value);        
		}

// scrolling cart functions

function setPos(Obj,Id)
{
	var coors = findPos(Obj);
	var x = document.getElementById(Id);
	window.alert(coors);
	x.style.postion = 'fixed'; 
	x.style.top = coors[1] + 'px';
	x.style.left = coors[0] + 'px';
}


function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function popupPartner() {
	window.open(site_url+document.partners.select.value,"partners","directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=280,height=300");
}

function highlightPartner() {
	var id = getVar('id');
	document.getElementByID(id).style.color="#ff0000";
	window.location.href = "index.html#"+id;
}

function showId(itemid) {
	document.getElementById(itemid).style.display="block";
}

function hideId(itemid) {
	document.getElementById(itemid).style.display="none";
}


function goToId(checkId,goId) {
	if(	document.getElementById(checkId)) {
		document.location.href = "#"+goId;		
	}
}


function checkRange(aVal,aMin,aMax,trueMsg,falseMsg,focusPoint) {
		//x7
		v = Math.floor(aVal);
		min = Math.floor(aMin);
		max = Math.floor(aMax);
		if ( v >= min && v <= max) {
			if(trueMsg != "") window.alert(trueMsg);
		}
		else {
			if(falseMsg != "") window.alert(falseMsg);
			focusPoint.focus();
		}
}


function clickLink(linkobj) {
     if (linkobj.getAttribute('onclick') == null) {
          if (linkobj.getAttribute('href')) document.location = linkobj.getAttribute('href');
     }
     else linkobj.onclick();
}

