/**
*
*  Crossbrowser Drag Handler
*  http://www.webtoolkit.info/
*
**/

var DragHandler = {


	// private property.
	_oElem : null,

	// public method. Attach drag handler to an element.
	attach : function(oElem) {
		if (!oElem){return;}
		oElem.onmousedown = DragHandler._dragBegin;

		// callbacks
		oElem.dragBegin = new Function();
		oElem.drag = new Function();
		oElem.dragEnd = new Function();

		return oElem;
	},


	// private method. Begin drag process.
	_dragBegin : function(e) {
		
		if (this.id=="lth" || this.id=="rth" || this.id=="lbh" || this.id=="rbh" || this.id=="crop_float" || this.id=="photo_div_1"){
		var oElem = DragHandler._oElem = this	;
			
			}else{
				
		prenosioc.style.display=this.style.display;
		prenosioc.style.top=getY( this )+"px";
		prenosioc.style.left=(getX( this )-getX(document.getElementById ('cijeli'))-galerija_cre.scrollLeft)+"px";
		prenosioc.style.width=this.style.width;
		prenosioc.style.height=this.style.height;
		//prenosioc.offsetTop=this.offsetTop;
		prenosioc.src=this.src;
		//alert (prenosioc.src);	
		
		var oElem = DragHandler._oElem = prenosioc;
		//prenosioc = oElem;
		//oElem = prenosioc;
		}

		if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
		if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }

		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);

		e = e ? e : window.event;
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;

		oElem.dragBegin(oElem, x, y);

		document.onmousemove = DragHandler._drag;
		document.onmouseup = DragHandler._dragEnd;
		return false;
	},


	// private method. Drag (move) element.
	_drag : function(e) {
		var oElem = DragHandler._oElem;
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
		var pagenuml=(document.getElementById ('page_id_l').value*1);
		var pagenumr=(document.getElementById ('page_id_l').value*1);
		var pagenum=(document.getElementById ('page_id').value*1)
		var divnum=(document.getElementById (pagenum+'div_number').value*1)-1;
		var e = e ? e : window.event;
		
		if (oElem.id=="lth" || oElem.id=="rth" || oElem.id=="lbh" || oElem.id=="rbh" || oElem.id=="crop_float" ){
		
		pomakx = e.clientX - oElem.mouseX;
		pomaky =e.clientY - oElem.mouseY; 
		
		newx= x + pomakx;
		newy= y + pomaky;
		
		
		//oElem.style.left = newx + 'px';	
		minleft=document.getElementById ('lim_left').value*1;
		mintop=document.getElementById ('lim_top').value*1;
		maxleft=document.getElementById ('lim_left').value*1+parseInt(document.getElementById ('crop_float').width);
		maxtop=document.getElementById ('lim_top').value*1+parseInt(document.getElementById ('crop_float').height);
		
		
		//if ((parseInt(document.getElementById ('cropbox').style.left)+parseInt(document.getElementById ('cropbox').style.width))<= maxleft ){		}else{oElem.dragEnd();return;}
		
		//if (parseInt(document.getElementById ('lth').style.top)>=mintop  &&  parseInt(document.getElementById ('rbh').style.top)<=maxtop ){}
		//cropbox=document.getElementById ('cropbox');
		//crop_float=document.getElementById ('crop_float');
		//lbh=document.getElementById ('lbh');
		//rbh=document.getElementById ('rbh');
		//lth=document.getElementById ('lth');
		//rth=document.getElementById ('rth');
		crop_omjer=document.getElementById ('b_omjer').value;
		sad_cropbox=parseInt(document.getElementById ('cropbox').style.left);
		sad_cropboy=parseInt(document.getElementById ('cropbox').style.top);
		sad_cropbow=parseInt(document.getElementById ('cropbox').style.width);
		sad_cropboh=parseInt(document.getElementById ('cropbox').style.height);
		
		
		
		
		if (oElem.id=="crop_float"){
			if((sad_cropbox+pomakx)>=minleft && (sad_cropbox+sad_cropbow+pomakx)<=maxleft){
				oElem.style.left = newx + 'px';
				document.getElementById ('cropbox').style.left=parseInt(document.getElementById ('cropbox').style.left)+ (e.clientX - oElem.mouseX) + 'px';
				document.getElementById ('lbh').style.left=document.getElementById ('lth').style.left=parseInt(document.getElementById ('lth').style.left)+ (e.clientX - oElem.mouseX) + 'px';
				document.getElementById ('rbh').style.left=document.getElementById ('rth').style.left=parseInt(document.getElementById ('rth').style.left)+ (e.clientX - oElem.mouseX) + 'px';
				oElem.style.left = x - (e.clientX - oElem.mouseX) + 'px';
			}else{
				oElem.style.left = x + 'px';
			}	
					
			if((sad_cropboy+ pomaky)>=mintop && (sad_cropboy+sad_cropboh+pomaky)<=maxtop){	
				oElem.style.top = newy + 'px';
				document.getElementById ('cropbox').style.top=parseInt(document.getElementById ('cropbox').style.top)+ (e.clientY - oElem.mouseY) + 'px';
				document.getElementById ('lth').style.top=document.getElementById ('rth').style.top=parseInt(document.getElementById ('lth').style.top)+ (e.clientY - oElem.mouseY) + 'px';
				document.getElementById ('rbh').style.top=document.getElementById ('lbh').style.top=parseInt(document.getElementById ('lbh').style.top)+ (e.clientY - oElem.mouseY) + 'px';
				oElem.style.top = y - (e.clientY - oElem.mouseY) + 'px';
				}else{
				oElem.style.top = y + 'px';
			}
		}else{
			
			oElem.style.left = newx + 'px';
			oElem.style.top = newy + 'px';
			
		}
		
		
		if (oElem.id=="rbh" || oElem.id=="rth"){
			if ((newx+5)<=maxleft && (newx + 5 - sad_cropbox)>=100 && (parseInt(document.getElementById ('rth').style.top)+5)>=mintop && (parseInt(document.getElementById ('rbh').style.top)+5)<=maxtop){
			document.getElementById ('cropbox').style.width= (x + 5 - sad_cropbox) +'px'; 
			document.getElementById ('cropbox').style.height=(parseInt(document.getElementById ('cropbox').style.width)*crop_omjer)+"px";
			document.getElementById ('rth').style.left=oElem.style.left;
			document.getElementById ('rbh').style.left=oElem.style.left;
			}else{	
			oElem.style.left = x + 'px';
			oElem.style.top = y + 'px';
			}
		}

		if (oElem.id=="lbh" || oElem.id=="lth"){
			if ((newx+5)>=minleft && (parseInt(document.getElementById ('rbh').style.left)-newx)>=100 && (parseInt(document.getElementById ('lth').style.top)+5)>=mintop && (parseInt(document.getElementById ('lbh').style.top)+5)<=maxtop){
			document.getElementById ('cropbox').style.width= (parseInt(document.getElementById ('rbh').style.left)-parseInt(document.getElementById ('lbh').style.left)) +'px';
			document.getElementById ('cropbox').style.height=(parseInt(document.getElementById ('cropbox').style.width)*crop_omjer)+"px";
			document.getElementById ('cropbox').style.left=(parseInt(oElem.style.left)+5)+'px';
			document.getElementById ('lbh').style.left=oElem.style.left;
			document.getElementById ('lth').style.left=oElem.style.left;
			document.getElementById ('crop_float').style.left=(parseInt(document.getElementById ('crop_float').style.left) - (e.clientX - oElem.mouseX)) + 'px' ;
			}else{	
			oElem.style.left = x + 'px';
			oElem.style.top = y + 'px';
			}
		}
		
		if (oElem.id=="rbh" || oElem.id=="lbh"){
			document.getElementById ('lbh').style.top=document.getElementById ('rbh').style.top=(parseInt(document.getElementById ('lth').style.top)+parseInt(document.getElementById ('cropbox').style.height)) +'px';
		}
		

		
		if (oElem.id=="rth" || oElem.id=="lth"){
			document.getElementById ('lth').style.top=document.getElementById ('rth').style.top=(parseInt(document.getElementById ('lbh').style.top)-parseInt(document.getElementById ('cropbox').style.height)) +'px';
			document.getElementById ('cropbox').style.top=(parseInt(oElem.style.top)+5)+'px';
			document.getElementById ('crop_float').style.top=(parseInt(document.getElementById ('crop_float').style.top) + ( y - parseInt(oElem.style.top))) + 'px' ;
		}
		
		
		
		if ( document.getElementById('scale_limit').value > parseInt(document.getElementById('div_wid').value)/parseInt(document.getElementById('cropbox').style.width)){
			document.getElementById('rez_por').style.display='none';}else{document.getElementById('rez_por').style.display='block';}
		
		
		
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
		oElem.drag(oElem, x, y);
		
		
		}else{
			
		oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px';
		oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px';
		//for (divs=0;divs<=divnum;divs++){
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
		oElem.drag(oElem, x, y);
			
			
		for (divs=0;divs<=(document.getElementById ('div_numberf_l').value-1);divs++){if (isinrange(oElem, document.getElementById (pagenuml+'fotog'+divs))){oElem.style.cursor="url('green_arrow.cur'), pointer";divs=document.getElementById ('div_numberf_l').value-1;}else{oElem.style.cursor='default';}}
		for (divs=0;divs<=(document.getElementById ('div_numberf_r').value-1);divs++){if (isinrange(oElem, document.getElementById (pagenumr+'fotog'+divs))){oElem.style.cursor="url('green_arrow.cur'), pointer";divs=document.getElementById ('div_numberf_r').value-1;}else{oElem.style.cursor='default';}}
			
		}
			
			
		//if (isinrange(oElem, document.getElementById (pagenum+'fotog'+divs))){oElem.style.cursor="url('green_arrow.cur'), pointer";divs=divnum;}else{oElem.style.cursor='default';}
		//}

		return false;
	},


	// private method. Stop drag process.
	_dragEnd : function() {
		var oElem = DragHandler._oElem;
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
		var pagenum=(document.getElementById ('page_id').value*1)
		var pagenuml=(document.getElementById ('page_id_l').value*1);
		var pagenumr=(document.getElementById ('page_id_r').value*1);
		var divnum=(document.getElementById (pagenum+'div_number').value*1)-1;
		document.getElementById ('div_numberf').value=divnum;
		//document.getElementById ('div_numberf_l').value
		oElem.dragEnd(oElem, x, y);
		//alert (getX(oElem)+' '+getY(oElem)+' '+ oElem.mouseX);
		//alert (divnum);
		
		if (oElem.id=="lth" || oElem.id=="rth" || oElem.id=="lbh" || oElem.id=="rbh" || oElem.id=="crop_float"){
		minleft=document.getElementById ('lim_left').value*1;
		mintop=document.getElementById ('lim_top').value*1;
		maxleft=document.getElementById ('lim_left').value*1+parseInt(document.getElementById ('crop_float').width);
		maxtop=document.getElementById ('lim_top').value*1+parseInt(document.getElementById ('crop_float').height);
		cropw=parseInt(document.getElementById ('cropbox').style.width);
		croph=parseInt(document.getElementById ('cropbox').style.height);
		cropt=parseInt(document.getElementById ('cropbox').style.top);
		cropl=parseInt(document.getElementById ('cropbox').style.left);
		
		
		$korekcijax=0;$korekcijay=0;$kor=0;
		if (cropl<minleft){	$korekcijax=minleft-cropl;$kor=1;}
		if (cropl+cropw>maxleft){$korekcijax=maxleft-(cropl+cropw);$kor=1;}
		if (cropt<mintop){$korekcijay=mintop-cropt;$kor=1;}
		if (cropt+croph>maxtop){$korekcijay=maxtop-(cropt+croph);$kor=1;}
				
		if ($kor==1){
		document.getElementById ('lbh').style.left=(parseInt(document.getElementById ('lbh').style.left)+$korekcijax)+'px';
		document.getElementById ('lbh').style.top=(parseInt(document.getElementById ('lbh').style.top)+$korekcijay)+'px';
		document.getElementById ('rbh').style.left=(parseInt(document.getElementById ('rbh').style.left)+$korekcijax)+'px';
		document.getElementById ('rbh').style.top=(parseInt(document.getElementById ('rbh').style.top)+$korekcijay)+'px';
		document.getElementById ('lth').style.left=(parseInt(document.getElementById ('lth').style.left)+$korekcijax)+'px';
		document.getElementById ('lth').style.top=(parseInt(document.getElementById ('lth').style.top)+$korekcijay)+'px';
		document.getElementById ('rth').style.left=(parseInt(document.getElementById ('rth').style.left)+$korekcijax)+'px';
		document.getElementById ('rth').style.top=(parseInt(document.getElementById ('rth').style.top)+$korekcijay)+'px';
		document.getElementById ('cropbox').style.left=(parseInt(document.getElementById ('cropbox').style.left)+$korekcijax)+'px';
		document.getElementById ('cropbox').style.top=(parseInt(document.getElementById ('cropbox').style.top)+$korekcijay)+'px';
		document.getElementById ('crop_float').style.left=(parseInt(document.getElementById ('crop_float').style.left)-$korekcijax)+'px';
		document.getElementById ('crop_float').style.top=(parseInt(document.getElementById ('crop_float').style.top)-$korekcijay)+'px';
		}
		
		document.onmousemove = null;
		document.onmouseup = null;
		DragHandler._oElem = null;
		
		}else{
		
		for (divs=0;divs<=(document.getElementById ('div_numberf_l').value-1);divs++){if (isinrange(oElem, document.getElementById (pagenuml+'fotog'+divs))){send_input_foto(oElem, 'fotog'+divs, 'page_id_l' )}}
		for (divs=0;divs<=(document.getElementById ('div_numberf_r').value-1);divs++){if (isinrange(oElem, document.getElementById (pagenumr+'fotog'+divs))){send_input_foto(oElem, 'fotog'+divs, 'page_id_r' )}}
		oElem.style.left='0px'; oElem.style.top='0px';
		document.onmousemove = null;
		document.onmouseup = null;
		DragHandler._oElem = null;
		prenosioc.style.display="none";
		}
	}

}

	

	function getY( oElement )
	{
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetTop;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
	}
	
	function getX( oElement )
	{
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetLeft;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
	}

	function isinrange(fele, fixele){
		if (fixele){
			var scrOfX = 0, scrOfY = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
			}
	
			MouseXpos=fele.mouseX+scrOfX;
			MouseYpos=fele.mouseY+scrOfY;
	
		
			if((MouseXpos>getX(fixele))&(MouseXpos<(getX(fixele)+fixele.offsetWidth))&(MouseYpos>getY(fixele))&(MouseYpos<(getY(fixele)+fixele.offsetHeight))){return true;}
		}
	}

	function cutpath(cutele){
	return cutele.substr(cutele.lastIndexOf('/')+1);
	}
	var listing=0;
	function updatediv(){
	if( frames['php2svg'].document.getElementById ('nsvg') ){ if( frames['php2svg'].document.getElementById ('nsvg').value=="1" ){ document.template["new"].value=0 ;}}
	document.getElementById(document.getElementById('page_id_s').value.replace('page_id', 'gf')).style.display='none';
	if (document.getElementById('auto').value=="1"){
		dijit.byId('auto_str').hide();
		document.getElementById('auto').value=0;
		if (document.getElementById('page_id_l').value!=0){document.getElementById ('page_id_s').value='page_id_l'; document.getElementById ('page_id').value=document.getElementById ('page_id_l').value; document.getElementById('wait_svg').value=1;}
			else{document.getElementById ('page_id_s').value='page_id_r';}
		gif_on();
		document.template.submit();	
		
		return;}
	
	tr_str=document.getElementById ('page_id_s').value;
	if (document.getElementById('wait_svg').value==1){tr_str='page_id_l'}
	//alert(tr_str+","+document.getElementById('wait_svg').value);
	if (tr_str=='page_id_l'){
			str_div='svg_jpeg_l';
			if (frames['php2svg'].document.getElementById (document.getElementById ('page_id_l').value+'div_number')){
			document.getElementById ('div_numberf_l').value=frames['php2svg'].document.getElementById (document.getElementById ('page_id_l').value+'div_number').value;}
		}else{
			str_div='svg_jpeg_r';
			document.getElementById ('div_numberf_r').value=frames['php2svg'].document.getElementById (document.getElementById ('page_id_r').value+'div_number').value}
	if (frames['php2svg'].document.getElementById ('frjpg')){
	document.getElementById (str_div).innerHTML=frames['php2svg'].document.getElementById ('frjpg').innerHTML;}
	document.getElementById ('svg_temp').value="";
	document.getElementById ('svg_podloga').value="";
	if (document.getElementById('wait_svg').value=="1")
		{
		document.template.foto.value="";
		document.template.divid.value="";
		SelectOpenPage('page_id_r');
			//dodano zbog zadnjih korica
			document.template.svg_temp.value="";
			document.template.page_id_s.value='page_id_r';
			document.template.page_id.value=document.getElementById('page_id_r').value;
			//--
		gif_on();
		document.template.submit();
		}
	//dodano zbog zadnjih korica
	if (document.getElementById ('page_id_r').value=='0' && document.getElementById('wait_svg').value!="1"){SelectOpenPage('page_id_l');}
	if (listing==1 && document.getElementById('wait_svg').value!="1" && tr_str=='page_id_r' && document.getElementById ('page_id_l').value!='0' ){ listing=0;SelectOpenPage('page_id_l'); }
	//--
	document.getElementById('wait_svg').value="0";
	document.template.foto.value="";
	document.template.divid.value="";
	document.getElementById('scrop').value='';
	document.getElementById('xcrop').value='';
	document.getElementById('ycrop').value='';
	document.getElementById('icrop').value='';
	promjeni_mapu('');
	
	if(frames['php2svg'].document.getElementById ('usage_txt')){
	usage_text=frames['php2svg'].document.getElementById ('usage_txt').value
	document.getElementById ('usage_txt').value=usage_text;
	update_usage(usage_text);
	}
	
	}	
	
	function send_input_foto(foto_in, div_in, page_s){
		document.getElementById ('page_id_s').value=page_s;
		document.getElementById ('page_id').value=document.getElementById (page_s).value;
		document.template.foto.value=foto_in.src;
		document.template.divid.value=div_in;
		gif_on();
		document.template.submit();
		foto_in.style.left='0px'; foto_in.style.top='0px';
		SelectOpenPage(page_s);
		
		}
		
 
	function message_alert_change(id_div){
		var message_type=document.getElementById(id_div);
		var message_box=document.getElementById('message_box');
		var transe_box=document.getElementById('trans');
		if (message_box.style.display!='block'){
			message_type.style.display='block';
			message_box.style.display='block';
			transe_box.style.display='block';
		}else{
			message_type.style.display='none';
			message_box.style.display='none';
			transe_box.style.display='none';
		}
	}
 
 
 

