function deleteText(object)
{
	
	if(!object.dlt)
	{
		object.value="";
		object.dlt=true;
	}
}

function addBookmark(title) {
  if (window.sidebar) //Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, location.href, '');
	else if (window.external) //IE bookmark
		external.AddFavorite(location.href, title);
	else if(window.opera && window.print) //Opera Hotlist
		return true;
}

function closePopup(id) {
	var pop=document.getElementById(id);
	if (pop) {
		pop.style.display="none";
	}
}

function showPopup(id) {
	var pop=document.getElementById(id);
	if (pop) {
		pop.style.display="block";
	}
}

function togglePopup(id) {
	var pop=document.getElementById(id);
	if (pop) {
		if (pop.style.display=="none") 
			pop.style.display=""; 
		else 
			pop.style.display="none";
	}
}


function execute(e,command)
{	
	if(e && command)
	{
		var key=e.keyCode;
		if(key && key==13)
			eval(command);
	}
}

function setFormAction(object,action,target)
{	
	while(object && object.nodeName.toLowerCase()!="form" && (object.parentNode ||object.parentElement))
	{
		if(object.parentNode)
			object=object.parentNode;
		else if(object.parentElement)
			object=object.parentElement;
	}
	if(object)
	{
		object.action=action;
		object.target=target;
		
	}
}

function DisableWindow(id)
{
	var object=document.getElementById(id);
	if(object)
	{
		object.disabled=true;
	}
}





function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

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));
}

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";
    }
}


/*function increaseText(id,increase)
{
	var cookieIncrease=getCookie("textincrease");
	var currentIncrease;
	
	if(!cookieIncrease)
		currentIncrease=0;
	else {
		currentIncrease=parseInt(cookieIncrease);
	}
	
	if(increase)
		currentIncrease+=increase;
	else if(currentIncrease!=0)
		increase=currentIncrease;
	else
		return;

	if (currentIncrease<-1) { increase=currentIncrease=-1; return; }
	if (currentIncrease>3) { increase=currentIncrease=10; return; }
//	alert(increase);		
//	if (currentIncrease<0)
//		increase=currentIncrease=0;
	
	setCookie("textincrease",currentIncrease,null,"/");
		

	var o=document.getElementById(id);
	if(o)
	{
		if (o.hasChildNodes() || (o.childNodes && o.childNodes.length>0) ) {
			var el;
		    if(document.all)
				el= o.children;
			else
				el= o.childNodes;
				
			
			for (var i=0; i<el.length; i++)
				if(el[i].nodeName.toLowerCase()!="#text")
					handleIncrease(el[i], increase);
		}
			
	}	
}
*/
var currentIncrease=0;
function increaseText(id,increase)
{
	//alert(currentIncrease);
	if((currentIncrease>2 && increase>0) || (currentIncrease<-2 && increase<0))
		{
			return;
		}
	
	if(increase==0)
		currentIncrease=0;
	else
		currentIncrease+=increase;
	
	//setCookie("textincrease",currentIncrease,null,"/");
		

	var o=document.getElementById(id);
	if(o)
	{
		if (o.hasChildNodes() || (o.childNodes && o.childNodes.length>0) ) {
			var el;
		    if(document.all)
				el= o.children;
			else
				el= o.childNodes;
				
			
			for (var i=0; i<el.length; i++)
				if(el[i].nodeName.toLowerCase()!="#text")
					handleIncrease(el[i], increase);
		}
			
	}	
}


function getStyle(x,styleProp)
{
	var y=null;

	if (document.defaultView && document.defaultView.getComputedStyle)
		y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	else if (x.currentStyle)
		y = eval('x.currentStyle.' + styleProp);
	
	return y;
}


