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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// advanced form validation
function validateForm(formObjects, OTISclass, OTISclassErr, OTISconfirm, OTISconfirmTxt) {
	statusDela = true;
	
	for (i=0; i<formObjects.length; i++) {
		statusDela = checkFormObject(formObjects[i], statusDela, OTISclass, OTISclassErr);
	}
		
	if (OTISconfirm) {
		return confirmEntry(statusDela, OTISconfirmTxt);
	} else {
		return statusDela;
	}
}
		
function checkFormObject(data, status, OTISclass, OTISclassErr) {
	var elm = document.getElementById(data);
	if (elm.value == "" || elm.value == "0") {
		elm.className = OTISclassErr;
		return checkStatus(status, false);
	} else {
		elm.className = OTISclass;
		return checkStatus(status, true);
	}
}

function checkStatus(curStatus, newStatus) {
	if (curStatus && newStatus) {
		return true;
	} else {
		return false;
	}
}
		
function confirmEntry(status, txt) {
	if (status) {
		return true;
	} else {
		return confirm(txt);
	}
}

// preveri formo za peticije
function checkEmail(emField){
var fieldValue = emField;

        if(fieldValue != ""){
        var atSymbol = 0;

                for(var a = 0; a < fieldValue.length; a++){
                        if(fieldValue.charAt(a) == "@"){
                        atSymbol++
                        }
                }

                if(atSymbol > 1){ // if more than 1 @ symbol exists
                //alert("Please Enter A Valid Email Address") // then cancel
                return false
                }

                if(atSymbol == 1 && fieldValue.charAt(0) != "@"){  // if @ symbol was found, and it is not the 1st character in string
                var period = fieldValue.indexOf(".",fieldValue.indexOf("@")+2) //look for period at 2nd character after @ symbol
                var twoPeriods = (fieldValue.charAt((period+1)) == ".") ? true : false // "."  immediately following 1st "." ?

                //if period was not found OR 2 periods together OR field contains less than 5 characters OR period is in last position
                        if(period == -1 || twoPeriods || fieldValue.length < period + 2 || fieldValue.charAt(fieldValue.length-1)=="."){
                        //alert("Please Enter A Valid Email Address") // then cancel
                        return false
                        }

                }
                else{  // no @ symbol exists or it is in position 0 (the first character of the field)
                //alert("Please Enter A Valid Email Address")
                return false
                }
        }
        else{
        //alert("Please Enter A Valid Email Address")
        return false
        }
//alert("VALID EMAIL ADDRESS!")
return true
}

function check_podpisi_se()
{
        var msg = "";
        var msg_first_line = "V prijavnico si pozabil/a vpisati:\n\n";
        var mail = document.petition.mail.value;

        if (document.petition.name.value == "") {
                msg += "* Ime\n";
        }
        if (document.petition.surname.value == "") {
                msg += "* Priimek\n";
        }
        if (document.petition.city.value == "") {
                msg += "* Mesto/Kraj\n";
        }
        if (document.petition.mail.value == "") {
                msg += "* Elektronski naslov (e-mail)\n";
        }

        if (msg == "" && checkEmail(mail) == true) {
                return true;
        } else {
                if (msg == "")
                        alert("E-mail naslov ni pravilno vpisan.");
                else {
                        msg_first_line += msg;
                        alert(msg_first_line); }

                return false;
        }
}

// funkcija poveca vse prve crke v besedi
//Primer:
// simon tomazic
// Simon Tomazic
function capitalizeInput(obj) {
    val = obj.value;
	newVal = '';
    val = val.split(' ');
    for(var c=0; c < val.length; c++) {
	newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length) + ' ';
    }
    obj.value = newVal;
}

// POVECAVA FONTOV //
// tove prisi v telo pa bo vse delalo kot je treba
// <BODY onLoad="fontSizer(0,'px');">


// Copyright 2003 Eddie Traversa
// http://www.dhtmlnirvana.com/
// free to use as long as this copyright notice stays intact
var tags = new Array( 'div','td','tr','p','b','table','strong','span','emphasis','a','h1','h2','h3','pre','sub','sup','i','th','cp','ul','ol','li','dt','dd');
var pixelArray =  new Array('9','10','11','13','15','17','19','21');
var emArray =  new Array('0.7','0.9','1.0','1.5','2.0','2.5','3');
var ptArray =  new Array('6','7','8','10','12','14','16');

var initSize =  parseInt(getCookie("fontsize"));
	if (!initSize) { 
		initSize = 2;
		// alert(initSize);
		var now = new Date();
		now.setTime(now.getTime() + 0 * 24 * 60 * 60 * 1000);
		setCookie("fontsize", initSize);
	}

function fontSizer(inc,unit) {
	if (!document.getElementById) 
		return;
	var size = initSize;
		size += inc;
	if (size < 0 ) {
		size = 0;
	}
	if (size > 6 ) {
		size = 6;
	}

		initSize = size;

		var now = new Date();
		now.setTime(now.getTime() + 2 * 24 * 60 * 60 * 1000);
		setCookie("fontsize", initSize);
		
		getBody = document.getElementsByTagName('body')[0];
	for (i = 0 ; i < tags.length ; i++ ) {
		getallTags = getBody.getElementsByTagName(tags[i]);
	for (k = 0 ; k < getallTags.length ; k++) 
		getallTags[k].style.fontSize = (unit=='px') ? pixelArray[size]+unit : ptArray[size]+unit;
	}
}


//////////////////////     

// POPUP FUNKCIJI //

// ## odpre novo okno ## //
function OpenWindowPrint(url,width,height,menubar,scrollbars) {
	window.open(url,"mywindow","location=0,menubar=" + menubar + ",resizable=1,scrollbars=" + scrollbars + ",width=" + width + ",height=" + height);
}

// ## odpre novo okno in ga pozicionira na sredino ## //
function PopUpWindow() {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;

    window.open('html/templates/popup.html','myExample7','height=230,width=250,status=no,location=no,toolbar=no,directories=no,menubar=no,resizable=no,scrollbars=no,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
    // ###########################
	// window.open("html/templates/popup.html","","height=230,width=250,status=no,location=no,toolbar=no,directories=no,menubar=no,resizable=no,scrollbars=no");
	// ###########################
}
// end POPUP FUNKCIJI //

// cookeis //
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

// END cookeis //