function xmlhttpPost(strURL, querystring) {
   	 var xmlHttpReq = false;
   	 var self = this;
   	 // Mozilla/Safari
   	 if (window.XMLHttpRequest) {
    	    self.xmlHttpReq = new XMLHttpRequest();
   	 }
   	 // IE
   	 else if (window.ActiveXObject) {
   	     self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
   	 }
   	 self.xmlHttpReq.open('POST', strURL, true);
   	 self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  	  self.xmlHttpReq.onreadystatechange = function() {
  	      if (self.xmlHttpReq.readyState == 4) {
    	        updatepage(self.xmlHttpReq.responseText);
    	    }
    	}
		//alert("selected="+querystring);
    	self.xmlHttpReq.send("selected="+querystring);
	}


function KoriceUpdate(id_korica) {
	if(document.getElementById("korice_set")){
		trenutna_korica=document.getElementById("korice_set").value;
		if(id_korica==trenutna_korica){return;}
		}
	//try{trenutna_korica=document.getElementById("korice_set").value;}catch(err){if(id_korica==trenutna_korica){return;}}
	
	var strURL='/creator/ajax/korice.php';
   	 var xmlHttpReq = false;
   	 var self = this;
   	 // Mozilla/Safari
   	 if (window.XMLHttpRequest) {
    	    self.xmlHttpReq = new XMLHttpRequest();
   	 }
   	 // IE
   	 else if (window.ActiveXObject) {
   	     self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
   	 }
   	 self.xmlHttpReq.open('POST', strURL, true);
   	 self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  	  self.xmlHttpReq.onreadystatechange = function() {
  	      if (self.xmlHttpReq.readyState == 4) {
    	        updatekorice(self.xmlHttpReq.responseText);
    	    }
    	}
		//alert("selected="+querystring);
    	self.xmlHttpReq.send("korice="+id_korica);
	}