function handleIncrease(o, increase)
{

	if(o)
	{
		if (o.hasChildNodes() || (o.childNodes && o.childNodes.length>0) ) {
			var el;
		    if(document.all)
				el= o.children;
			else
				el= o.childNodes;
					
			for (var i=0; i<el.length; i++)
			{ //alert(el[i].nodeName.substr(0,1));
				if(el[i].nodeName.substr(0,1)!="#")
					handleIncrease(el[i], increase);
			}
		}
			
		var newval=null;
		
		try
		{
			if(o.style && o.style.fontSize)
				newval=o.style.fontSize;
			else
				newval=getStyle(o,(document.all ? "fontSize" : "font-size") );
		}
		catch (e) { return; }
			
		if(newval && newval!="")
		{
//			alert(newval);
			var extension=newval.match(/[a-z]+$/i);
//			alert("ext: " + extension);
			newval=newval.match(/^[\d\.]+/i);
//			alert("\nnewval: " + newval + "\nincrease: " + increase + "\nextension: " + extension);
//			alert("" + (parseFloat(newval) + increase) + extension);
//			throw("x");
			
			try {
				o.style.fontSize=(parseFloat(newval) + increase) + extension;			
			} catch (e) {
				//alert("Napaka v cookieincrease!\n" + e + "\nnewval: " + newval + "\nincrease: " + increase + "\nextension: " + extension);
				//throw(e);
			}
		}
	
	}	

}


function addEvent(o, evType, f, capture) {
	if(o.addEventListener) {
		o.addEventListener(evType, f, capture);
		return true;
	} else if (o.attachEvent) {
		var r = o.attachEvent("on" + evType, f);
		return r;
	} else {
		// alert("Handler could not be attached");
	}
}

function removeEvent(o, evType, f, capture) {
	if(o.removeEventListener) {
		o.removeEventListener(evType, f, capture);
		return true;
	} else if (o.detachEvent) {
		o.detachEvent("on" + evType, f);
	} else {
		// alert("Handler could not be removed");
	}
}



// formValidator

function trim(s) 
{ 
    var l=0; var r=s.length -1; 
    while(l < s.length && s[l] == ' ') 
    {     l++; } 
    while(r > l && s[r] == ' ') 
    {     r-=1;     } 
    return s.substring(l, r+1); 
} 


/* notify
 * The function is called to somehow notify user of errors.
 * @param message (any string message would fit)
 * @param FIELD (an <input> object)
 * @return void
 */
function notify(FIELD, message) {
		alert(message);
		FIELD.focus();
		FIELD.select();
		// window.status=message;
		// setTimeout("window.status=\"\"", 2000);
}

/* validateForm
 * This function validates form elements that define the ALT property.
 * returns: true/false
 * @see: validateField
 * @param: FORM (the <form> object)
 */
function validateForm(FORM) {
		allok=true;	
		//alert('Preverjam obrazec ...');
    
		for (i=0; (i<FORM.elements.length && allok); i++) {
	allok=allok && validateField(FORM.elements[i]);
		}
    
		return allok;
}

/* validateField
 * Function checks field for validity.
 * returns: true/false
 * @see: validateDate, validateFloat, validateInteger, validateTime, validateNotnull
 * @param: FIELD (an <input> object)
 */
