function call_service_init(){
	
	call_waiting_enable_change();
	//if (fxs_num=="2") hunting_group2ports(document.callform);
	call_ports_hotline_enable_change(document.callform);
}

function call_ports_hotline_enable_change()
{
		var f=document.callform;
		call_port_hotline_enable_change(f.call_port0_hotline_enable,0);
		if (fxs_num=="2") call_port_hotline_enable_change(f.call_port1_hotline_enable,1);
}

function call_port_hotline_enable_change(e, port)
{
	
	if (e.checked) {	// enabled
		id_visible("row_port"+port+"_hotline_number");
	} else {
		id_invisible("row_port"+port+"_hotline_number");
	}
}

function call_waiting_enable_change()
{	
	var f=document.callform;
	if (f.call_waiting_enable.checked) {	// enabled
		document.getElementById("row_call_waiting_timeout").className = "data_visible";
	} else {
		document.getElementById("row_call_waiting_timeout").className = "data_invisible";
	}
}


function hunting_group2ports(f)
{
	var portlist=f.call_hunting_group.value;
	var ports, p, i;

	ports=portlist.split(" ");
	for (i=0; ports[i]; i++) {
		switch (parseInt(ports[i])) {
			case 0:	f._call_hunting_port0.checked=true; break;
			case 1:	f._call_hunting_port1.checked=true; break;
		}
	}
}	

function hunting_ports2group(f)
{
	f.call_hunting_group.value="";
	if (f._call_hunting_port0 && f._call_hunting_port0.checked)
		f.call_hunting_group.value=f.call_hunting_group.value+"0 ";
	if (f._call_hunting_port1 && f._call_hunting_port1.checked)
		f.call_hunting_group.value=f.call_hunting_group.value+"1 ";
}

function submitchk(f)
{
	if (	!value_between(f.call_waiting_timeout.value, 10, 100, "Call Waiting Timeout should be between 10..100.") ||
		!value_between(f.call_attended_transfer_timeout.value, 5, 32, "Call Attended Transfer Timeout should be between 5..32.") ) {
		return true;
	}
	if (	!valid_or_null(f.call_port0_forward_busy_uri.value, is_string, "Port 1 Call Forward on Busy URI is in invalid format.") ||
		!valid_or_null(f.call_port0_forward_noans_uri.value, is_string, "Port 1 Call Forward on No Answer URI is in invalid format.") ||
		!valid_or_null(f.call_port0_forward_always_uri.value, is_string, "Port 1 Call Forward Always URI is in invalid format.") ||
		!value_between(f.call_port0_auto_answer_timeout.value, 10, 300, "Port 1 Auto Answer Timeout should be between 10..300.") ) {
		return false;
	}
	
	if (!integer_between(f.call_port0_auto_answer_timeout.value, 10, 300, "Port 1 Auto Answer Timeout should be an integer between 10..300.") ) {
		return false;
	}
	if (f.call_port0_hotline_enable.checked && !is_digits(f.call_port0_hotline_number.value)) {
		alert("Port 1 Hot line number is invalid");
		return false;
	}
	
	if (fxs_num=="2"){
		/*f.call_hunting_group.value="";
		
		if(f._call_hunting_port0.checked==true)
			f.call_hunting_group.value="0 ";
			
		if(f._call_hunting_port1.checked==true)
			f.call_hunting_group.value+="1";
		//f._call_hunting_port0.checked+" "+f._call_hunting_port0.value;
		*/
		if (!valid_or_null(f.call_port1_forward_busy_uri.value, is_string, "Port 2 Call Forward on Busy URI is in invalid format.") ||
			!valid_or_null(f.call_port1_forward_noans_uri.value, is_string, "Port 2 Call Forward on No Answer URI is in invalid format.") ||
			!valid_or_null(f.call_port1_forward_always_uri.value, is_string, "Port 2 Call Forward Always URI is in invalid format.") ||
			!value_between(f.call_port1_auto_answer_timeout.value, 10, 300, "Port 2 Auto Answer Timeout should be between 10..300.") ) {
			return false;
		}
		
		if (!integer_between(f.call_port1_auto_answer_timeout.value, 10, 300, "Port 2 Auto Answer Timeout should be an integer between 10..300.") ) {
			return false;
		}
		
		if (f.call_port1_hotline_enable.checked && !is_digits(f.call_port1_hotline_number.value)) {
			alert("Port 2 Hot line number is invalid");
			return false;
		}
	}
	
	return true;
}

