//var addonpath = "/happyfish/";
var addonpath = "/";
var tt=0;

function subscribe(){
	var email = document.getElementById('email').value;
	var daily = 0;
	var week = 0
	if(document.getElementById('daily').checked){
		daily = 1;
	}
	if(document.getElementById('week').checked){
		week = 1;
	}
	var pageLink = addonpath+'phps/subscribe.php?email='+email+'&daily='+daily+'&week='+week;
	var divId = 'resp';	
	$.ajax({
		type: 'POST',
		data: 'cmd=new',
		url: pageLink,
		success: function(rsps){
		if(divId.length>1){
			$("#"+divId).html(rsps);
		}
	}

	})
}

function submitavs(){
	var emisiunes = '';
	var data = '';
	var words = document.getElementById('words').value;
	if(words.length>2){
		wordstosend = (words.split(" ")).join(",");
		
		var emisiune1 = document.getElementById('emis1').value;
		if(emisiune1>0){
			emisiunes = emisiune1+",";
		}
		var emisiune2 = document.getElementById('emis2').value;
		if(emisiune2>0){
			emisiunes += emisiune2;
		}
		var emisiune3 = document.getElementById('emis3').value;
		if(emisiune3>0){
			if(emisiune2>0){
				emisiunes +=",";
			}
			emisiunes += emisiune3;
		}
		if(emisiunes.length==0){
			emisiunes = 0;
		}
		
		if(document.getElementById('dayo').checked==true){
			data = '';
		} else if(document.getElementById('daydate').checked==true){
			data = document.getElementById('today').value;
		} else {
			var daystart = document.getElementById('startday').value;
			var monthstart = document.getElementById('startmonth').value;
			var yearstart = document.getElementById('startyear').value;
			
			var dayend = document.getElementById('endday').value;
			var monthend = document.getElementById('endmonth').value;
			var yearend = document.getElementById('endyear').value;
			data = yearstart+"-"+monthstart+"-"+daystart+","+yearend+"-"+monthend+"-"+dayend;
		}
		self.location=addonpath+"cauta/"+words+"/"+emisiunes+"/"+data;
	} else {
		alert('Alege cel putin un cuvant pentru cautare');
	}
}
function epadd_p1(formitems,actiontype,eid,where){

	var val = "";
	var querylist = new Array;
	querylist = {cmd:actiontype};
	var FieldList = formitems.split(",");
	for(var i = 0; i < FieldList.length; i++){
		val = document.getElementById(FieldList[i]).value;
		querylist[FieldList[i]]=val;
	}
	querylist['eid'] = eid;
//	querylist+="}";
	var what= addonpath+"phps/addepisod/pas1.php";
	$("#"+where).load(what,querylist,function(){});
}

function epadd_p2(actiontype,where,eid){
	var what= addonpath+"phps/addepisod/pas2.php?cmd="+actiontype+"&eid="+eid;
	$("#"+where).load(what);
}

function changeEpvalues(infotype,eid,fieldName,fieldValue,where,cmd)
{
	var totalitems = new Array;
	totalitems = {eid:eid};
	
	totalitems['infotype']=infotype;
	totalitems['fieldName']=fieldName;
	totalitems['fieldValue']=fieldValue;
	totalitems['cmd']=cmd;
	var what= addonpath+"phps/addepisod/additionalinfo.php";
	$("#"+where).load(what,totalitems,function(){});
}

function selectfct(thishere,idfunctie,where,cmd,eid){
	var totalitems = document.getElementById('totalfct').value;
	var denumire = '';
	for(var i=0;i<totalitems;i++){
		denumire = 'fct_'+i;
		if(document.getElementById(denumire)!=null){
			document.getElementById(denumire).style.backgroundColor = "";
		}
	}
	denumire = 'fct_'+thishere;
	if(document.getElementById(denumire)!=null){
		document.getElementById(denumire).style.backgroundColor = "#FF0000";
	}
	var what= addonpath+"phps/people.php?fct="+idfunctie+"&cmd="+cmd+"&eid="+eid;
	$("#"+where).load(what);
	
}