function updatepage(str){
		//alert (str);
   	 document.getElementById("spigl_list").innerHTML = str;
	 trenutni_broj=document.getElementById("trenutno_stranice").value-2;
	 document.getElementById("pages_no").value=document.getElementById("trenutno_stranice").value;
	 //last_page_idd=document.getElementById("last_page_id").value;
	 if(document.getElementById("overlimit").value==1){
		 document.getElementById(document.getElementById ('stara_p').value).style.borderBottom='1px solid #FFC888';
		 dialogAlert('Upozorenje!','Dosegnut je maksimalni broj stranica!');return;}
	
	if(document.getElementById("overlimit").value==2){
		 document.getElementById(document.getElementById ('stara_p').value).style.borderBottom='1px solid #FFC888';
		 dialogAlert('Upozorenje!','Dosegnut je minimalni broj stranica!');return;}
		 
	if (document.getElementById("trenutno_stranice").value==document.getElementById("total_pages").value ){
		if((trenutni_broj+2) <= document.getElementById("stara_p").value){trenutni_broj=trenutni_broj+2;}
			document.getElementById("stara_p").value=(document.getElementById("stara_p").value*1)-4;
		}
		
		document.getElementById(trenutni_broj).onclick();
	}
			
		
function updatekorice(str){
		document.getElementById ('stara_p').value="2";
		document.getElementById("korice_rend").innerHTML = str + '<img style="position: relative; top: -30px;left:60px;" onclick="javascript:pomak(\'b\')" onmouseout="javascript:this.src=\'../images/dd.jpg\'" onmouseover="javascript:this.src=\'../images/dd_o.jpg\';" src="../images/dd.jpg"/>';
		}
		

