//javascript functions used in project
function update(item) {
	itemCode = item.name;
	quantity = item.options[item.selectedIndex].value;

	document.location.href = 'index.php?cart=update&item='+itemCode+'&quantity='+quantity;
}

function showDiv(divID) {
	var div = document.getElementById(divID);
	div.style.visibility = "visible";
}

function hideDiv(divID) {
	var div = document.getElementById(divID);
	div.style.visibility = "hidden";
}

function clearBox(box) {
	if(box.value==box.defaultValue) {
		box.value = "";
	}
}

function bookmarksite(title, link){
	if(!title)
		title = document.title;
	if(!link)
		link = location.href;
	
	if (document.all)
		window.external.AddFavorite(link, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, link, "");
	else if(window.opera && window.print)
		return true;
}

/* ajax */
var xmlHttp=null;
function GetXmlHttpObject() {
	try {
		xmlHttp=new XMLHttpRequest();	// Firefox, Opera 8.0+, Safari
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}

function changeNewsletterHtml() { 
	if (xmlHttp.readyState==4) {
		if(xmlHttp.responseText && xmlHttp.responseText != "error")
			document.getElementById("newsletterSignup").innerHTML=xmlHttp.responseText;
	}
}
function newsletterSignup(naziv, ime, email, status) {
	xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange=changeNewsletterHtml;
	xmlHttp.open("GET","newsletter.php?n="+naziv+"&i="+ime+"&e="+email+"&s="+status,true);
	xmlHttp.send(null);
}

function changeSurveyHtml() { 
	if (xmlHttp.readyState==4) {
		document.getElementById("survey").innerHTML=xmlHttp.responseText;
	}
}
function surveyDoVote(vote, sex, vote_now) {
	xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange=changeSurveyHtml;
	xmlHttp.open("GET","survey.php?vote_item="+vote+"&"+sex+"=true&vote_now="+vote_now,true);
	xmlHttp.send(null);
}