function save_fct(actiontype,fctid,totalnr,episodid,where){
	var totalitems = new Array;
	totalitems = {cmd:actiontype};
	var totalitems_iterator = 0;
	for(var i=1;i<=totalnr;i++){
		aid = "df_"+fctid+"_"+i;
		if(document.getElementById(aid)!=null){
			if(document.getElementById(aid).checked==true){
				totalitems[totalitems_iterator] = document.getElementById(aid).value;
				totalitems_iterator++;
			}
		}
	}
	totalitems['items']=totalitems_iterator;
	totalitems['eid']=episodid;
	totalitems['fid']=fctid;
	var what= addonpath+"phps/addepisod/saveback.php";
	$("#"+where).load(what,totalitems,function(){});
}

function save_epas(curentBound,eid,where){
	var totalitems = new Array;
	totalitems = {curentBound:curentBound};
	totalitems = {eid:eid};
	var what= addonpath+"phps/addepisod/saveassoc.php?curentBound="+curentBound+"&eid="+eid+"&rspdiv="+where;
	window.open(what,"Episoade","width=400,height=550,toolbars=0,scrollbars=1,location=0,status=0,resizable=0,menubar=0");
//	window.open("/openls.php?sati="+sati+"&cmd=s","Sateliti","width=460,height=350,toolbars=0,scrollbars=0,location=0,status=0,resizable=0,menubar=0");
//	$("#"+where).load(what,totalitems,function(){});

}

function episodesByEmisiune(emisid,where){
	var what= addonpath+"phps/addepisod/emisid.php?emisid="+emisid;
	$("#"+where).load(what);
}

function chSt(what,total){
	for(var i=0;i<total;i++){
		var idcl = "cl_"+i;
		if(document.getElementById(idcl)!=null){
			document.getElementById(idcl).style.backgroundColor = "";
		}
		var idtl = "tx_"+i;
		if(document.getElementById(idtl)!=null){
			document.getElementById(idtl).style.color = "#6B6B5E";
		}
	}
	idwh = "cl_"+what;
	document.getElementById(idwh).style.backgroundColor = "#6b6b5e";
	var idtl = "tx_"+what;
	if(document.getElementById(idtl)!=null){
		document.getElementById(idtl).style.color = "#dadad7";
	}
}

function showhide (divtoshow, divtohide)
{
var divs=document.getElementById(divtoshow);
var divh=document.getElementById(divtohide);
divs.style.display="";
divh.style.display="none";
}

function showsmenu(smenuTs){
	var all = new Array();
	all[1] = 'posturi_tematice';
	all[2] = 'bloguri';
	all[3] = 'shorturi';

	for(var i=1;i<=all.length;i++){
		if(document.getElementById(all[i])!=null){
			document.getElementById(all[i]).style.display = "none";
		}
	}
	document.getElementById(smenuTs).style.display = "";
}

function  sayIt(what)
{
	alert(what);
}

function updateValue(aid,m_name,m_value)
{
	var what = document.getElementById(aid);
	if(what!=null)
	{
		whatValue = what.value+","+m_value;
		what.value = whatValue;
	} else
		{
			document.write('<input type="hidden" name="'+m_name+'" id="'+aid+'" value="'+m_value+'">');
		}
}

function appear(usepreloader,where,what){
	if(usepreloader){
		var preloader = addonpath+"phps/preloader.php";
		var querylist = new Array;
		querylist = {cmd:'nothinghere'};
		$("#"+where).load(preloader,querylist,function(){
			$("#"+where).load(what);
		});
	} else {
				$("#"+where).load(what);
	}
}