function korice(){
		if (document.getElementById('page_id_r').value==0){return;}
		document.getElementById('page_id_r').value=0;
		document.getElementById("korice_rend").innerHTML ="";
		document.getElementById("plusminusstr").style.display="none";
		document.getElementById("svg_rend").style.display="none";
		document.getElementById("naslov_ds_2c").style.display="none";
		document.getElementById("naslov_ls_2c").style.display="none";
		document.getElementById("odabir_templatea").style.display="none";
		document.getElementById("v_template").style.display="none";
		document.getElementById("v_korice").style.display="block";
		document.getElementById("naslov_ls_2c_korice").style.display="block";
		document.getElementById("naslov_ds_2c_korice").style.display="block";
		document.getElementById("odabir_korica").style.display="block";	
		document.getElementById("korice_rend").style.display="block";
		
		stara_p=document.getElementById ('stara_p').value;
		document.getElementById (stara_p).style.borderBottom='1px solid #FFF';
		KoriceUpdate('0');
		
	}
	
	function korice_off(){
		document.getElementById("plusminusstr").style.display="block";
		document.getElementById("svg_rend").style.display="block";
		document.getElementById("naslov_ds_2c").style.display="block";
		document.getElementById("naslov_ls_2c").style.display="block";
		document.getElementById("odabir_templatea").style.display="block";
		document.getElementById("v_template").style.display="block";
		document.getElementById("v_korice").style.display="none";
		document.getElementById("naslov_ls_2c_korice").style.display="none";
		document.getElementById("naslov_ds_2c_korice").style.display="none";
		document.getElementById("odabir_korica").style.display="none";	
		document.getElementById("korice_rend").style.display="none";	
	}	
	
