// JavaScript Document
function getCookie(NameOfCookie)
{
// First we check to see if there is a cookie stored.
// Otherwise the length of document.cookie would be zero.
	if (document.cookie.length > 0)
	{
// Second we check to see if the cookie's name is stored in the
// "document.cookie" object for the page.
// Since more than one cookie can be set on a
// single page it is possible that our cookie
// is not present, even though the "document.cookie" object
// is not just an empty text.
// If our cookie name is not present the value -1 is stored
// in the variable called "begin".
		begin = document.cookie.indexOf(NameOfCookie+"=");	
		if (begin != -1) // Note: != means "is not equal to"
		{
// Our cookie was set.
// The value stored in the cookie is returned from the function.
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return null;
// Our cookie was not set.
// The value "null" is returned from the function.
}
function setCookie(NameOfCookie, value, expiredays)
{
// Three variables are used to set the new cookie.
// The name of the cookie, the value to be stored,
// and finally the number of days until the cookie expires.
// The first lines in the function convert
// the number of days to a valid date.
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 *1000));
// The next line stores the cookie, simply by assigning
// the values to the "document.cookie" object.
// Note the date is converted to Greenwich Mean time using
// the "toGMTstring()" function.
	document.cookie = NameOfCookie + "=" + escape(value) +
	((expiredays == null) ? "" : "; expires=" +	ExpireDate.toGMTString());
}
function delCookie (NameOfCookie)
{
// The function simply checks to see if the cookie is set.
// If so, the expiration date is set to Jan. 1st 1970.
	if (getCookie(NameOfCookie)) document.cookie = NameOfCookie + "=" +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
function xmlinit()
{
var ss='<?xml version="1.0"?>';
return ss;
}
function provvreme(v,tip)
//poredjenje sa sadasnjim datumom i vremenom
{
	if (v=="") return false;
	vreme=new Date();
  	//document.write(vreme.getYear());	
	switch (tip)
	{
		case "god":{if ((v>vreme.getFullYear())||(v<0)) return true; else return false;}
		case "mes":{if ((v>vreme.getMonth())||(v<0)) return true; else return false;}
		case "dan":{if ((v>vreme.getDay())||(v<0)) return true; else return false;}
		case "sat":{if ((v>(vreme.getHours()+1))||(v<0)) return true; else return false;}
		case "min":{if ((v>vreme.getMinutes())||(v<0)) return true; else return false;}
		case "sec":{if ((v>vreme.getSeconds())||(v<0)) return true; else return false;}
	}
	
}
function opentable(tag,type)
{
//type 1 adobe in design table
	var ss="<"+tag+">";
		switch (type)
		{
			case "adobe":
				{ss+='<InDesign:Table xmlns:InDesign="adobe:ns:InDesign/">';
				break;}
			case "other":
				{ss+="<Tabela:Table>";//ne provereno
				break;}
		}
	return ss;
}
function closetable(tag,type)
{
//type 1 adobe in design table
	var ss="";
		switch (type){
			case "adobe" :
				{ss="</InDesign:Table>";
				break;}
			case "other" :
				{ss="</Tabela:Table>";//ne provereno
				break;}
		}
	return ss+"</"+tag+">";
}

function tdopen(type)
{
	switch (type){
			case "adobe" :
				{ss="<InDesign:TD>";
				break;}
			case "other" :
				{ss="<Tabela:TD>";//ne provereno
				break;}
		}
	return ss;
}
function tdclose(type)
{
	switch (type){
			case "adobe" :
				{ss="</InDesign:TD>";
				break;}
			case "other" :
				{ss="</Tabela:TD>";//ne provereno
				break;}
		}
	return ss;
}
function tropen(type)
{
	switch (type){
			case "adobe" :
				{ss="<InDesign:TR>";
				break;}
			case "other" :
				{ss="<Tabela:TR>";//ne provereno
				break;}
		}
	return ss;
}
function trclose(type)
{
	switch (type){
			case "adobe" :
				{ss="</InDesign:TR>";
				break;}
			case "other" :
				{ss="</Tabela:TR>";//ne provereno
				break;}
		}
	return ss;
}
function trinline(v,type,zn)
//v="var1,var2,var3...varn"
//<tr>var1<tr>
//
//<tr>varn<tr>  
{
	var l=v.split(",");
	var ss=tdopen(type);
	for(i=0;i<=l.length-1;i++)
	{
		ss+=tropen(type);
		ss+=numseparator(l[i],zn);
		ss+=trclose(type);	
	}
	ss+=tdclose(type);
	return ss;
}
function tdinline(v,type,zn)
//v="var1,var2,var3...varn"
//<td>var1<td>
//
//<td>varn<td>  
{
	var l=v.split(",");
	var ss=tropen(type);
	for(i=0;i<=l.length-1;i++)
	{
		ss+=tdopen(type);
		ss+=numseparator(l[i],zn);
		ss+=tdclose(type);	
	}
	ss+=trclose(type);
	return ss;
}
function trarraylist(aa,v,num,type,zn)
//v[0],v[1],...,v[n]
//<tr>v[0]<tr>
//...........
//<tr>v[n]<tr>
{
	var ss=tdopen(type)+tropen(type)+aa+trclose(type);
	for(i=0;i<=num;i++)
	{
		ss+=tropen(type);
		ss+=numseparator(v[i].value,zn);
		ss+=trclose(type);	
	}
	ss+=tdclose(type);
	return ss;
}
function tdarraylist(aa,v,num,type,zn)
//v[0],v[1],...,v[n]
//<tr>v[0]<tr>
//...........
//<tr>v[n]<tr>
{
	var ss=tropen(type)+tdopen(type)+aa+tdclose(type);
	for(i=0;i<=num;i++)
	{
		ss+=tdopen(type);
		ss+=numseparator(v[i].value,zn)
		ss+=tdclose(type);	
	}
	ss+=trclose(type);
	return ss;
}
function numcheck(sss,ff,win)
//za celobrojne zahteve
{
		if (sss=="") return "";
		i=parseInt(sss,10);
		if (isNaN(i))
			{
				alert("Kindly enter valid whole number");
				if (ff) win.focus();
				return "";
			} 
		return String(i);
}
function floatnumcheck(sss,ff,win)
//za realne brojeve
{
			if (sss=="") return "";
			var pp=parseFloat(sss);
			if (isNaN(pp))
					{alert("Kindly enter numeric (real) value");
					if (ff) win.focus();
					return "";} 
			return String(Math.round(pp*100)/100); //na dve decimale
}
function telnumcheck(sss,ff,win)
//za telefonske brojeve
{
		if (sss=="") return "";
		var nstr="0123456789.-+(){}[]/ ";
		var c="";
		if (sss.length<5) 
			{alert("Kindly enter at least 5 digits");
				if (ff) win.focus();						//vecina browsera ima ogranicen broj upotrebe naredbe obj.focus
				return "";} 
		if (sss=="") return "";
		for (i=0;i<=sss.length-1;i++)
		{
			c=sss.charAt(i);
			if (nstr.indexOf(c)<0) 
			{alert("Kindly enter valid phone number");
				if (ff) win.focus();
				return "";} 
		}
		return sss;
}
function emailcheck(sss,ff,win)
//za realne brojeve
{
		var nesmestr=" ,*`";
		var c="";
		if (sss=="") return "";
		for (i=0;i<=sss.length-1;i++)
		{
			c=sss.charAt(i);
			if (nesmestr.indexOf(c)>0)
			{
				alert("Kindly enter valid email");
				if (ff) win.focus();
				return "";
			}
			 
		}
		if ((sss.indexOf("@")<0)||(sss.indexOf(".")<0))
		{
				alert("Kindly enter valid email like xxx@kkk.zzz");
				if (ff) win.focus();
				return "";
		}
		return sss;
}
function clrreancheck()
{
	for(i=0;i<=7;i++) main.reancheck[i].checked=false;
}
function oneofchecked(v,num)
{
	var r=false;
	for (i=0;i<=num;i++) r=r||v[i].checked;
	return r;
}
function mastenter(v,ss,ff)
{
	if (v.value=="")
	{
  		if (ff)
		{	alert(ss);
			v.focus();}
		return false;
	}	else return true;
}
function createsss(s,tag,sep)
{
	var a="<"+tag+">"+numseparator(s.value,sep)+"</"+tag+">";
	return a;
}
function opentag(tag)
{
	var a="<"+tag+">";
	return a;
}
function closetag(tag)
{
	var a="</"+tag+">";
	return a;
}
function getchecked(v,num)
{
	var ss="";
	var ent=false;
	if (num==0) 
	{
		if (v.checked) ss+=v.value;
		return ss;
	}
	for (i=0;i<=num;i++)
	{
		if (ent && v[i].checked) ss=ss+"%0a";//<br>
		if (v[i].checked) 
			{ss+=v[i].value;
			ent=true;}
	}
	return ss;
}
function strchecked(v,o,tag,num)
{
	var a="";
	var ss="<"+tag+">";
	var s=getchecked(v,num);
	if (o!="") 
		{if (s!="") a="%0a"+escape(o); else a=escape(o);}//<br>
	ss+=s+a+"</"+tag+">";
	return ss;
}
function velikaslova(v,tip)
{
	var c=v.charAt(0);
	if (v=="") return "";
	switch (tip)
	{
		case "prvo":{ var ss=c.toUpperCase()+v.substring(1,v.length); return ss;}
		case "sve":{return v.toUpperCase();}
	}
	return "";	
}
function sumrow(gde,sta,k)
{
	var ss="0";
	for(i=0;i<=k;i++) if ((sta[i].value!="") && !(isNaN(sta[i].value))) ss+="+"+sta[i].value;
	gde.value=eval(ss);	
}
function numseparator(nstr,znak)
{
	if ((znak=="")||(nstr=="")) return nstr;
	if (!isNaN(nstr))
	{
		var ssl=nstr.split(".");
		var klen=ssl[0].length;
		var pomssl=ssl[0];
		var lenstr=Math.floor(Math.abs((klen-1)/3));
		
		for(iii=1;iii<=lenstr;iii++) pomssl=pomssl.substring(0,klen-iii*3)+znak+pomssl.substring(klen-iii*3,pomssl.length);
			
		
		if (ssl.length>1) pomssl+="."+ssl[1];
		if (lenstr>=1) return pomssl;
	}
	return nstr;
}
