﻿// JavaScript Document
/* PAGE */
function bodyPrint(fPath, myPage)
{
	window.open(fPath + '/body_print.php'/*?page_name='*/,'', 'width=720,height=500,resizable=1,scrollbars=1,toolbar=0,menubar=0');
}
function changeImg(imgPath, imgName, isOn)
{
	myImg = document.getElementById(imgName);
	if (isOn == "on")
		myImg.src = imgPath + imgName + "_2.gif";
	else
		myImg.src = imgPath + imgName + "_1.gif";
}
function eNovice(objId, langId)
{
	var myObj = document.getElementById(objId);
	var XYpos = getPosition(myObj).split(",");
	var xPos = XYpos[0], yPos = XYpos[1];
	createNewEl(xPos, yPos, langId);
}
function getPosition(obj)
{
    var topValue = 0, leftValue = 0;
    while(obj)
	{
		leftValue+= obj.offsetLeft;
		topValue+= obj.offsetTop;
		obj= obj.offsetParent;
    }
    finalvalue = leftValue + "," + (topValue+3);
    return finalvalue;
}
function removeEl()
{
	try
	{
		document.body.removeChild(document.body.lastChild);
	}
	catch(err)	
	{
		document.location.reload();
	}
}
function createNewEl(xPos, yPos, langId)
{
	var bgColor = document.getElementById('th_clr').value;	
	var divTag = document.createElement("div");
	
	divTag.id = "eNewsDiv";
	divTag.setAttribute("align", "center");
	divTag.style.margin = "0px auto";
	divTag.style.position = "fixed";
	divTag.style.display = "block";
	divTag.style.zIndex = "1000000";
	divTag.style.left = xPos+"px";
	divTag.style.top = yPos+"px";
	divTag.style.width = "350px";
	//divTag.style.height = "250px";
	divTag.style.backgroundColor = bgColor;
	
	divTag.innerHTML = createENewsBorder(350, 250, langId);
	
	document.body.appendChild(divTag);
}
function createENewsBorder(width, height, langId)
{
	var html = "<form name='e_news_sign' action='' method='post'>"
	html += "<table width='"+width+"' border='0' cellpadding='2' cellspacing='0' style='border:1px solid #ffffff;'>";
	
	if (langId == 1)
		html += "<tr><td align='right' width='35%' style='border-bottom:1px solid #ffffff;'>Ime in priimek:</td>";
	else if (langId == 2)	
		html += "<tr><td align='right' width='35%' style='border-bottom:1px solid #ffffff;'>First and second name:</td>";
		
	html += "<td align='left' width='65%' style='border-bottom:1px solid #ffffff;'><input type='text' name='fl_name' size='25' maxlength='40' value=''></td></tr>";
	
	if (langId == 1)
		html += "<tr><td align='right' width='35%' style='border-bottom:1px solid #ffffff;'>e-Pošta:</td>";
	else if (langId == 2)	
		html += "<tr><td align='right' width='35%' style='border-bottom:1px solid #ffffff;'>e-Mail:</td>";
			
	html += "<td align='left' width='65%' style='border-bottom:1px solid #ffffff;'><input type='text' name='e_mail' size='30' maxlength='100' value=''></td></tr>";
	html += "<tr><td align='center' colspan='2' style='color:#ffffff;border-bottom:1px solid #ffffff;'>";
	if (langId == 1)
		html += "Vaših podatkov ne bomo posredovali tretjim osebam, potrebujejo se izključno samo za obveščanje o novicah na spletni strani MOLGA.si!";
	else if (langId == 2)	
		html += "Vaših podatkov ne bomo posredovali tretjim osebam, potrebujejo se izključno samo za obveščanje o novicah na spletni strani MOLGA.si!";
	
	html += "</tr></td>";
	html += "<tr><td colspan='2' align='center'>";
	if (langId == 1)
	{
		html += "<input type='button' name='add_me' value='Prijavi se' class='e_btns' onClick='submitENews(this.form, " + langId + ");'>&nbsp;";
		html += "<input type='button' name='close_w' value='Zapri' class='e_btns' onClick='removeEl();'>";
	}
	else if (langId == 2)
	{
		html += "<input type='button' name='add_me' value='Subscribe me' class='e_btns' onClick='submitENews(this.form, " + langId + ");'>&nbsp;";
		html += "<input type='button' name='close_w' value='Close' class='e_btns' onClick='removeEl();'>";
	}	
	html += "<input type='hidden' name='e_news_form' value='ok'>";
	html += "</td></tr>";
	html += "</table></form>";
	return html;
}
function submitENews(myForm, langId)
{
	var alerts = new Array();
	alerts[0] = new Array(2);
	alerts[0][0] = "Vnesite vaše ime in priimek!";
	alerts[0][1] = "Vnesite e-mail!";
	alerts[1] = new Array(2);
	alerts[1][0] = "Please enter your name and second name!";
	alerts[1][1] = "Please enter your e-mail!";
	
	if (myForm.fl_name.value == "")
		alert(alerts[langId-1][0]);
	else if (myForm.e_mail.value == "")
		alert(alerts[langId-1][1]);
	else
		myForm.submit();
}
/* ADMIN */
function chngColor(rowId, color, aColor, cName)
{
	document.getElementById("r-"+rowId).style.backgroundColor=color;
	document.getElementById("a-"+rowId).style.color=aColor;
}
function showImage(imgSrc)
{
	window.open("./inc/showImage.php?img="+imgSrc,"showImg","width=450, height=470, top=100, left=100");
}
function editContent(pageUrl, pageName, langName)
{
	window.open(pageUrl+"inc/edit_content.php?page_name="+pageName+"&lang_name="+langName, "editCntn", "width=1000, height=750, top=30, left=30");	
}
function editNews(pageUrl, pageName, langName, newsId)
{
	window.open(pageUrl+"inc/edit_content.php?page_name="+pageName+"&lang_name="+langName+"&is_news=DA&news_id="+newsId, 
			    "editNews", "width=1000, height=750, top=30, left=30");	
}
function editWinns(pageUrl, winId, action)
{
	if (action == undefined)
		window.open(pageUrl+"admin/edit_winns.php?win_id="+winId, 
					"editNews", "width=400, height=250, top=30, left=30");	
	else
		window.open(pageUrl+"admin/edit_winns.php?win_id="+winId+"&action="+action, 
					"editNews", "width=400, height=250, top=30, left=30");	

}
function deleteNews(pageUrl, newsId)
{
	if (confirm("Izbrišem novico?"))
		window.open(pageUrl+"inc/edit_content.php?delete=news&news_id="+newsId, 
			    "editNews", "width=10, height=10, top=10, left=10");	
}
function resizeImg(imgWidth, imgHeight, imgId)
{
	var myImg = document.getElementById(imgId);
	myImg.width = imgWidth;
	myImg.height = imgHeight;
}