function job_mod(id_job, action_job, mod) {
		var strURL='/creator/ajax/jobs.php';
   	 	var xmlHttpReq = false;
   	 	var self = this;
   	 	// Mozilla/Safari - IE
   	 	if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); } else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
   		self.xmlHttpReq.open('POST', strURL, true);
   	 	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  	  	self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { updatejob(self.xmlHttpReq.responseText);} }
		self.xmlHttpReq.send("id_job="+id_job+"&action_job="+action_job+"&mod="+mod);
	}
	
	function updatejob(str){
		t_akcija=document.getElementById("ac_job").value;
		if(t_akcija=="delete")	{document.getElementById("jobs_place").innerHTML=str; document.getElementById("select_job_id").value=document.getElementById("newfirst").value;return;}
		if(t_akcija=="novi")	{
			window.location=str;
			return;}
		if(t_akcija=="naruci")	{
			if ( str =="blank" ){
						test_user();
			}else{ 
					if (document.getElementById('izradi_no')){
						if (document.getElementById('izradi_no').value!=""){
							window.location=$link2a+"?proizvod="+document.getElementById('izradi_no').value;
						}else{ window.location=$linkkos; }
					}else{ window.location=$linkkos; }
			return;}
		}
		if(t_akcija=="pregledaj") {
			if (navigator.appName.indexOf("Microsoft")!=-1) {supp='?id='+str;}else{supp='';}
			window.location=$link3c+supp;
			return;}
	}
	
	