function appearp(where){
	if(where=='gre'){
		document.getElementById('sis').src = 'http://www.happyfish.ro/images/sis_nesel.png';
		document.getElementById('cin').src = 'http://www.happyfish.ro/images/cine_nesel.png';
		document.getElementById('gre').src = 'http://www.happyfish.ro/images/gc_sel.png';
	}
	
	if(where=='sis'){
		document.getElementById('sis').src = 'http://www.happyfish.ro/images/sis_sel.png';
		document.getElementById('cin').src = 'http://www.happyfish.ro/images/cine_nesel.png';
		document.getElementById('gre').src = 'http://www.happyfish.ro/images/gc_nesel.png';
	}
	
	if(where=='cin'){
		document.getElementById('sis').src = 'http://www.happyfish.ro/images/sis_nesel.png';
		document.getElementById('cin').src = 'http://www.happyfish.ro/images/cine_sel.png';
		document.getElementById('gre').src = 'http://www.happyfish.ro/images/gc_nesel.png';
	}
}

function cclasspr(type,where,classToC,classFromC,classToT,classFromT){

	if(type=='episod'){
		var all = new Array();
		all[1] = 'views';
		all[2] = 'note';
		all[3] = 'comments';
		all[4] = 'noi';
	
		for(var i=1;i<=3;i++){
			var whDiv = all[i]+"c";
			$("#"+whDiv).removeClass(classToC);
			$("#"+whDiv).addClass(classFromC);
			var whDivT = all[i]+"t";
			$("#"+whDivT).removeClass(classToT);
			$("#"+whDivT).addClass(classFromT);
		}
	} else if(type=='usr') {
		var all = new Array();
		all[1] = 'favorites';
		all[2] = 'votes';
		all[3] = 'commentsusr';
		all[4] = 'viewd';
	
		for(var i=1;i<=4;i++){
			var whDiv = all[i]+"c";
			$("#"+whDiv).removeClass(classToC);
			$("#"+whDiv).addClass(classFromC);
			var whDivT = all[i]+"t";
			$("#"+whDivT).removeClass(classToT);
			$("#"+whDivT).addClass(classFromT);
		}
	} else if(type=='ssc'){
		var all = new Array();
		all[1] = 'sharing';
		all[2] = 'stats';
		all[3] = 'credits';
		for(var i=1;i<=3;i++){
			var whDiv = all[i]+"c";
			$("#"+whDiv).removeClass(classToC);
			$("#"+whDiv).addClass(classFromC);
			var whDivT = all[i]+"t";
			$("#"+whDivT).removeClass(classToT);
			$("#"+whDivT).addClass(classFromT);
		}
	}
	var wherec = where+"c";
	var wheret = where+"t";

	$("#"+wherec).removeClass(classFromC);
	$("#"+wherec).addClass(classToC);

	$("#"+wheret).removeClass(classFromT);
	$("#"+wheret).addClass(classToT);

}

function openls(sati){
	window.open("/openls.php?sati="+sati+"&cmd=s","Sateliti","width=460,height=350,toolbars=0,scrollbars=0,location=0,status=0,resizable=0,menubar=0");
}

function openlm(){
	window.open("/openls.php?cmd=m","Sateliti","width=460,height=350,toolbars=0,scrollbars=0,location=0,status=0,resizable=0,menubar=0");
}
function auto_complete(aid,tagtype)
{
var litere=document.getElementById('ArticoleTagC').value;
if(litere.length>=2){
	wordstosend = (litere.split(" ")).join("_");
	appear(false,"tag_ac",addonpath+"phps/tags.php?litere="+wordstosend+"&aid="+aid+"&tagtype="+tagtype);
} else {
	document.getElementById('tag_ac').innerHTML = "";
}
}
function add_tag(aid,tagtype)
{
 	var what = document.getElementById('TagPosibile').value;
 	appear(false,"taguribun",addonpath+"phps/showtags.php?tid="+document.getElementById('TagPosibile').value+"&aid="+aid+"&cmd=add&tagtype="+tagtype);
 	document.getElementById('tag_ac').innerHTML = "";
 	document.getElementById('ArticoleTagC').value = "";
}

