var datum; var oldpagenum;
var res_ime="";
var for_sep=' ' + res_for + ' ';
var viewHor=false;

function dve(n){ return (n = 0 ? '00' : (n < 10 ? '0' + String(n) : String(n))); }

function goAstro(s){
  var o=s.substr(1,1)=="0";
  var el=document.getElementById(o?"leftcol":"subnav");
  if(el){
  	var n=Number(s.substr(2, s.length-2))+(o?0:1);
  	var el2=el.getElementsByTagName('a');
  	if(el2){location=el2[n].href }
	}
}

function queryString(key)
{
 var s=window.location.search;
 s = s.substr(1, s.length - 1);
 //return unescape(s);
 return s; 
}

function SetSubnavClass(klasa){
	var fl = document.getElementById("subnav");
	if(fl!=undefined) {fl.className=klasa;}
}

function SetCurrent(mc)
{
	var el = document.getElementById("current");
	if(el) el.id="";
	mc.id="current";
}

function clearCurrent() {
	var el = document.getElementById("current");
	if(el) el.id="";
}

function SetCurSub(mc)
{
	var el = document.getElementById("cursub");
	if(el != undefined) el.id="";
	if(arguments.length>0) {
		mc.id="cursub";
	} else {
		var el2=document.getElementById("subnav");
		var mc=el2.getElementsByTagName('a');
		//alert(mc + ", " + mc.length + mc.name);
		if(mc.length>0) {
			mc[0].id="cursub";
		}
	}
	
}

function showsnipet(mc, koji)
{
	flashProxy.call('Exec', 'SNIPETI|'+ koji + '|' + SelHor);
	SetCurSub(mc);
SetSubnavClass("");
	return false
}

function setHide(el){
  var s=el.className;
 	if(s.substring(s.length -4, s.length)!='hide'){
  	el.className = s+' hide';
  }
}

function clearHide(el){
  var s=el.className;
 	if(s.substring(s.length -4, s.length)=='hide'){
  	el.className = s.substring(0, s.length-5);
  }
}

function ShowText(mc, newEl)
{
	var fl;
	if(newEl != oldEl){
  	var el = document.getElementById(newEl);
	if(el){
		var el2 = document.getElementById(oldEl);
		//if(el)el.style.display="none";
		if(el2){
			if(oldEl=='chart'){
				fl = document.getElementById("flashid");
				if(!fl) { fl = document.getElementById("no_fl"); }
				if(fl) { fl.height = 1;}
				fl.style.visibility="hidden";
				fl = document.getElementById("subnav");
				if(fl!=undefined) {fl.className="hide";}
			} else {
				//el2.style.display="none";
				setHide(el2)
			}
		}
		if(newEl=="chart"){
			fl = document.getElementById("subnav");
			if(fl!=undefined) { fl.className=""; }

			fl = document.getElementById("flashid");
			//alert(fl);
			fl.style.visibility="visible";
			fl.height=505;
		} else {
			//el.style.display="block";
			clearHide(el);
			flashProxy.call('Loading', 'Wait');
		}
		oldEl=newEl;
	}	
}
if (mc != undefined) {SetCurrent(mc);}
return false;
}

function showchart(mc)
{
  if(arguments.length > 0) { 
  	ShowText(mc, 'chart'); 
  } else {
  	ShowText(null, 'chart'); 
  }
}

function setSubNav(mtiphoro){
  	var el = document.getElementById("subnav"+tiphoro.charAt(0));
  	if(el) el.className="hide";
  	var el = document.getElementById("subnav"+mtiphoro.charAt(0));
  	if(el) el.className="";
  	tiphoro = mtiphoro;
  	var el2=el.getElementsByTagName('a');
  	SetCurSub(el2[0]);
}

function changeSubNavTitle(mc){
var s,s1,n,n1;
  var el=document.getElementById("subnav");
  var el2=el.getElementsByTagName('a');
  for(var i=0; i<el2.length; i++){
  	s=el2[i].getAttribute('title');
  	n=s.indexOf(for_sep);
  	s1=mc.getAttribute('title');
  	n1=s1.indexOf(for_sep);
  	if(n>=0){ el2[i].setAttribute('title', s.substring(0, n + for_sep.length) + s1.substring(n1 + for_sep.length-2, s1.length))}
  	res_ime=s1.substring(n1 + for_sep.length, s1.length);
	}
}