function custom_confirm(ret_function, tx_msg, title_ms, yes_btn, no_btn, width_c, height_c, topbutton, dojo__button_third ){
		dojo_button_ok='';
		var winW = 630, winH = 460;
				
		if (topbutton==1){
			buttontop='<img alt="Zatvori" title="Zatvori" onclick="dijit.byId(\'custom_conf\').hide();" onmouseout="javascript:this.src=\'../images/close.png\'" onmouseover="javascript:this.src=\'../images/close_o.png\';" src="../images/close.png" name="upload" style="margin: 2px; position: absolute; float: right; right:5px;top:-2px"/>';	
			}else{buttontop='';}
		
		
	if (parseInt(navigator.appVersion)>3) {
 	if (navigator.appName=="Netscape") {
  	winW = window.innerWidth;
  	winH = window.innerHeight;
	 }
 	if (navigator.appName.indexOf("Microsoft")!=-1) {
  	winW = document.body.offsetWidth;
  	winH = document.body.offsetHeight*0.8;
 	}
	}
		if (dijit.byId('custom_conf')){
		if( typeof(height_c) != 'undefined' ) {dojo.style(dijit.byId('custom_conf').domNode, {height: height_c+"px"});}else{dojo.style(dijit.byId('custom_conf').domNode, {height: "auto"});}
		if( typeof(width_c) != 'undefined' ) {dojo.style(dijit.byId('custom_conf').domNode, {width: width_c+"px"});}else{dojo.style(dijit.byId('custom_conf').domNode, {width: "250px"});}
		}else{cconff=new dijit.Dialog({ id:'custom_conf' })}
		tx_msg=tx_msg+"<br>";
		
		if (yes_btn!=''){
			
		dojo__button_no='<span  style="margin: 10px;" class="dijit dijitReset dijitLeft dijitInline dijitButton" ><span class="dijitReset dijitRight dijitInline"><span class="dijitReset dijitInline dijitButtonNode"><button style="-moz-user-select: none;" tabindex="0" id="dijit_form_Button_0" aria-labelledby="dijit_form_Button_0_label" role="button" class="dijitReset dijitStretch dijitButtonContents" onclick="javascript:dijit.byId(\'custom_conf\').hide();'+ret_function+'(false);"><span class="dijitReset dijitInline"><span class="dijitReset dijitToggleButtonIconChar"></span></span><span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_0_label" dojoattachpoint="containerNode">'+no_btn+'</span></button></span></span></span>'
		
		dojo__button_yes='<span  style="margin: 10px;" class="dijit dijitReset dijitLeft dijitInline dijitButton" ><span class="dijitReset dijitRight dijitInline"><span class="dijitReset dijitInline dijitButtonNode"><button style="-moz-user-select: none;" tabindex="0" id="dijit_form_Button_0" aria-labelledby="dijit_form_Button_1_label" role="button" class="dijitReset dijitStretch dijitButtonContents" onclick="javascript:dijit.byId(\'custom_conf\').hide();'+ret_function+'(true);"><span class="dijitReset dijitInline"><span class="dijitReset dijitToggleButtonIconChar"></span></span><span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_0_label" dojoattachpoint="containerNode">'+yes_btn+'</span></button></span></span></span>'
	
		}
		document.getElementById('custom_conf_title').innerHTML = title_ms+ buttontop;
		//dijit.byId('custom_conf').attr("title", title_ms + buttontop);
		
		if (dojo__button_third){if (dojo__button_third!=''){
			
		dojo__button_third='<span  style="margin: 10px;" class="dijit dijitReset dijitLeft dijitInline dijitButton" ><span class="dijitReset dijitRight dijitInline"><span class="dijitReset dijitInline dijitButtonNode"><button style="-moz-user-select: none;" tabindex="0" id="dijit_form_Button_0" aria-labelledby="dijit_form_Button_2_label" role="button" class="dijitReset dijitStretch dijitButtonContents" onclick="javascript:dijit.byId(\'custom_conf\').hide();'+ret_function+'1(true);"><span class="dijitReset dijitInline"><span class="dijitReset dijitToggleButtonIconChar"></span></span><span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_2_label" dojoattachpoint="containerNode">'+dojo__button_third+'</span></button></span></span></span>';}else{dojo__button_third='';}}else{dojo__button_third='';}
		
		
		if (yes_btn!='' ){
			if (button_style==0){
				dijit.byId('custom_conf').attr("content", tx_msg+dojo__button_no+dojo__button_third+dojo__button_yes);
			}else{
				dijit.byId('custom_conf').attr("content", tx_msg+dojo__button_yes+dojo__button_third+dojo__button_no);
			}
		}else{
						
			if (ret_function){dojo_button_ok='<span title="Cancel" class="dijitDialogCloseIcon" onclick="javascript:dijit.byId(\'custom_conf\').hide();'+ret_function+'(true);">	<span title="Cancel" class="closeText" >x</span></span>';}	
		
		dijit.byId('custom_conf').attr("content", tx_msg+dojo_button_ok);}
				
				
		
		
		dijit.byId('custom_conf').show();
		if (yes_btn!='' || topbutton==1 || dojo_button_ok!=''){document.getElementById('custom_conf_djOKb').style.display='none';}
		
				
		//document.getElementById('custom_conf_content').innerHTML = tx_msg+dojo__button_no+dojo__button_yes;	}else{document.getElementById('custom_conf_content').innerHTML = tx_msg;}
		//if( typeof(width_c) != 'undefined' ){document.getElementById('custom_conf').style.width= width_c+"px";}else{document.getElementById('custom_conf').style.width="250px";}
		
	}
	

