
/**
 * Common javascript
 * <p>
 * (C) comundus GmbH, D-71332 WAIBLINGEN, www.comundus.com
 * @author $Author: nguyen $
 * @version $Revision: 1.3 $ ($Date: 2004/07/01 15:22:19 $)
 */

/*
   $Log: common.js,v $
   Revision 1.3  2004/07/01 15:22:19  nguyen
   Version bei Klinikum KA, 1.7.04

   Revision 1.2  2004/04/13 11:47:18  nguyen
   LDAP angebildet

   Revision 1.1.1.1  2004/04/05 10:46:35  nguyen
   no message

*/

var clicked=false;

function FillForm(username, email, office, phone,firstname,lastname,room,department,costcenter)
{
	window.opener.document.ticket.username.value = username;

	if (window.opener.document.ticket.email!=null)
		window.opener.document.ticket.email.value = email;

//Bei Verwendung der Adresse wird der Nachname und Vorname in separate Felder eingetragen
	if (window.opener.document.ticket.office!=null)
		window.opener.document.ticket.office.value = lastname;

	if (window.opener.document.ticket.firstname!=null)
		window.opener.document.ticket.firstname.value = firstname;
//Werden keine Adressdaten verwendet, diesen Bereich aktivieren
/*	if (window.opener.document.ticket.office!=null)
		window.opener.document.ticket.office.value = lastname + " " + firstname;
*/
	if (window.opener.document.ticket.phone!=null)
		window.opener.document.ticket.phone.value = phone;

	if (window.opener.document.ticket.room!=null)
		window.opener.document.ticket.room.value = room;

	if (window.opener.document.ticket.department!=null)
		window.opener.document.ticket.department.value = department;

	if (window.opener.document.ticket.cost_centre!=null)
		window.opener.document.ticket.cost_centre.value = costcenter;


	window.close();

}
/* Nur aktivieren wenn wirklich benötigt. Funktioniert nicht unter Firefox und Mac */
/* variable "short1" muss umbenannt werden, da Firefox diese als standardvariable erkennt!!! */
/*function fillSuggestionText(question,answer)
{
	while ( answer.indexOf("<br />")!=-1)
	{
		answer = answer.replace("<br />","\n");
	}

	window.opener.document.ticket.short1.value =question;
	window.opener.document.ticket.description.value = answer;
	window.close();

}*/

function fillParentTicket(id)
{
	window.opener.document.ticket.parentId.value = id;
	doc = window.opener.document;
	doc.getElementById('tparent').innerText=id;
	window.close();
	doc.ticket.submit();
}


function deleteParentTicket()
{
	window.document.ticket.parentId.value = "";
	doc = window.document;
	//doc.getElementById('tparent').innerText="";
	document.ticket.submit();

}

function doSearchUser(e)
{
	if  (window.event && window.event.keyCode == 13)
	{
	    document.forms[0].searchbutton.click();
		return false;
	}


	if  (e && e.which == 13)
	{
		document.forms[0].searchbutton.click();
		return false;
	}
	return true;

}

function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
//	document.ticket.anchor.value = "";
/*	if (document.ticket.pageXOffset)
		document.ticket.pageXOffset = 5;
	if (document.ticket.pageYOffset)
		document.ticket.pageYOffset = 200;
*/
	document.ticket.submit();
}


function onDuplicate(id)
{
	window.navigate ('index_content.php?t=tcre&id='+id);
	location.href = 'index_content.php?t=tcre&id='+id;
	//document.ticket.duplicate.value = id;
	//document.ticket.submit();
}

function checkTicketId()
{
	if (document.formTicketSearch.id.value=="" || !document.formTicketSearch.id.value)
	{
		return false;
	}
	return true;
}




function MM_jumpMenuafda(targ,selObj,restore)
{ //v3.0
//	document.ticket.anchor.value = "cat";
	document.ticket.submit();
}

function chooseParent(qrystr)
{

		lookupWin = window.open("../modules/parent_child/tparent_ticket.php?qry=" + qrystr, "UserLookup"," width=590,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,left=0,top=0");
		lookupWin.focus();

}

function showSuggestionText(qrystr)
{
		lookupWin = window.open("../modules/suggestion_text/suggestiontext_view.php?subcat=" + qrystr, "Vorschlagstexte"," width=590,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,left=0,top=0");
		lookupWin.focus();
}

function showSuggestionTextForUser(qrystr)
{
		lookupWin = window.open("modules/suggestion_text/suggestiontext_view.php?subcat=" + qrystr, "Vorschlagstexte"," width=590,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,left=0,top=0");
		lookupWin.focus();
}