function changePerson(mc, persa, promena)
{
//	var el=document.getElementById("selpers");
//	if(el) el.innerHTML = mc.innerHTML;
	SetCurrent(mc);

	if(persa)
	{
  		var podaci = persa.split("|");
		var n = podaci[1].indexOf(";");
		if(n>-1) {
			SelID = podaci[1].substr(0, n-1);
		} else {
			SelID = "0";
		}
  	
  		if(podaci) { setSubNav(podaci[0]);}
		SelHor=persa;
		
		if(arguments.length < 3) { flashProxy.call('Exec', 'Wheel|'+ persa); }
	  showchart(mc);
	}
	changeSubNavTitle(mc);
SetSubnavClass("");

	return false;
}

function setDefPerson(mc, persa){
  var n=changePerson(mc, persa);
  mc.id='defper';
  return false;
}

function SetWheel()
{
	flashProxy.call('Exec', 'Wheel|');
	showchart();
SetSubnavClass("");
	return false;
}

function NewPersonal(){
	flashProxy.call('NewPersonal', ''); return true;
}
function NewTransit(){
	flashProxy.call('NewTransit', ''); return true;
}
function NewSynastry(){
	flashProxy.call('NewSynastry', ''); return true;
}

function AddPerson(mc)
{
	flashProxy.call('Exec', 'ENTERDATA|NEW');
	showchart();
	SetCurSub();
//	SetCurrent(mc);
//SetSubnavClass("hide");
	return false;
}

function AddSynastry(mc)
{
	flashProxy.call('Exec', 'SYNASTRYDATA');
	showchart();
	SetCurrent(mc);
//SetSubnavClass("hide");
	return false;
}

function EditPerson(mc)
{
	flashProxy.call('Exec', 'ENTERDATA|EDIT');
	showchart();
//	SetCurrent(mc);
//SetSubnavClass("hide");
	return false;
}

function DeletePerson(mc)
{ 
	if(SelHor.length>15) {
		alert(res_nodel);
	} else if (confirm(res_del + res_ime)) {
		flashProxy.call('Delete', '');
		showchart();
		//	SetCurrent(mc);
		//SetSubnavClass("hide");
	}
	return false;
}

function OrderReports(mc, tip)
{
	flashProxy.call('Exec', 'OrderReports|'+tip);
	showchart();
	SetCurrent(mc);
  SetSubnavClass("hide");
	return false;
}

function ShowHoroscope(mc)
{
	flashProxy.call('Exec', 'Wheel|'+SelHor);
	SetCurSub(mc);
SetSubnavClass("");
	return false;
}

function CreateList(s)
{ 
//alert("comm");
	var el=document.getElementById("PersonList");
	if(el) {
		clearCurrent();
		var arr=s.split("|");
		var def=-1;
		var defstr=SelHor;
		var n=3;
		var nn=0;
		var ss="";
		var klasa=(strana=="SIN" ? 'class="syn" ' : (strana=="TRA" ? 'class="tra" ' : 'class="nat" '));
//		var sss="";
//		var tt=(arr[0]);
		for(var i=0;i<arr.length-1; i=i+n){
			nn++;
			if(arr[i+1].substr(0,1)=='+') {
				arr[i+1]=arr[i+1].substr(1, arr[i+1].length-1);
				defstr=strana + "|" + arr[i+1] + "|" + arr[i+2];
				def=nn-1;
			}
			ss += 	"<li><a " + klasa + ' href="/js.html" title="' + (strana=="NAT"?res_personal:(strana=="TRA"?res_daily:res_love))+ ' ' + res_horoscope + ' ' + res_for + ' ' + arr[i] + '" onClick="return changePerson(this, ' +
				"'" + strana + '|' + arr[i+1] + '|' + arr[i+2] + "');" + '">' + (arr[i]) + '</a></li>';
				
		}					
		for(var i=nn;i<4; i++){
			ss += (strana=="SIN" ? 
			'<li><a class="syn" href="/js.html" title="' + res_free_love + '" onClick="return AddSynastry(this);">' + res_add_love + '</a></li>':
			(strana=="TRA" ? 
			'<li><a class="tra" href="/js.html" title="' + res_free_daily + '" onClick="return AddPerson(this);">' + res_add_daily + '</a></li>':
			'<li><a href="/js.html" class="nat" title="' + res_free_personal + '" onClick="return AddPerson(this);">' + res_add + ' ' + (i==0?res_your:res_new) + ' ' + res_horoscope + '</a></li>'));
		}	
		el.innerHTML = ss; ;
//alert('def='+def+', str='+s);
  	var el2=el.getElementsByTagName('a');
  	if(def < 0 && nn > 0) { def = 0; defstr = strana + "|" + arr[1] + "|" + arr[2];};
  	if(el2.length > 0 && def < el2.length && def >= 0 && (viewHor!=true)) { //dodato &&viewHor zbog tudjih horo
  		//alert('def='+def+',el2[def]='+el2[def]);
  		//var n=changePerson(el2[def], defstr, true);
  		SelHor=defstr; 
  		SetCurrent(el2[def]); 
  		changeSubNavTitle(el2[def]); 
  		//alert('el2='+el2[def]);
  		//var ss=el2[def];
  		//el2[def].id='defper';
  	}
	}
//	alert(sss);
//if(strana=="TRA") { 
//	var per = document.getElementById("defper");
//	setDefPerson(per, HorTra1);
//}
}