function moo_confirm( ret_function, tx_msg, title_ms, yes_btn, no_btn, width_c, height_c, topbutton, button_third, overflow, aftertext, onopen ){
		if (!height_c){ height_c='auto'; }else if( height_c==''){ height_c='auto'; }else{ height_c=height_c+'px';}
		if (!width_c){ width_c='auto'; }else if( width_c==''){ width_c='auto'; }else{ width_c=width_c+'px';}
			
		$title_moo='<div style="font-size: 13px; font-weight:bold; line-height:13px; background-color: rgb(255, 204, 153); height: 20px; margin-bottom: 15px;"><div style="padding:5px 5px 8px 5px;">'+title_ms+'</div></div>';
		
		if (yes_btn){if (yes_btn!=''){ $button_yes='&nbsp;<input type="button" onclick="'+ret_function+'(true);SqueezeBox.close();" value="'+yes_btn+'">'; }else{$button_yes='';}}else{$button_yes='';}
		if (button_third){if (button_third!=''){ $button_third ='&nbsp;<input type="button" onclick="'+ret_function+'1(false);SqueezeBox.close();" value="'+button_third+'">&nbsp;'; }else{$button_third='&nbsp;&nbsp;';}}else{$button_third='&nbsp;&nbsp;';}
		if (no_btn){if (no_btn!=''){ $button_no ='<input type="button" onclick="'+ret_function+'(false);SqueezeBox.close();" value="'+no_btn+'">&nbsp;'; }else{$button_no='';}}else{$button_no='';}
		if (aftertext){if (aftertext!=''){ $aftertext ='<br />'+aftertext; }else{$aftertext='';}}else{$aftertext='';}
		
		if (button_style==0){
				$buttons = $button_no+$button_third+$button_yes+$aftertext+'<br />';
			}else{
				$buttons = $button_yes+$button_third+$button_no+$aftertext+'<br />';
			}
			
		var prozor = new Element('div', {});
		prozor.setStyle( 'text-align', 'center');
		prozor.setStyle( 'color', '#000');
		prozor.setStyle( 'font-size', '13px');
		prozor.setStyle( 'line-height', '15px');
		prozor.set('html', $title_moo+tx_msg+'<br /><br />'+$buttons  );
		window.addEvent("domready", function() { 
			SqueezeBox.initialize({});
			SqueezeBox.open(prozor, { handler: 'adopt', size: {x: width_c , y:height_c }, onClose: function() {}, onOpen: function() {eval(onopen);} });
			if(overflow!=0){document.getElementById('sbox-content').style.overflow='hidden';}else{document.getElementById('sbox-content').style.overflow='auto';}
		});
}

var counterdialog=0;
function moo_dialogAlert(Title, Alert){

		var prozor = new Element('div', {});
							counterdialog++;
							prozor.setStyle( 'text-align', 'center');
							//prozor.setStyle( 'width', 'auto');
							prozor.set('html', '<div style="font-size:13px;background-color:#FC9;height:20px;margin-bottom:15px;">'+Title+'</div><div style="font-size:15px;color:#F00;">'+Alert+'</div>' );
							SqueezeBox.initialize({});
							SqueezeBox.open(prozor, { handler: 'adopt', size: {x: 300, y: 90, width:'auto' }, onClose: function(){}, onOpen:function(){this.overlay.removeEvents('click');}  });
}




	
	
