function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/**
 * opens a popup window in the center of the screen
 * @param (string)url 		- url to open in popup
 * @param (string)title		- title of the window
 * @param (int)width		- width of the window
 * @param (int)height		- height of the window
 * @param (boolean)scrollbas	- show scroolbars  (0|1)
 * @param (boolean)status	- show status (0|1)
 **/

function openPopup(url,naslov,width,height,scrollbar,status) {
	var m, h;
	var LeftPosition=(screen.width)?(screen.width-width)/2:100;
	var TopPosition=(screen.height)?(screen.height-height)/2:100;
	m =  window.open(url,"popupWin","toolbar=no,width=" + width + ",height=" + height + ",top=" + TopPosition + ",left=" + LeftPosition + ",location=no,directories=no,status="+ status +",menubar=no,resizable=no,scrollbars="+status+",target=_blank");
 	m.focus();
}

function odpri_okno(url,naslov,sirina,visina,drsnik,status) {
	var m, h;
	LeftPosition=(screen.width)?(screen.width-sirina)/2:100;
	TopPosition=(screen.height)?(screen.height-visina)/2:100;
	m =  window.open("","_blank","toolbar=no,height=" + visina + ",width=" + sirina + ",top=" + TopPosition + ",left=" + LeftPosition + ",location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,target=_blank");
	m.document.open();
 	h = m.document;
 	h.writeln("<html><head><title>" + naslov + "</title></head><body bgcolor=white leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>");
 	h.writeln("<a href='index.html' OnClick='javascript:window.close();'><img src=" + url + " border=0>");
 	h.writeln("</body></html>")
 	h.close()
 	m.focus()
}

function checkForm(formId){
	
	var form	= document.getElementById(formId);
	if(form == null) {
		alert("Can't submit form !!!");
		return;
	}
	
	var elements	= form.elements;
	var onError		= false;
	for(var i = 0; i < elements.length; i++){
		var el		= elements[i];
		if(el.id != "")
			if(el.value == ""){
				el.style.border='1px solid #800000';
				onError = true;
			} else el.style.border='1px solid black';
	}


	if(onError)	{
		return;
	}

	
	form.submit();
	
}

function checkOfferForm(formId){
	var form 		= document.getElementById(formId);
	if(form == null) {
		alert("Can't submit form !!!");
		return;
	}
	var onError		= false;
	var els			= form.elements;
	for(var i = 0; i < els.length;i++){
		var el 	= els[i];
		if((el.type =='checkbox')){
			if(el.checked == true){
				var name= el.name;
				var justName	= name.substring(name.indexOf('[')+1,name.indexOf(']'));
				//alert(justName);
				var subField	= document.getElementById(justName+'_opis');
				if(subField == null){
					alert("subField ["+justName+'_opis'+"] not found !" );
					return;
				}
				if(subField.value == ""){
					onError = true;
					subField.style.border = '1px solid #800000';
				}  else el.style.border='1px solid black';
			} else {
				clearSub(el);
			}
		}
		
		if(el.id != ""){
			if(el.id.indexOf('_opis')==-1){
				if(el.value == ""){
					el.style.border='1px solid #800000';
					onError = true;
				} else el.style.border='1px solid black';
			}
		}
	}
	if(onError) return;
	form.submit();
}

function clearSub(checkField){

	if(checkField == null) return;

	var name	= checkField.name;
	var justName	= name.substring(name.indexOf('[')+1,name.indexOf(']'));
	//alert(justName);
	var subField	= document.getElementById(justName+'_opis');
	if(subField == null){
		alert("subField ["+justName+'_opis'+"] not found !" );
		return;
	} 
	if(!checkField.checked) subField.value='';
}

function addToFavorites(urlAddress,pageName) { 
	if (window.external) { 
		window.external.AddFavorite(urlAddress,pageName) 
	} else 
	if (window.sidebar){
		window.sidebar.addPanel(pageName,urlAddress,  "");
	} else { 
		alert("Sorry! Your browser doesn't support this function."); 
	} 
} 


function submitMailForm(){
	var form	= document.getElementById('mailForm');
	if(form == null) return;
	if(emptyTextFields(form)) return;
	
	form.submit();
	
}

function submitRegisterForm(){
	var form	= document.getElementById('registerForm');
	if(form == null) return;
	if(emptyTextFields(form)) return;
	
	form.submit();
}

function emptyTextFields(form){
	var emptyFields	= false;
	if(form == null) return;
	for(var i = 0; i < form.elements.length; i++){
		var field	= form.elements[i];
		if(field.type == 'text'){
			if(field.value==''){
				field.style.border ='1px solid red';
				emptyFields = true;
			} else {
				field.style.border ='';
			}
		}
	}
	return emptyFields;
}