function validateField(FIELD) {
	allok=true;
	if (FIELD.alt!=null) {
		checkfor=FIELD.alt.match(/[a-z]+/gi);
		for (j=0; (checkfor!=null && j<checkfor.length && allok); j++) {
			if (checkfor[j]=="date")
				allok=allok && validateDate(FIELD);
			if (checkfor[j]=="datenotnull")
				allok=allok && validateDateNotNull(FIELD);
			if (checkfor[j]=="datetime")
				allok=allok && validateDateTime(FIELD);  
			if (checkfor[j]=="float")
				allok=allok && validateFloat(FIELD);
			if (checkfor[j]=="percentage")
				allok=allok && validatePercentage(FIELD);
			if (checkfor[j]=="integers") 
				allok=allok && validateIntegers(FIELD);
			if (checkfor[j]=="integer")
				allok=allok && validateInteger(FIELD);
			if (checkfor[j]=="time")
				allok=allok && validateTime(FIELD);
			if (checkfor[j]=="notnull")
				allok=allok && validateNotnull(FIELD);
			if (checkfor[j]=="emails")
				allok=allok && validateEmail(FIELD);

			// type 'null' has special handling: if specified as the first
			// type in <input> object's alt property it validates the field
			// which would not validate as a 'date'
			// specify it as the first in type list if you need a 'date' or 
			// 'null' field
			if (checkfor[j]=="null" && trim(FIELD.value)=="") {
			  // alert('Polje je null in je hkrati prazno');
				return true;
				} else if (checkfor[j]=="null" && trim(FIELD.value)!="") {
				  if (FIELD.value.indexOf(";")!=-1) {
                            notify(FIELD, "Polje ne sme vsebovati znaka ; (podpicje) !");
                            return false;
                          }
				}
				
				if (trim(FIELD.value)!="") {
				  if (FIELD.value.indexOf(";")!=-1) {
                            notify(FIELD, "Polje ne sme vsebovati znaka ; (podpicje) !");
                            return false;
                          }
				}
				
			
		}
	}
	return allok;
}

/* validateDate
 * Checks a field for a date value. Returns false if format doesn't match the
 * specified regexpr or incorrect values are specified for day/month/year.
 * Current format: 'dd.mm.yyyy' or 'd.m.yyyy'
 * returns: true/false
 * @see validateField
 * @param FIELD (an <input> object)
 */
function validateDate(FIELD) {
		// 'dd.mm.yyyy' or 'd.m.yyyy'
		if (trim(FIELD.value)!="") {
		datumreg=FIELD.value.match(/(\d?\d)\.(\d?\d)\.(\d{4})/g);

		if (datumreg==null) {
	notify(FIELD, "Polje mora vsebovati datum oblike 'dd.mm.yyyy'!");
	return false;
		} else {
	datumtest=new Date(RegExp.$3, RegExp.$2-1, RegExp.$1);
	if (datumtest.getMonth()+1 != RegExp.$2) {
			notify(FIELD, "Tak datum ne obstaja!");
			return false;
	}
	return true;
		}
		} else {
		  return true;
		}
		
}


function validateDateNotNull(FIELD) {
		// 'dd.mm.yyyy' or 'd.m.yyyy'
		//if (trim(FIELD.value)!="") {
		datumreg=FIELD.value.match(/(\d?\d)\.(\d?\d)\.(\d{4})/g);

		if (datumreg==null) {
	notify(FIELD, "Polje mora vsebovati datum oblike 'dd.mm.yyyy'!");
	return false;
		} else {
	datumtest=new Date(RegExp.$3, RegExp.$2-1, RegExp.$1);
	if (datumtest.getMonth()+1 != RegExp.$2) {
			notify(FIELD, "Tak datum ne obstaja!");
			return false;
	}
	return true;
		}
		/*} else {
		  return true;
		}*/
		
}


function validateDateTime(FIELD) {
		// 'dd.mm.yyyy hh:mm' or 'd.m.yyyy h:m'
		datumreg=FIELD.value.match(/(\d?\d)\.(\d?\d)\.(\d{4}) (\d?\d):(\d?\d)/g);

		if (datumreg==null) {
	notify(FIELD, "Polje mora vsebovati datum oblike 'dd.mm.yyyy hh:mm'!");
	return false;
		} else {
	datumtest=new Date(RegExp.$3, RegExp.$2-1, RegExp.$1);
	if (datumtest.getMonth()+1 != RegExp.$2) {
			notify(FIELD, "Tak datum ne obstaja!");
			return false;
	}
	return true;
		}
}

function validateFloat(FIELD) {
    
		datumreg=FIELD.value.match(/(-?\d+)[\.,]?(\d*)/g);
		if (datumreg==null) {
	notify(FIELD, "Polje mora vsebovati število!");
	return false;
		} else {
	if (RegExp.$2!="")
			FIELD.value=RegExp.$1+"."+RegExp.$2;
	else
			FIELD.value=RegExp.$1;
	return true;
		}
}