function newtag(aid,tagtype){
	var what = document.getElementById('ArticoleTagC').value;
	var querylist = new Array;
	querylist = {cmd:'add tag'};
	querylist['tag'] = document.getElementById('ArticoleTagC').value;
	var litere=document.getElementById('ArticoleTagC').value;
	var wordstosend = (litere.split(" ")).join("_");
	querylist['url'] = wordstosend;
	var where = "taguribun";
	var prd = addonpath+"phps/newtag.php?aid="+aid+"&cmd=add&tagtype="+tagtype;
//	appear(false,"taguribun",addonpath+"phps/newtag.php?aid="+aid+"&cmd=add&tagtype="+tagtype);
	$("#"+where).load(prd,querylist,function(){
			document.getElementById('ArticoleTagC').value = "";
			document.getElementById('ArticoleBtn').style.display = "none";
	})
	
	//,querylist,function(){}
}

function add_tagnew(tid,aid,tagtype){
	appear(false,"taguribun",addonpath+"phps/showtags.php?tid="+tid+"&aid="+aid+"&cmd=add&tagtype="+tagtype);
}

function removetag(aid,tid,tagtype){
	appear(false,"taguribun",addonpath+"phps/showtags.php?tid="+tid+"&aid="+aid+"&cmd=del&tagtype="+tagtype);
}

function changer(counter){
	clearTimeout(tt);
	counter = parseInt(counter);
	for(var i=0;i<=counter;i++){
		var idname = 'star_'+i;
		document.getElementById(idname).src = addonpath+'images/sageata_vot.png';
	}
	var ncounter = counter+1;
	ncounter = parseInt(ncounter);
	for(var j=ncounter;j<5;j++){
		var rand_no = Math.random();
		rand_no = rand_no * 100;
		var idname = 'star_'+j;
		document.getElementById(idname).src = addonpath+'images/sageata_vot_goala.png?'+rand_no;
	}
}

function unvote(counter){
	tt = setTimeout('changer("'+counter+'")',1000);
}

function vote(where,counter,uid,eid){
	counter = parseInt(counter);
	for(var i=0;i<5;i++){
		var idname = 'star_'+i;
		document.getElementById(idname).onmouseover = function(){ return false};
		document.getElementById(idname).onmouseout = function(){ return false};
		document.getElementById(idname).onclick = function(){ return false};
	}
	var querylist = new Array;
	querylist = {cmd:'insert comm'};
	querylist['value'] = counter;
	querylist['eid'] = parseInt(eid);
	querylist['uid'] = parseInt(uid);
	var what= addonpath+"phps/vote.php";
	$("#"+where).load(what,querylist,function(){
	});
}

function slideitd(counter,total){
	
	var divid = "";
	var divw = "box_"+counter;
	if($("#"+divw).is(":hidden")){
		for(var i=0;i<total;i++){
			divid = "box_"+i;
			if($("#"+divid).is(":hidden")){
			} else {
				$("#"+divid).slideUp("normal");
			}
		}
		$("#"+divw).slideDown("slow");
	}
}

function slideDive(divid){
	if($("#"+divid).is(":hidden")){
		$("#"+divid).slideDown("normal");
	} else {
		$("#"+divid).slideUp("fast");
	}
}

function sendmail(usepreloader,where,uid){
	var nume = $.trim(document.getElementById('nume').value);
	var mail = $.trim(document.getElementById('mail').value);
	var mesaj = $.trim(document.getElementById('mesaj').value);
	
	var what = addonpath+"phps/sendmailaction.php";
		var preloader = addonpath+"phps/preloader.php";
		var querylistfake = new Array;
		querylistfake = {cmd:'nothinghere'};
		$("#"+where).load(preloader,querylistfake,function(){
			var querylist = new Array;
			querylist = {cmd:'send mail'};
			querylist['uid'] = uid;
			querylist['nume'] = nume;
			querylist['mail'] = mail;
			querylist['mesaj'] = mesaj;
			$("#"+where).load(what,querylist,function(){});
		});

}

function fpass(where){
	var email = $.trim(document.getElementById('mail').value);
	var querylist = new Array;
	querylist = {cmd:'new account'};
	var what= addonpath+"phps/passnou.php";
	var preloader = addonpath+"phps/preloader.php";
	$("#"+where).load(preloader,querylist,function(){
		querylist['email'] = email;
		$("#"+where).load(what,querylist,function(){});
	});
}

