/*##################
	cms home roll over
################### */

function MyBut(norm,over,nmn) {
  if (document.images) {
    this.name=nmn;
    this.Normal=new Image();
    this.Normal.src=norm;
    this.Over=new Image();
    this.Over.src=over;
  }
}

// This is the function that moves the cursor to the end of content
function moveCursorToEnd(editor_id) {
    inst = tinyMCE.getInstanceById(editor_id);
    tinyMCE.execInstanceCommand(editor_id,"selectall", false, null);
    if (tinyMCE.isMSIE) {
        rng = inst.getRng();
        rng.collapse(false);
        rng.select();
    } 
    else {
        sel = inst.getSel();
        sel.collapseToEnd();
    }
}


function OverBut(btn)
{
  if (document.images){
     document.images['' + btn.name].src=btn.Over.src;
  }
}

function OutBut(btn){
  if (document.images){
    document.images['' + btn.name].src=btn.Normal.src;
  }
}

// ##############################

/*function SetThumbnailSrc(select, selected_id, part_path)
{
	img = document.images['preview_image'];
	tempPath_uplFile_pictureID = '/util/thumb.php?w=200&h=100&ID='+ select.value; 
	img.src = '/util/thumb_w_h.php?w=200&h=100&ID='+ select.value; 
	document.getElementById('filename_div_uplFile_pictureID').innerHTML = select.options[select.selectedIndex].text;
}*/

function SetThumbnailSrc(image_id, width, height)
{
	img = document.images['preview_image'];
	img.src = '/util/thumb_w_h.php?w=' + width + '&h=' + height + '&ID=' + image_id; 
}

function SetThumbnailSrcAndTitle (newSrc, newTitle){
	var img = document.getElementById('mainImage');
	img.src = newSrc; 
	img.alt = newTitle;
	img.title = newTitle;
}
function switchAnchorAndSpan(ordinalNo) {
	var i; 
	var galleryLinkName;
	var gallerySpanName;
	for(i=0; i<document.anchors.length; i++){
		//alert('document.anchors[i].name.substring(0, 12) = ~'+document.anchors[i].name.substring(0, 12)+'~');
		if(document.anchors[i].name.substring(0, 12) == 'galleryLink_'){
			//document.anchors[i].style.display='inline';
			galleryLinkName = 'galleryLink_'+(i+1).toString();
			gallerySpanName = 'gallerySpan_'+(i+1).toString();
			document.getElementById(galleryLinkName).style.display='inline';
				//alert('Menjam display za'+galleryLinkName+' - postaje inline');
			document.getElementById(gallerySpanName).style.display='none';
				//alert('Menjam display za'+gallerySpanName+' - postaje none');
		}
	}
	document.getElementById('galleryLink_'+ordinalNo).style.display='none';
	document.getElementById('gallerySpan_'+ordinalNo).style.display='inline';
}
//function SetThumbnailSrc(select, selected_id)
//{
//	img = document.images['preview_image'];
//	tempPath_uplFile_pictureID = '/util/thumb.php?w=200&h=100&ID='+ select.value; 
//	alert(img.src = '/util/thumb_w_h.php?w=200&h=100&ID='+ select.value); 
//	document.getElementById('filename_div_uplFile_pictureID').innerHTML = select.options[select.selectedIndex].text;
//}
	
function setDocumentFileID(FID, tagName)
{	
	//alert('U funkciji je tagName = ' + tagName);
	eval('document.forms[0].' + tagName + '_fileID.value = ' + FID);
}
function Setdocument1IDFilename(select, selected_id, part_path)
{
	document.getElementById('filename_div_uplFile_document1ID').innerHTML = select.options[select.selectedIndex].text;	
}
function Setdocument2IDFilename(select, selected_id, part_path)
{
	document.getElementById('filename_div_uplFile_document2ID').innerHTML = select.options[select.selectedIndex].text;	
}


function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function SetIconSrc(select, selected_id)
{
	img = document.images['preview_image'];
	filename = select.options[select.selectedIndex].text; 
	extension = Right(filename, 3);
	img.src = '/cms/delovi/images/' + extension + '.gif'; 
	document.getElementById('filename_div').innerHTML = filename;
}


function getSelectedFileName(sel, part_path)
{	
	return part_path + sel.options[sel.selectedIndex].text;
}
	
function go(pid)
{
	document.location = "index.php?PID="+pid;
}

function fixUrl(str)
{
	opener.location.reload();
	return str;
}

function openPopUp_Url_W_H(url,W,H,SCROLLBAR){
	//window.open(url,'', 'toolbar=0,scrollbars='+SCROLLBAR+',location=0,statusbar=0,menubar=0,resizable=0,width='+W+',height='+H);
	//var winObj = window.open(url,'', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=450');
	var winObj = window.open(url,'', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=0,width='+W+',height='+H);
	winObj.moveTo(screen.width/2-225,screen.height/2-250)
}

function ImagePopUp_Url_W_H(url,W,H,SCROLLBAR){
	var winObj = window.open(url,'', 'toolbar=0,scrollbars='+SCROLLBAR+',location=0,statusbar=0,menubar=0,resizable=0,width='+W+',height='+H);
	winObj.moveTo(screen.width/2-W/2,screen.height/2-H/2)
}

function openPopUp_SubmitUrl(url){
		window.open(url,'', 'toolbar=0,scrollbars=no,location=0,statusbar=0,menubar=0,resizable=0,width=350,height=100');
}


//*************
//	DHTML API
//*************
function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

//Item editor change folder
function changeFolder(sel_folder)
{
	document.location = window.location.search.replace(/\&folderID\=[0-9]*/g, "") + '&folderID='+sel_folder.value;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function clearText(field) {
if(field.defaultValue == field.value)
     field.value = "";
}

function usersSubmitForm(){	
	if (confirm('Da li ste sigurni?')){ 
		var forma=document.forms['formMain'];
		forma.submit(); 
	}

}