function zoom(page_id_side){
		var winW = 630, winH = 460;

	if (parseInt(navigator.appVersion)>3) {
 	if (navigator.appName=="Netscape") {
  	winW = window.innerWidth;
  	winH = window.innerHeight;
	 }
 	if (navigator.appName.indexOf("Microsoft")!=-1) {
  	winW = document.body.offsetWidth;
  	winH = document.body.offsetHeight*0.8;
 	}
	}

		
		page_id=document.getElementById(page_id_side).value;
		if (page_id!=0){
		zoom_d=dijit.byId('zoom_dialog');
		zoom_d.attr("href", '/creator/ajax/zoom.php?page_id='+page_id+'&w='+winW+'&h='+winH);
		
		dojo.style(zoom_d.domNode, {width: 0.7*winW+"px"});
		dojo.style(zoom_d.domNode, {height: 0.9*winH+"px"});
		dijit.byId('zoom_dialog').attr("loadingMessage", '<span class="dijitContentPaneLoading">'+zoom_msg+'</span>');
		dijit.byId('zoom_dialog').show();
		
		document.getElementById('zoom_dialog_djOKb').innerHTML='<span  style="margin-top: 4px;" class="dijit dijitReset dijitLeft dijitInline dijitButton" ><span class="dijitReset dijitRight dijitInline"><span class="dijitReset dijitInline dijitButtonNode"><span class="dijitReset dijitInline"><span class="dijitReset dijitToggleButtonIconChar"></span></span><span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_0_label" dojoattachpoint="containerNode">'+Zatvori_js+'</span></span></span></span>';
		//“dijit.byId('zoom_dialog').attr("width", winH*1.2+"px;");
		}
		document.getElementById('zoom_dialog_djOKb').className='';
		//alert(dijit.byId('zoom_dialog').style.width);
	}

// right click test
function clickIE4(){ if (event.button==2){return false;}}
function clickNS4(e){if (document.layers||document.getElementById&&!document.all){if (e.which==2||e.which==3){return false;}}}
if (document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS4;}else if (document.all&&!document.getElementById){document.onmousedown=clickIE4;}
document.oncontextmenu=new Function("return false")
//
 
	
function custom_confirm_html( ret_function, url_cont, title_ms, width_c, load_mess, ok_butt ){
	
	if (ok_butt == '1') {
			buttontop='<img alt="Zatvori" title="Zatvori" onclick="dijit.byId(\'custom_conf\').hide();" onmouseout="javascript:this.src=\'../images/close.png\'" onmouseover="javascript:this.src=\'../images/close_o.png\';" src="../images/close.png" name="upload" style="margin: 2px; position: absolute; float: right; right:5px;top:-2px"/>';
			dijit.byId('custom_conf').attr("title", title_ms+buttontop);
			}else{dijit.byId('custom_conf').attr("title", title_ms);}
		
	if( typeof(width_c) != 'undefined' ) {dojo.style(dijit.byId('custom_conf').domNode, {width: width_c+"px"});}else{dojo.style(dijit.byId('custom_conf').domNode, {width: "250px"});}
	
	dijit.byId('custom_conf').attr("href", url_cont);
	dijit.byId('custom_conf').show();
	document.getElementById('custom_conf_djOKb').style.display='none';
	
	}
	

function salji_crop(div_wid ,div_heig, div_left, div_top, foto_id, div_w_temp, div_h_temp, $page_i){
	if (document.getElementById("filter_sel")) { document.template.filter.value=korekcija_foto( foto_id , 1  ); }else{document.template.filter.value="";}
	if(document.getElementById ('page_id_l').value == $page_i){SelectOpenPage('page_id_l');}else{SelectOpenPage('page_id_r');}
	document.getElementById('scrop').value=div_wid/parseInt(document.getElementById('cropbox').style.width);
	//korekcija=document.getElementById('scrop').value*document.getElementById('scrop').value;
	korekcija=0;
	document.getElementById('xcrop').value=((parseInt(document.getElementById('cropbox').style.left)-div_left)*div_w_temp/div_wid);
	document.getElementById('ycrop').value=((parseInt(document.getElementById('cropbox').style.top)-div_top)*div_h_temp/div_heig)-korekcija;
	document.getElementById('icrop').value=foto_id;
	gif_on();
	document.template.submit();
	dijit.byId('custom_conf').hide();
	}	
	
	
	
//urldecode-encode	
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

function korekcija_foto( fid, mode  ){
	//if (mode==99){ return fid; }
	izlaz_kor='fid='+fid+'&mode='+mode;
	fcomm1='';
	filteri=new Array();
	
	var sel = document.getElementById("filter_sel").options[document.getElementById("filter_sel").selectedIndex].value;
	if (sel!=""){filteri[filteri.length] =sel;}
	
	for(i=0; i<document.fotokorekcija.elements.length; i++) {
		if (document.fotokorekcija.elements[i].checked ){
			filteri[filteri.length] =document.fotokorekcija.elements[i].value ;
		}
	}
	
	fcomm=filteri.join(',');
	if ( fcomm.length > 0 ){fcomm1='&filteri='+fcomm;}
	
	izlaz_kor=izlaz_kor + fcomm1 ;
	
	if ( mode==0 ){
		
	 	var strURL='/creator/ajax/korekcija.php';
   	 	var xmlHttpReq = false;
   	 	var self = this;
   	 	// Mozilla/Safari - IE
   	 	if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); } else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
   		self.xmlHttpReq.open('POST', strURL, true);
   	 	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  	  	self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { korekcija_update(self.xmlHttpReq.responseText, 99);} }
		self.xmlHttpReq.send(izlaz_kor);	
		}else{ return fcomm; }
	}
	
 function korekcija_update(resp){
	 	document.getElementById('foto_bc').style.backgroundImage = 'url('+resp+')';
	   	document.getElementById('crop_float').src=resp;
	};
	
