﻿
function addCDATA() {
	insertAtCursor(document.rssform.rssContent, '<![CDATA[REPLACE]]>');
}

function insertAtCursor(myField, myValue) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

function showHideCheck() {
	accept = document.getElementById("news_viewnews_accept");
	accept.style.visibility = "visible";
}

function startTime()
{
var today=new Date();
var Y=today.getFullYear();
var M=today.getMonth();
var D=today.getDate();
var Weekday=today.getDay();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
M=M+1;
// add a zero in front of numbers<10
if (h == 0) {
	h = "0" + h;
}
m=checkTime(m);
s=checkTime(s);

switch (Weekday) {
	case 0:
	Today = "Sunday";
	break;
	
	case 1:
	Today = "Monday";
	break;
	
	case 2:
	Today = "Tuesday";
	break;
	
	case 3:
	Today = "Wednesday";
	break;
	
	case 4:
	Today = "Thursday";
	break;
	
	case 5:
	Today = "Friday";
	break;
	
	case 6:
	Today = "Saturday";
	break;
}


if (M<10)
{
  M="0" + M;
}


		
document.getElementById('clock').innerHTML=D+"."+M+"."+Y+". "+h+":"+m;
t=setTimeout('startTime()',30000);
}

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}

function poptastic(url)
{
	newwindow = window.open(url,'','height=675,width=900,resizable=yes,scrollbars=yes,location=yes,toolbar=yes,status=yes,menubar=yes,directories=yes');
	if (window.focus) {newwindow.focus()}
}

function poptastic2(url)
{
	newwindow = window.open(url,'','height=615,width=815,resizable=no,scrollbars=no,location=no,toolbar=no,status=yes,menubar=no,directories=no');
	if (window.focus) {newwindow.focus()}
}

function gdDailyVisits() {
	gdid = document.getElementById("stats_daily_graph");
	gdid.innerHTML = "<img src='stats/analysis/gd_daily_visits.php' alt='Daily Visits' width='525' height='275'>";
}

function gdDailyHits() {
	gdid = document.getElementById("stats_daily_graph");
	gdid.innerHTML = "<img src='stats/analysis/gd_daily.php' alt='Daily Hits' width='525' height='275'>";
}

function gdMonthlyVisits() {
	gdid = document.getElementById("stats_yearly_graph");
	gdid.innerHTML = "<img src='stats/analysis/gd_monthly_visits.php' alt='Daily Visits' width='525' height='275'>";
}

function gdMonthlyHits() {
	gdid = document.getElementById("stats_yearly_graph");
	gdid.innerHTML = "<img src='stats/analysis/gd_monthly.php' alt='Daily Hits' width='525' height='275'>";
}

function showNamjestaj() {
	check = document.getElementById("namCheck");
	if (check.checked) {
		nam = document.getElementById("namjestaj");
		nam.style.display = "";
		nam2 = document.getElementById("namjestaj2");
		nam2.style.display = "";
	} else {
		nam = document.getElementById("namjestaj");
		nam.style.display = "hide";
		nam2 = document.getElementById("namjestaj2");
		nam2.style.display = "hide";
	}
}

function xyPosition(Event) {
	var divX = document.getElementById("X");
	var divY = document.getElementById("Y");
	divX.value = Event.offsetX;
	divY.value = Event.offsetY;
}

function danas() {
	var danas=new Date();
	var Y=danas.getFullYear();
	var M=danas.getMonth();
	var D=danas.getDate();
	M=M+1;
	if (M<10) {
		M="0" + M;
	}
	if (D<10) {
		D="0" + D;
	}

	document.getElementById('datum').value=D+"."+M+"."+Y;
}

function addToFavorites() {

 title = "Portal SUPERMARKETI.info - Gdje je najjeftinije?"; 
  // Blogger - Replace with <$BlogItemTitle$> 
  // MovableType - Replace with <$MTEntryTitle$>

 url = "http://www.supermarketi.info/";
  // Blogger - Replace with <$BlogItemPermalinkURL$> 
  // MovableType - Replace with <$MTEntryPermalink$>
  // WordPress - <?php bloginfo('url'); ?>

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }
 
 function calculateCurrency() {
	var x = $("#source").val();
	var y = $("#select1").val();
	var z = $("#select2").val();
	y=y.replace(/,/,".");
	z=z.replace(/,/,".");
	parseFloat(y);
	parseFloat(z);
	result = Math.round(100*x*y/z)/100;
	$("#dest").val(result);
}

function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getRandomChar() {
	var numberChars = "123456789";
	var lowerChars = "abcdefghijkmnpqrstuvwxyz";
	var upperChars = "ABCDEFGHJKLMNPQRSTUVWXYZ";
	var otherChars = "!@#&-+";
	var charSet = "";
	charSet += numberChars;
	charSet += lowerChars;
	charSet += upperChars;
	charSet += otherChars;
	return charSet.charAt(getRandomNum(0, charSet.length));
}
function getPassword(length) {
	var rc = "";
	if (length > 0) {
		rc = rc + getRandomChar();
		for (var idx = 1; idx < length; ++idx) {
			rc = rc + getRandomChar();
		}
	}
	document.getElementById("pass").value = rc;
	//return rc;
}
	