// test na povinne parametry formulare
function checkMe(tf,text,pars)
{
	pole=pars.split(',');
	for(i=0;i<pole.length;i+=2)
	{
		if(eval('typeof  tf.'+pole[i])!='undefined'){
			if(eval('tf.'+pole[i]+'.value')=='')
			{
				alert(pole[(i+1)]+' '+text);
				eval('tf.'+pole[i]+'.focus()');
				return false;
			}
		}
	}
	return true;
}

// nove okno
function previewWindow(url, title)
{
	window.open(url, title, "toolbar=no,status=yes,scrollbars=yes,resizable=yes,width=800,height=600");
}

function newwindow(url,title){
	window.open(url, title, "toolbar=yes,status=yes,scrollbars=yes,resizable=yes");
}


// vraci hodnotu z popup okna zpet do formulara
function backToForm(elName, newId, newName){

//	if (window.showModalDialog) {
//		dialogArguments.document.all(dialogArguments.elementFk).value = newId;
//		dialogArguments.document.all(dialogArguments.elementName).innerHTML = newName;
//	} else { //Netscape
		var opnr=window.opener;
		opnr.document.getElementById(elName+'_fk').value=newId;
		opnr.document.getElementById(elName+'_name').innerHTML=newName;	
//	}
	window.setTimeout('window.close()',10);
}

// smaza hodnoty z formulare u tematu 
function deleteFormInput(name){
	document.getElementById(name+'_fk').value='';
	document.getElementById(name+'_name').innerHTML='';
}

// Otevre okno pro vyber souboru (reuse)
function chooseFile(inpId){
//	if (window.showModalDialog) {
//		window.elementFk = inpId+'_fk';
//		window.elementName = inpId+'_name';
//		showModalDialog ("../fileman/files.asp?inpID="+inpId, window, "dialogheight=600px;dialogwidth=800px;status=no;toolbar=no;menubar=no;location=no;resizable=yes;scroll:yes")
//	} else {
		window.open("../fileman/files.asp?inpID="+inpId, 'zipWindow', 'width=800,height=600,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,')
//	}
}



function InsertTag(oElement, ThisTagName) {
  if (document.selection) { 
	  if ( typeof(oElement) == 'object' ) {
	 	  oElement.focus();
	 	  if ( typeof(document.selection.createRange()) == 'object' ) {
	 			var seltext = document.selection.createRange();
	  		seltext.text = ThisTagName + seltext.text ;
	  		document.selection.clear;
	  	}
	  }
  }else{	  
	oldValue = oElement.value;
	if (oElement.selectionStart == oElement.selectionEnd) {
		selStart = oldValue.substring(0,oElement.selectionStart);
		selEnd = oldValue.substring(oElement.selectionStart, oElement.textLength);
		oElement.value = selStart + ThisTagName + selEnd;
	} else {
		oElement.value = oElement.value +  ThisTagName ;
	}
	
  }		
}
function InsertTagFile(oElement, ThisTagName) {
  if (window.opener.document.selection) { 
	  if ( typeof(oElement) == 'object' ) {
	 	  oElement.focus();
	 	  if ( typeof(window.opener.document.selection.createRange()) == 'object' ) {
	 			var seltext = window.opener.document.selection.createRange();
	  		seltext.text = ThisTagName + seltext.text ;
	  		window.opener.document.selection.clear;
	  	}
	  }
  }else{	  
	oldValue = oElement.value;
	if (oElement.selectionStart == oElement.selectionEnd) {
		selStart = oldValue.substring(0,oElement.selectionStart);
		selEnd = oldValue.substring(oElement.selectionStart, oElement.textLength);
		oElement.value = selStart + ThisTagName + selEnd;
	} else {
		oElement.value = oElement.value +  ThisTagName ;
	}
	
  }		
}

function SmajlClick(ItemName, a) {
  InsertTag(document.getElementById(ItemName), '<smajlik' + a + '>');
}
function replyClick(ItemName, a) {
  InsertTag(document.getElementById(ItemName), '' + a + ': ');
}
function FileClick(ItemName, filName) {
  InsertTagFile(window.opener.document.getElementById(ItemName), '<fotka' + filName + '>');
  //alert('cop.. copak' + window.opener.document.getElementById(ItemName).value);
  window.setTimeout('window.close()',10);
}
function RefreshConn() 
{
	var dtNow;
	dtNow = new Date();
	strTimestamp = dtNow.getTime();
	document.getElementById('ImageRefresh').src = "reload.asp?&timestamp=" + strTimestamp;
	nID = setTimeout("RefreshConn()", 300000);
};

function vydaniPreview(menId){
	datum=document.getElementById("reuFrom").value
	window.open('http://www.punk.cz/index.asp?menu='+menId+'&redakcePreview=ok&datePrview='+datum);
}

function predejVybraneObjednavky(srcName,descID){
	var elms, retv, elm;
	
	retv='0';
	elms=document.getElementsByName(srcName);
	for(var i=0;i<elms.length;i++){
		if(elms[i].checked) retv+=','+elms[i].value;
	}
	elm=document.getElementById(descID);
	elm.value=retv;	
}