function showQuestionText()
{
	if (document.ticket.qaid!=null)
	  assigned_id=document.ticket.qaid.value;

/*        if (!assigned_id)
	{
	    alert("Es gibt keinen Fragetext!");
	    return false;

	}*/



	lookupWin = window.open("../modules/question_text/questiontext_display.php?assigned_id="+assigned_id, "UserLookup"," width=590,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,left=0,top=0");
		lookupWin.focus();

}


function showChildren(qrystr)
{

		lookupWin = window.open("../modules/parent_child/tchild.php?qry=" + qrystr, "UserLookup"," width=590,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,left=0,top=0");
		lookupWin.focus();

}

function showParent(qrystr)
{

		lookupWin = window.open("../modules/parent_child/tparent.php?qry=" + qrystr, "UserLookup"," width=590,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,left=0,top=0");
		lookupWin.focus();

}



function prefill(qrystr)
{
	if (qrystr != "") {
		lookupWin = window.open("tuserlookup.php?qry=" + qrystr, "UserLookup"," width=590,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,left=0,top=0");
		lookupWin.focus();
	}
}

function showHistory(qrystr)
{
	if (qrystr != "") {
		lookupWin = window.open("../modules/user_history/history_search.php?qry=" + qrystr, "UserHistory"," width=590,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,left=0,top=0");
		lookupWin.focus();
	}
}

function showEmail()
{
		lookupWin = window.open("../modules/email_cc/email_search.php?qry=","UserEmail"," width=590,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,left=0,top=0");
		lookupWin.focus();

}


function srollto(x,y)
{
	window.scrollTo(x, y);
}

function openDokutoolForInfo(sHref)
{
        windowOpen = window.open(sHref,'Information', " width=700,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,left=10,top=10");
        windowOpen.focus();
}

/*
function openDokutoolForSearch(sDokutoolPath,sTableName,sCondColName,iCondType,sSQL)
{
	var sPath = "/dokutool_VoBa";
	var sDokutoolKey = document.ticket.platform_key.value;
	var sDokutoolVal = document.ticket.platform_value.value+"%";
	var sParamAll;
	var sCond;
	sParamAll = sDokutoolKey+"="+sDokutoolVal;
	if (iCondType==1)
	{
		sParamAll = sParamAll + "&" + sCondColName + "=" + document.ticket.username.value+"%";
	}

//	sHref = "/dokutool/db-extern/search.php?table="+sPlatform+"&colName="+sDokutoolKey+"&"+sDokutoolKey+"="+sDokutoolVal+"&submits=true"
	sHref = sPath+"/db-extern/search.php?table="+sTableName+"&submits=true"+"&"+sParamAll;
    windowOpen = window.open(sHref,'Suchen', " width=700,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,left=10,top=10");
    windowOpen.focus();
}
*/

function openDokutoolForSearch(sDokutoolPath,sTableName,sCondColName,iCondType,sSQL)
{
	var sDokutoolKey = document.ticket.platform_key.value;
	var sDokutoolVal = document.ticket.platform_value.value+"%";
	var sParamAll;
	var sCond;

//	sParamAll = sDokutoolKey+"="+sDokutoolVal;

	sParamAll = "table="+sTableName+"&colname=" + sDokutoolKey + "&submits=true"+"&"+sDokutoolKey+"="+sDokutoolVal;

	if (iCondType==1)
	{
		if (sSQL!='')
		{
			sSQLNew = sSQL.replace("{platform_key}",sDokutoolKey);
			sSqlCond = sDokutoolVal+","+ document.ticket.username.value+"%";
			sParamAll = sParamAll + "&sql=" + sSQLNew + "&sqlcond="+sSqlCond;
		}
		else
		{
			sParamAll = sParamAll + "&" + sCondColName + "=" + document.ticket.username.value+"%";
		}
	}

	sHref = sDokutoolPath+"/db-extern/search.php?"+sParamAll;
    windowOpen = window.open(sHref,'Suchen', " width=700,height=550,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,left=10,top=10");
    windowOpen.focus();
}

function ignoreSupporter()
{
	document.ticket.ignore.value = "true";
	document.ticket.submit();
}

function check_private_aufgabe()
{

	if (document.ticket.private_aufgabe.value=="on")
	{
		document.ticket.private_aufgabe.value="off";
	}
	else
	{
		document.ticket.private_aufgabe.value="on";
	}
}

function validateFeedbackDlg(name,firstname,street,postcode,location,email)
{
	if (document.ticket.name.value =="")
	{
		alert (unescape(name));
		return false;
	}
	
	if (document.ticket.firstname.value =="")
	{
		alert (unescape(firstname));
		return false;
	}
	
	if (document.ticket.street.value =="")
	{
		alert (unescape(street));
		return false;
	}
		if (document.ticket.postcode.value =="")
	{
		alert (unescape(postcode));
		return false;
	}
	
	if (document.ticket.location.value =="")
	{
		alert (unescape(location));
		return false;
	}
	
	if (document.ticket.email.value !="" && isValidEmail(document.ticket.email.value,email)==false)
	{
		return false;
	}
	
	return true;
}




