function showTooltip(name, e) {
	var elem = $(name + 'Tooltip');
	elem.style.visibility = 'visible';

	if(e.clientX > screen.width) {
		elem.style.left = screen.width + 'px';
	} else {
		elem.style.left = e.clientX + 20 + 'px';
	}

	elem.style.top = e.clientY + 'px';
}

function hideTooltip(name) {
	$(name + 'Tooltip').style.visibility = 'hidden';
}

function checkNewPageForm(f) {
	var error = '';

	with(f) {
		if(isEmpty(page_name)) {
			error += "Niste vnesli ime spletne strani!\n";
		}

		if(isEmpty(page_title)) {
			error += "Niste vnesli naslov (title) spletne strani!\n";
		}
	}

	if(error != '') {
		alert("Opozorilo:\n\n" + error);
		return false;
	}

	return true;
}

function redirect(url) {
	location.href = url;
}

function isEmpty(elem) {
	return (elem.value == '');
}

function isEmail(email) {
	if(email && typeof email == 'object') email = email.value;

	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}

function OpenWindow(url, width, height, top, left) {
	if(top == undefined) top = 0;
	if(left == undefined) left = 0;
	if(width == undefined) width = 820;
	if(height == undefined) height = 880;

	var win = window.open(url, "",'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+ height +',top='+top+',left='+left);
}

function popUp(url, width, height, top, left) {
	OpenWindow(url, width, height, top, left);
}

function openInvoiceWindow(url) {
	var win = window.open(url, "",'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=800,height=880,top=0,left=0');
}

function customWindow(url) {
	OpenWindow(url, 660, 500, 0, 0);
}

function AjaxGetter(url) {
	$('loaderDiv').style.visibility = 'visible';
	$('loaderDiv').innerHTML = "<div class='loader_div'><img src='images/ajax-loader.gif' align='absmiddle'></div>";
	
	var options = {
		asynchronous: true,
		method:'get',
		onSuccess: function(transport){
  			var response = transport.responseText || "no response text";
  			$('loaderDiv').innerHTML = '';
			$('loaderDiv').style.visibility = 'hidden';
    	},
    	
    	onFailure: function(){ alert('Something went wrong...') }
	}
	
	new Ajax.Request(url, options);

}

function checkRegisterForm(f) {
	var error = '';

	with(f) {
		if(isEmpty(first_name)) {
			error += "Prosimo vnesite ime!\n"
		}

		if(isEmpty(last_name)) {
			error += "Prosimo vnesite priimek!\n"
		}

		if(isEmpty(address)) {
			error += "Prosimo vnesite naslov!\n"
		}

		if(isEmpty(city)) {
			error += "Prosimo vnesite mesto!\n"
		}

		if(isEmpty(zip)) {
			error += "Prosimo vnesite poštno št.!\n"
		}

		if(isEmpty(telephone)) {
			error += "Prosimo vnesite kontaktno telefonsko št.!\n"
		}

		if(isEmpty(email)) {
			error += "Prosimo vnesite email!\n";
		}
		else {
			if(!isEmail(email)) {
				error += "Vpisani email ni pravilen (format)!\n"
			}
		}

		if(isEmpty(email2)) {
			error += "Prosimo vnesite 'ponovljen' email!\n";
		}
		else {
			if(!isEmail(email2)) {
				error += "Ponovljeni email naslov ni pravilen (format)!\n"
			}
		}

		if(email.value != email2.value) {
			error += "Vpisana email naslova se ne ujemata!";
		}
	}

	if(error != '') {
		alert("U-Grooves opozorilo: \n\n" + error);
		return false;
	}

	return true;
}

function copyBillingToDelivery() {
	var forma = document.forms.enterAddress;
	if(forma.sameAddress.checked) {
		forma.shipping_name.value = forma.customer_name.value;
		forma.shipping_company.value = forma.customer_company.value;
		forma.shipping_street_address.value = forma.customer_street_address.value;
		forma.shipping_zip.value = forma.customer_zip.value;
		forma.shipping_city.value = forma.customer_city.value;
		forma.shipping_country_id.value = forma.customer_country_id.value;
	}
	else {
	}

}

function checkTellafriend(f) {
	var error = '';

	with(f) {
		if(isEmpty(prejemnik_email)) {
			error += "Prejemnikov email prosim!\n";
		}
		else {
			if(!isEmail(prejemnik_email)) {
				error += "Prejemnikov email ni pravilen (format)!\n"
			}
		}

		if(isEmpty(posiljatelj_email)) {
			error += "Tvoj email prosim!\n";
		}
		else {
			if(!isEmail(posiljatelj_email)) {
				error += "Tvoj email ni pravilen (format)!\n"
			}
		}

		if(isEmpty(ht_code)) {
			error += "Anti spam kodo prosim!?\n";
		}
	}

	if(error != '') {
		alert("U-Grooves opozorilo: \n\n" + error);
		return false;
	}

	return true;
}

function checkDetailsForm(f) {
	var error = '';

	with(f) {
		if(isEmpty(shipping_name)) {
			error += "Ime za dostavo!?\n";
		}

		if(isEmpty(shipping_street_address)) {
			error += "Naslov za dostavo!?\n";
		}

		if(isEmpty(shipping_zip)) {
			error += "Poštna št. za dostavo!?\n";
		}

		if(isEmpty(shipping_city)) {
			error += "Mesto za dostavo!?\n";
		}
	}

	if(error != '') {
		alert("U-Grooves opozorilo: \n\n" + error);
		return false;
	}

	return true;
}

function checkPozabljenoGesloEmail(f) {
	error = "";

	if(isEmpty(f.pozab_email)) {
		error += "Email naslov prosim!?";
	}
	else {
		if(!isEmail(f.pozab_email)) {
			error += "To ni email naslov!?";
		}
	}

	if(error != '') {
		alert("U-Grooves opozorilo: \n" + error);
		return false;
	}

	return true;

}

function checkLoginForm(f) {
	error = "";

	if(isEmpty(f.email)) {
		error += "Email naslov prosim!?\n";
	}
	else {
		if(!isEmail(f.email)) {
			error += "To ni email naslov!?\n";
		}
	}

	if(isEmpty(f.pass)) {
		error += "Geslo prosim!?\n";
	}

	if(error != '') {
		alert("U-Grooves opozorilo: \n\n" + error);
		return false;
	}

	return true;
}

function checkAnketa(f) {
	var check = false;
	var len = f.answer_id.length;

	for(var i = 0; i < len; i++)
		if(f.answer_id[i].checked == true)
   			check = true;

	if(!check) {
		alert("Niste izbrali odgovor!");
		return false;
	}

	return true;
}

function checkuploadform(f) {
	error = "";

	if(isEmpty(f.author_name)) {
		error += "Vpišite vaše ime (ali nickname)!\n";
	}
	
	if(isEmpty(f.author_email)) {
		error += "Vpišite email naslov (ni viden na spletni strani)!\n";
	}
	else {
		if(!isEmail(f.author_email)) {
			error += "To ni email naslov!?\n";
		}
	}
	
	if(isEmpty(f.author_location)) {
		error += "Vpišite iz katerega kraja ste (vsaj približno)!\n";
	}
	
	if(isEmpty(f.photo_file)) {
		error += "Kaj pa slika!?\n";
	}

	if(error != '') {
		alert("U-Grooves opozorilo: \n\n" + error);
		return false;
	}

	return true;
}

function ToggleMenu(innerDiv, onoffimg) {
	if(onoffimg.src.match('expand.png')) {
		innerDiv.appear({ duration: 0.0 });
		onoffimg.src = 'images/contract.png';
	}
	else {
		innerDiv.hide();
		onoffimg.src = 'images/expand.png';
	}
	
	return false;
}


function ToggleMenuHideAll(itemNum, allbut) {
	
	var tst = "";
	for(var i = 0; i<=itemNum; i++) {
		if($("item"+i)) {
			$("item"+i).hide();
			
			if($("onoffpic"+i) != null) {
				$("onoffpic"+i).src = 'images/expand.png';
			}
			
			if(i && i == allbut && allbut > 0) {
				$("item"+i).appear({ duration: 0.0 });
			
				if($("onoffpic"+i) != null) {
					$("onoffpic"+i).src = 'images/contract.png';
				}
			}
		}
	}
	
	return false;
}

function checkNagradnaForm(forma) {
	var _checked;
	for(i=0;i<forma.odgovor.length;i++) {
		if(forma.odgovor[i].checked) {
			_checked = true;
		}
	}
	
	if(!_checked) {
		alert('Niste izbrali odgovor!?');
		return false;
	}
	
	return true;
}