function validatePercentage(FIELD) {
    
		datumreg=FIELD.value.match(/(-?\d+)[\.,]?(\d*)\s?%/g);
		if (datumreg==null) {
	notify(FIELD, "Polje mora vsebovati procentualno vrednost (npr. '-13%', '14.3 %')!");
	return false;
		} else {
	if (RegExp.$2!="")
			FIELD.value=RegExp.$1+"."+RegExp.$2+"%";
	else
			FIELD.value=RegExp.$1+"%";
	return true;
		}
}

function validateInteger(FIELD) {
            //alert('Preverjam integer ...: '+FIELD.value );
		//datumreg=FIELD.value.match(/(-?\d+)/g);
		datumreg=FIELD.value.match(/^[-+]?[0-9]+$/);
		//alert('datumreg: '+ datumreg );
		if (datumreg==null) {
	notify(FIELD, "Polje mora vsebovati celo število!");
	return false;
		} else {
		//alert('Polje je OK.');
	return true;
		}
}

function validateIntegers(FIELD) {
    
		datumreg=FIELD.value.match(/^\d{4}$/g);
		if (datumreg==null) {
	notify(FIELD, "Polje mora vsebovati štiri mestno celo število!");
	return false;
		} else {
	return true;
		}
}

function validateTime(FIELD) {
    
		datumreg=FIELD.value.match(/(\d?\d):(\d?\d)/g);
		if (datumreg==null) {
	notify(FIELD, "Polje mora vsebovati cas v formatu 'hh:mi'!");
	return false;
		} else {
	if (RegExp.$1>24 || RegExp.$2>59) {
			notify(FIELD, "Polje mora vsebovati cas v formatu 'hh:mi'!");
			return false;
	}
	return true;
		}
}

function validateEmail(FIELD) {
        if (trim(FIELD.value)!="") {
		datumreg=FIELD.value.match(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/g);
		if (datumreg==null) {
	notify(FIELD, "Polje mora vsebovati pravilen email naslov!");
	return false;
		} else {
	return true;
		}
		} else {
		  return true;
		}
}




function validateNotnull(FIELD) {
            if (FIELD.value.indexOf(";")!=-1) {
              notify(FIELD, "Polje ne sme vsebovati znaka ; (podpicje) !");
              return false;
            }
		if (trim(FIELD.value)=="") {
	notify(FIELD, "Polje ne sme biti prazno!");
	return false;
		}
		return true;
}


function toDate(VALUE) {
		// 'dd.mm.yyyy' or 'd.m.yyyy'
		datumreg=VALUE.match(/(\d?\d)\.(\d?\d)\.(\d{4})/g);

		if (datumreg==null) {
	return null;
		} else {
	datumtest=new Date(RegExp.$3, RegExp.$2-1, RegExp.$1);
	if (datumtest.getMonth()+1 != RegExp.$2) {
			return null;
	}
	return datumtest;
		}
}

function formatDate(DATE) {
	if (navigator.appName == "Microsoft Internet Explorer")
			return ""+DATE.getDate()+"."+(DATE.getMonth()+1)+"."+DATE.getYear();
	else
			return ""+DATE.getDate()+"."+(DATE.getMonth()+1)+"."+(DATE.getYear()+1900);
}


// dodatek za show/hide element
function showElement(id) {
		document.getElementById(id).style.display = 'block';
}

function hideElement(id) {
		document.getElementById(id).style.display = 'none';
}

// dodatek za scrolltoAnchor
function ScrollToElement(MyID) {
       //alert("Pomikam se na anchor: <%#AnchorName%>");
       //location.href=location.href + '#<%#AnchorName%>';
       //alert('scrolltoelement');
       document.getElementById(MyID).scrollIntoView(true);     
}