function login(where){
	var usern = $.trim(document.getElementById('usern').value);
	var pass = $.trim(document.getElementById('pass').value);
	
	var querylist = new Array;
	querylist = {cmd:'login'};
	var what= addonpath+"phps/login.php";
	var preloader = addonpath+"phps/preloader.php";
	$("#"+where).load(preloader,querylist,function(){
		querylist['fuser'] = usern;
		querylist['fpass'] = pass;
		$("#"+where).load(what,querylist,function(){});
	});
}

function newacount(where){
	var email = $.trim(document.getElementById('mail').value);
	var usern = $.trim(document.getElementById('usern').value);
	var pass = $.trim(document.getElementById('pass').value);
	var cpass = $.trim(document.getElementById('cpass').value);
	var querylist = new Array;
	querylist = {cmd:'new account'};
	var what= addonpath+"phps/regcontnou.php";
	var preloader = addonpath+"phps/preloader.php";
	$("#"+where).load(preloader,querylist,function(){
		querylist['email'] = email;
		querylist['usern'] = usern;
		querylist['pass'] = pass;
		querylist['cpass'] = cpass;
		$("#"+where).load(what,querylist,function(){});
	});
}

function isEmail(str) {
	  // are regular expressions supported?
	  var supported = 0;
	  if (window.RegExp) {
	    var tempStr = "a";
	    var tempReg = new RegExp(tempStr);
	    if (tempReg.test(tempStr)) supported = 1;
	  }
	  if (!supported) 
	    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	  return (!r1.test(str) && r2.test(str));
	}

function cautamic(){
	
	self.location=addonpath+"cauta/"+document.getElementById('cmic').value;
}

function postcomment(where)
{
	if((document.getElementById('comment').value.length>=3) &&(document.getElementById('comment').value!='Comentariu')){
	document.getElementById('addcom').disabled = true;
	var querylist = new Array;
	querylist = {cmd:'insert comm'};
	querylist['entitate_id'] = document.getElementById('entitate_id').value;
	querylist['entitate_tip'] = document.getElementById('entitate_tip').value;
	querylist['nname'] = document.getElementById('nname').value;
	querylist['nmail'] = document.getElementById('nmail').value;
	querylist['ide'] = document.getElementById('ide').value;
	querylist['cid'] = document.getElementById('cid').value;
	querylist['comment'] = document.getElementById('comment').value;
	
	var what= addonpath+"phps/postcomment.php";
	$("#"+where).load(what,querylist,function(){
		document.getElementById('comment').value = '';
		document.getElementById('addcom').disabled = false;
	});
	} else {
		alert('Scrie un comentariu de cel putin 3 caractere');
	}	
}
function vfpropune()
{
var idsect=document.getElementById('VflinkVfsect').options[document.getElementById('VflinkVfsect').options.selectedIndex].value;
var sect=document.getElementById('VflinkVfsect').options[document.getElementById('VflinkVfsect').options.selectedIndex].text;
//document.getElementById('VflinkVfsect').options[document.getElementById('VflinkVfsect').options.selectedIndex].disabled=true;
var url= document.getElementById('VflinkLink').value;
document.getElementById('VflinkLink').value='';
var deja=document.getElementById('VflinkUrl').value;
var dejas=document.getElementById('VflinkAfisare').value;
//document.getElementById('VflinkUrl').value=deja+","+idsect+"-"+url;
document.getElementById('VflinkAfisare').value=dejas+sect+"-"+url+' ';
}
function filtrusect(linc, idsect)
{
var sect=document.getElementById(idsect).value;
var locatie=linc+sect;
self.location = locatie;
}

function shnews(forwd){
	var cid = document.getElementById('cid').value;
	var where = 'hts';
	var what = addonpath+"happyfish/getnews/"+cid+"/"+forwd;
	$("#"+where).load(what);
}