function submitFeedbackDlg(name,lastname,street,postcode,ort,email)
{	
	if (document.ticket.sb.value=="")
	{
	   return false;	
	}
	
	
	
	if (validateFeedbackDlg(name,lastname,street,postcode,ort,email)==true)
	{
		document.ticket.submit();
		document.ticket.sb.value="";
	}
	
	
}

function submitDialog2(des)
{	
	if (document.ticket.description.value =="")
	{		
		alert (unescape(des));		
		return false;
	}
	else
	{
		document.ticket.sb1.value="Submit";
		document.ticket.submit();
	}
	
}




function isValidEmail(str,email_msg) 
	{
	var checkEmail = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/;
	var	email = str;
	var checked = true;
	if ((checkEmail.test(email)) == false || email.length == 0)
		{
			alert (unescape(email_msg));  
			checked = false;
		}
	return checked;
	}
	
function FillEmail(email)
{
	if (window.opener.document.ticket.email_cc!=null)
		window.opener.document.ticket.email_cc.value = email;

	window.close();

}

function doSubmit (button)
{
	if (document.ticket.sb.value=="") return;	
	document.ticket.submit();
	document.ticket.sb.value="";
	return true;
}

function checkMandantInstall()
{
	if (document.ticket.url.value=="")
	{
		alert ("Feld Url darf nicht leer bleiben.");
		return false;
	}
	if (document.ticket.db_host.value=="")
	{
		alert ("Feld DB-Host darf nicht leer bleiben.");
		return false;
	}
	
	if (document.ticket.db_user.value=="")
	{
		alert ("Feld DB-User darf nicht leer bleiben.");
		return false;
	}
	
	if (document.ticket.db_password.value=="")
	{
		alert ("Feld DB-Passwort darf nicht leer bleiben.");
		return false;
	}
	
	if (document.ticket.db_name.value=="")
	{
		alert ("Feld DB-Name darf nicht leer bleiben.");
		return false;
	}
	
	if (document.ticket.destination_email.value=="")
	{
		alert ("Feld Destinationsemail darf nicht leer bleiben.");
		return false;
	}
	else
	{
		if (!isValidEmail(document.ticket.destination_email.value,"falsches Email."))
		{
			return false;
		}
	}
	
	if (document.ticket.sender_email.value=="")
	{
		alert ("Feld Senderemail darf nicht leer bleiben.");
		return false;
	}
	else
	{
		if (!isValidEmail(document.ticket.sender_email.value,"falsches Email."))
		{
			return false;
		}
	}
	return true;
}

function doResetMandantInstall()
{
	document.ticket.sender_email.value="";
	document.ticket.destination_email.value="";
	document.ticket.db_password.value="";
	document.ticket.db_name.value="";
	document.ticket.db_host.value="";
	document.ticket.db_user.value="";
	document.ticket.url.value="";
	//document.ticket.act.value="";
	if (document.ticket.mandant!=null)	
	  document.ticket.mandant.value="";
	document.ticket.sb.value="Mandant einfügen";
	return true;

	
}
function doSubmitFeedback1(priority)
{
	document.ticket.priority.value = priority
	document.ticket.submit();
}
function myreload()
{
	location="index_nav.php";
	
}

function insertSignature()
{	
	document.ticket.email_msg.value = document.ticket.email_msg.value + "\n\n\n" + document.ticket.mysignature.value;
}
function doCSVExport(language)
{
	
	sRef = "../modules/csv_export/csv_export.php?language="+language;

	
	if (document.ticket.platform.value!="")
	{
		sRef = sRef + "&platform="+document.ticket.platform.value;
	}
	
	
	if (document.ticket.category.value!="")
	{
		sRef = sRef + "&category="+document.ticket.category.value;
	}
	
	if (document.ticket.priority.value!="")
	{
		sRef = sRef + "&priority="+document.ticket.priority.value;	
		
	}
	
	if (document.ticket.date_from.value!="")
	{
		sRef = sRef + "&date_from="+document.ticket.date_from.value;	
		
	}
	
	if (document.ticket.date_to.value!="")
	{
		sRef = sRef + "&date_to="+document.ticket.date_to.value;	
		
	}
	
	if (document.ticket.group.value!="")
	{
		sRef = sRef + "&group="+document.ticket.group.value;	
		
	}
	
	lookupWin = window.open(sRef,'Suchen', " width=50,height=50,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,left=0,top=0");
	
	
}


function doOneSubmit()
{
	if (clicked==true) return false;
	
	clicked=true;
	return true;
}

function doDeleteTicket (msg)
{
	var ok= window.confirm(msg+" ");
	return ok;
}
