/**
 * @author zvone
 */
function js(){
	this.izbornik = '';
	this.izbornici = Array('NASLOVNICA','TEME','PROIZVODI','LINKOVI','FORUM','KONTAKT');
	
	this.odaberiTrazilicu = function(){
		$("trazilica").focus();
	}
	this.obrisiTrazilicu = function(element){
		element.value = '';
	}
	this.safariTrazilica = function(){
		if(navigator.userAgent.indexOf('Safari') != -1){
			$('divTrazilica').className = 'trazilicaSafari';
		}
	}
	this.ubaciMail = function(prviDio, drugiDio, tekst){
		document.write('<a href="mailto:'+prviDio+'@'+drugiDio+'">'+tekst+'</a>');
	}
	this.postaviAktivniIzbornik = function(){
		if(this.izbornik == ''){
			this.izbornik = 'NASLOVNICA';
		}
		for(var i = 0; i < this.izbornici.length; i++){
			if(this.izbornici[i] == this.izbornik.toUpperCase()){
				$(this.izbornik.toUpperCase()).className = 'ThemeOfficeMainItemHover';
			}
		}
	}
	this.resizeForum = function(element){
		element.height = element.contentWindow.document.body.scrollHeight;;
	}
	this.submitTrazilica = function(){
		if($('trazilica').value.length < 4){
			alert('Da bi izvršili pretragu upišite više od 4 znaka!');
			$('trazilica').focus();
			$('trazilica').select();
		}
		else{
			document.trazilicaForma.submit();
		}
	}
	this.checkTrazilica = function(){
		if($('trazilica').value.length < 4){
			alert('Da bi izvršili pretragu upišite više od 4 znaka!');
			$('trazilica').focus();
			$('trazilica').select();
			return false;
		}
		else{
			return true;
		}
	}
	this.checkKontakt = function(){
		if($('mail').value == ''){
			alert('Niste upisali vašu e-mail adresu!');
			$('mail').focus();
			$('mail').select();
			return false;
		}
		else if(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/.test($("mail").value) == false){
			alert('Unijeli ste neispravnu e-mail adresu!');
			$('mail').value = '';
			$('mail').focus();
			$('mail').select();
			return false;
		}
		else if($('kontakt').value == ''){
			alert('Niste upisali ništa u polje za poruku!');
			$('kontakt').focus();
			$('kontakt').select();
			return false;
		}
		else{
			return true;
		}
	}
	this.pravilaKomentrianja = function(){
		window.open("pravila.html",null,"height=500,width=400,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
	}
	this.dohvatiKomentare = function(id){
		if($('komentari').innerHTML == '&nbsp;' || !id){
			if(!id){
				post = 'id_clanci_tema='+$('id_clanci_tema').value+'&nickname='+$('nickname').value+'&email='+$('email').value+'&komentar='+$('komentar').value
			}
			else{
				post = 'id='+id;
			}
			new Ajax.Request('./classes/getData.php', {
				postBody: post,
				onCreate: function(transport){
					var loading = new Image();
					loading.src = ".template/slike/loading.gif";
					$('komentari').innerHTML = '<table align="center" cellpadding="0" cellspacing="0" border="0"><tr><td><img src="./template/slike/loading.gif"></td></tr></table>';
				},
				onSuccess: function(transport) {
					$('komentari').innerHTML = transport.responseText;
					$('brojKomentara').innerHTML = $('brojKomentaraNovo').value;
					$('dugmicKoment').value = 'SAKRIJ KOMENTARE';
					//location.href = "#komentar";
				}
			});
		}
		else{
			if(id){
				$('komentari').innerHTML = '&nbsp;';
				$('dugmicKoment').value = 'PRIKAŽI KOMENTARE';
			}
		}
	}
	this.checkKomentar = function(){
		if($('nickname').value == ''){
			alert('Niste upisali vaše ime!');
			$('nickname').focus();
			$('nickname').select();
		}
		else if($('email').value == ''){
			alert('Niste upisali vašu e-mail adresu!');
			$('email').focus();
			$('email').select();
		}
		else if(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/.test($("email").value) == false){
			alert('Unijeli ste neispravnu e-mail adresu!');
			$('email').value = '';
			$('email').focus();
			$('email').select();
		}
		else if($('komentar').value == ''){
			alert('Niste upisali ništa u polje za komentar!');
			$('komentar').focus();
			$('komentar').select();
		}
		else{
			this.dohvatiKomentare();
		}
	}
}

/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
	var dyniframe=new Array()
	for (i=0; i<iframeids.length; i++){
		if ($)
			resizeIframe(iframeids[i])
		//reveal iframe for lower end browsers? (see var above):
		if ((document.all || $) && iframehide=="no"){
			var tempobj=document.all? document.all[iframeids[i]] : $(iframeids[i])
			tempobj.style.display="block"
		}
	}
}

function resizeIframe(frameid){
	var currentfr=$(frameid)
	if (currentfr && !window.opera){
		currentfr.style.display="block"
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
			currentfr.height = currentfr.Document.body.scrollHeight;
		if (currentfr.addEventListener)
			currentfr.addEventListener("load", readjustIframe, false)
		else if (currentfr.attachEvent){
			currentfr.detachEvent("onload", readjustIframe) // Bug fix line
			currentfr.attachEvent("onload", readjustIframe)
		}
	}
}

function readjustIframe(loadevt) {
	var crossevt=(window.event)? event : loadevt
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
	if (iframeroot)
		resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
	if ($)
		$(iframeid).src=url
}

if (window.addEventListener)
	window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
	window.attachEvent("onload", resizeCaller)
else
	window.onload=resizeCaller