function CL(s, pers)
{
  CreateList(s);
  var el=document.getElementById("PersonList");
  var arr=s.split("|");
  for(var i=0;i<arr.length-1; i=i+3){
    if(arr[i+1]==pers){ 
  	var el2=el.getElementsByTagName('li');
  	if(el2) {
  		alert("NAT|"+pers+"||");
  		changePerson(el2, "NAT|"+pers+"||");
  	}
  	break; 
    }
  }
}

function SignIn()
{
	flashProxy.call('Exec', 'SignIn');
	showchart();
SetSubnavClass("hide");
	return false;
}

function SetFlashHeight(visina){
	var el=document.getElementById("name");
	var fl=document.embeds["flashid"];
	if(fl==undefined) { fl = document.getElementById("flashid"); };
	if(visina < 505){
		visina = 505;
	} else
	{
		visina = visina + 20;
	}
	fl.height = visina;
}

	function SetVisPage(page, kako)
	{
	var mc=document.getElementById(page);
  	if(mc) mc.style.display = kako;
	}
	
	function SetPage(pagenum)
	{
		if(pagenum=='') return false;
		var el=document.getElementById('current'); 
		if(el) el.id="l"+selpage;
		if(selpage != '') {
			SetVisPage('p'+selpage, "none");
		}
		el=document.getElementById('l'+pagenum);
		if(el) SetCurrent(el);
		SetVisPage('p'+pagenum, "block");		
		selpage=pagenum;
		return false;
	}

function SetAPage(pagenum){
if(oldpagenum!=pagenum){
var el=document.getElementById(oldpagenum);if(el){ el.className="textarea nat hide" }
var el=document.getElementById(pagenum);if(el){ el.className="textarea nat" }
oldpagenum=pagenum;
}
}

function selReports(keyCode)
{
	var el=document.getElementById("explanation");
	if(el){
		var el2=document.getElementById("expcaption");
		el2.innerHTML = keyCode;
		flashProxy3.call('Exec', "Horoscopes/Natal/" + delin + "/"+keyCode+".swf");
	}
}

function crmShow(n) {
	var el=document.getElementById('crm');
	if(el) {
		el.className="flash";
	}
	var el=document.getElementById('crm_text');
	if(el) {
		el.className="hide";
	}
}

function prikaziText(txtId) {
	var el=document.getElementById(oldEl);
	if(el) { el.className="hide"; }
	var el=document.getElementById(txtId);
	if(el) { el.className=""; }
	oldEl=txtId;
}

function flashid_DoFSCommand(command, args) {
  if(command=='CreateList') {
	  CreateList(args); 
  }
}

document.write('<script language="VBScript"\> \n');
document.write('on error resume next \n');
document.write('Sub flashid_FSCommand(ByVal command, ByVal args)\n');
document.write('  call flashid_DoFSCommand(command, args)\n');
document.write('end sub\n');
document.write('</script\> \n');
