//Der Feld für Kommentare wird auf 100 Zeichen begrenzt
function limitText(limitField) {
    if (limitField.value.length > 110) {
        limitField.value = limitField.value.substring(0, 110);
    } 
}

function resize(){
	if(window.sizeToContent) window.sizeToContent();
}
function closeW(){
	this.window.close();
}


function hide_elements(fromid_txt,matchtype_txt){
	var fromDirection=document.getElementById("fromDirection");
	var toDirection=document.getElementById("toDirection");
	var FromSipBox=document.getElementById("FromSipBox");
	var FromIsdnBox=document.getElementById("FromIsdnBox");
	var FromAnalogBox=document.getElementById("FromAnalogBox");
	var FromGsmBox=document.getElementById("FromGsmBox");
	var manualSip=document.getElementById("manualsip");
	var manualSipFrom=document.getElementById("manualsipfrom");
	var toSipBox=document.getElementById("toSipBox");
	var toIsdnBox=document.getElementById("toIsdnBox");
	var toAnalogBox=document.getElementById("toAnalogBox");
	var toGsmBox=document.getElementById("toGsmBox");
	var toSip=document.getElementById("to_sip");
	var match_type=document.getElementById("match_type");
	var from_txt=document.getElementById("from_txt");
	var fromSip=document.getElementById("from_sip");
	if ((fromDirection.selectedIndex==0) && (toDirection.selectedIndex==0)){
		//Wenn keine ISDN oder ANALOG Gruppe existiert.
		if(typeof(toDirection.options[1])=="undefined"){
			alert("From direction: SIP and To direction: SIP is not allowed. Please add a new ISDN or ANALOG group.");
			window.close();
			return;
		}else{
			alert("From direction: SIP and To direction: SIP is not allowed");
		}
		toDirection.options[1].selected=true;
	}
	if (fromDirection.options[fromDirection.selectedIndex].value=="sip"){
		from_txt.innerHTML="<b>"+matchtype_txt+":<br><br>"+fromid_txt+":</b>";
		FromSipBox.style.display="";
		FromAnalogBox.style.display="none";
		FromIsdnBox.style.display="none";
		FromGsmBox.style.display="none";
	}else if (fromDirection.options[fromDirection.selectedIndex].value=="isdn"){
		from_txt.innerHTML="<b>"+fromid_txt+":</b>";
		FromSipBox.style.display="none";
		FromAnalogBox.style.display="none";
		FromGsmBox.style.display="none";
		FromIsdnBox.style.display="";
	}else if (fromDirection.options[fromDirection.selectedIndex].value=="analog"){
		from_txt.innerHTML="<b>"+fromid_txt+":</b>";
		FromSipBox.style.display="none";
		FromAnalogBox.style.display="";
		FromIsdnBox.style.display="none";
		FromGsmBox.style.display="none";
	}else if (fromDirection.options[fromDirection.selectedIndex].value=="gsm"){
		from_txt.innerHTML="<b>"+fromid_txt+":</b>";
		FromSipBox.style.display="none";
		FromAnalogBox.style.display="none";
		FromIsdnBox.style.display="none";
		FromGsmBox.style.display="";
	}
	
	if (toDirection.options[toDirection.selectedIndex].value=="sip"){
		toSipBox.style.display="";
		toAnalogBox.style.display="none";
		toIsdnBox.style.display="none";
		toGsmBox.style.display="none";
	}else if (toDirection.options[toDirection.selectedIndex].value=="isdn"){
		toSipBox.style.display="none";
		toAnalogBox.style.display="none";
		toGsmBox.style.display="none";
		toIsdnBox.style.display="";
	}else if (toDirection.options[toDirection.selectedIndex].value=="analog"){
		toSipBox.style.display="none";
		toAnalogBox.style.display="";
		toIsdnBox.style.display="none";
		toGsmBox.style.display="none";
	}else if (toDirection.options[toDirection.selectedIndex].value=="gsm"){
		toSipBox.style.display="none";
		toAnalogBox.style.display="none";
		toIsdnBox.style.display="none";
		toGsmBox.style.display="";
	}
	
	if (toSip.options[toSip.selectedIndex].value=="manual"){
		manualSip.style.display="";
	}else{
		manualSip.style.display="none";
	}
	
	if (match_type.options[match_type.selectedIndex].value=="manual"){
		manualSipFrom.style.display="";
		fromSip.style.display="none";				
	}else{
		manualSipFrom.style.display="none";
		fromSip.style.display="";
	}
}


function is_submit(form)
{
	var elem = document.getElementsByTagName("input");
	for (i=0;i<elem.length;i++){
		if (elem[i].type=="text"){
			elem[i].value= elem[i].value.replace(/\"/g,"\"");
			elem[i].value= elem[i].value.replace(/\'/g,"\"");
		}
	}
	return true;
}
