var ROOT_URL = "http://www.bnc-charter.com/";


//********************************************************
// WISH LIST
//********************************************************
function getCookie(c_name) {
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length
	    return unescape(document.cookie.substring(c_start,c_end));
	    } 
	  }
	return null;
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	
	var old_value = getCookie(c_name);
	var new_value = c_name+ "=";
	if (old_value != null){
		new_value = new_value +escape(old_value);
	}
	new_value = new_value +escape("_"+value+";")+ ((expiredays==null) ? "" : ";expires="+exdate)+ ";path=/";
	document.cookie= new_value;
	window.location = ROOT_URL + "wish-list.php";
}

function removeFromCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	
	var old_value = getCookie(c_name);
	var new_value = c_name+ "=";
	
	myregexp = new RegExp("_"+value+";", "gi");
	
	fixed_value = old_value.replace(myregexp, "");
	
	new_value = new_value +escape(fixed_value)+ ((expiredays==null) ? "" : ";expires="+exdate)+ ";path=/";
	document.cookie= new_value;
	
	window.location = ROOT_URL + "wish-list.php";
}

function checkCookie() {
	username=getCookie('username');
	if (username!=null)
	  {alert('Welcome again '+username+'!');
	}
	else 
	  {
	  username=prompt('Please enter your name:',"");
	  if (username!=null && username!="")
	    {
	    setCookie('username',username,365);
	    }
	  }
}


//********************************************************
// MOTOR YACHT CHARTER
//********************************************************
function hideAllBoatDivs()
{
		var hideDiv = document.getElementById("opis");
		hideDiv.style.display = "none";
		hideDiv = document.getElementById("oprema");
		hideDiv.style.display = "none";
		hideDiv = document.getElementById("pogoji");
		hideDiv.style.display = "none";
}

function showBoatDiv(BoatDivID)
{
	hideAllBoatDivs();
	
	var showDiv = document.getElementById(BoatDivID);
	showDiv.style.display = "block";
	//window.location.hash = "podatki";
	document.getElementById("podatki").scrollIntoView(true);
}

function loadBoatPic(pic_name, description) 
{
	document.getElementById("BigBoatPic").src = pic_name;
	document.getElementById("BigBoatPicDescription").innerHTML = "<b>" + description + "</b>";
}

function drawVisualCaptcha(picID) 
{
	//alert(picID);
	document.getElementById(picID).src = ROOT_URL + "include/inc.captcha_redraw.php?" + Math.random();
}

function open_win(url)
{
window.open(url,"bncwindow","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=300, height=360");
}

function sendpage_win(sendURL)
{
openURL = ROOT_URL+"send-to-friend.php";
var url = openURL + "?sendURL=" + sendURL;
window.open(url,"sendwindow","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=300, height=360");
}

function write_opinion(model)
{
openURL = ROOT_URL+"write-opinion.php";
var url = openURL + "?model=" + model;
window.open(url,"sendwindow","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=300, height=360");
}


//********************************************************
// SORTING
//********************************************************
function chSort(oldByParam,oldDirParam,byParam) {
	//alert("STARO: "+oldByParam+","+oldDirParam+", ŽELIMO: "+byParam);
	
	if (oldByParam == byParam) {
		switch (oldDirParam) {
			case "ASC":
				dirParam = "DESC";
				break;
			case "DESC":
				dirParam = "ASC";
				break;
			default:
				dirParam = "ASC";
		}
	}
	else {
		switch (byParam) {
			case "model":
				dirParam = "ASC";
				break;
			case "year":
				dirParam = "DESC";
				break;
			case "length":
				dirParam = "ASC";
				break;
			case "cabins":
				dirParam = "ASC";
				break;
			case "berths":
				dirParam = "ASC";
				break;
			case "charter_bases":
				dirParam = "ASC";
				break;
			case "price":
				dirParam = "ASC";
				break;
			case "rating":
				dirParam = "DESC";
				break;
			default:
				dirParam = "ASC";
		}
	}
	//alert("DOBIMO: "+byParam+","+dirParam);
	
	document.fmHidden.sortParam.value = byParam;
	document.fmHidden.sortDirParam.value = dirParam;
	document.fmHidden.submit();
}
