
function sip_ports_enable_change()
{	
	f=document.sipaform;
	
	//sip_port_enable_change(f.sip_port0_enable,0);
	//if (fxs_num=="2") sip_port_enable_change(f.sip_port1_enable,1);
	sip_port_asserted_enable_change(f.sip_port0_asserted_enable,0);
	if (fxs_num=="2") sip_port_asserted_enable_change(f.sip_port1_asserted_enable,1);
}

function sip_port_enable_change(e, port)
{
	if (e.checked) {	// enabled
		document.getElementById("row_port"+port+"_username").className = "data_visible";
		document.getElementById("row_port"+port+"_displayname").className = "data_visible";
		document.getElementById("row_port"+port+"_auth_username").className = "data_visible";
		document.getElementById("row_port"+port+"_auth_password").className = "data_visible";
		document.getElementById("row_port"+port+"_confirm_password").className = "data_visible";
		document.getElementById("row_port"+port+"_asserted_enable").className = "data_visible";
		document.getElementById("row_port"+port+"_asserted_identity_uri").className = "data_visible";
		document.getElementById("row_port"+port+"_asserted_identity_displayname").className = "data_visible";
		//sip_port_asserted_enable_change(document.getElementById("sip_port"+port+"_asserted_enable"), port);
	} else {
		document.getElementById("row_port"+port+"_username").className = "data_invisible";
		document.getElementById("row_port"+port+"_displayname").className = "data_invisible";
		document.getElementById("row_port"+port+"_auth_username").className = "data_invisible";
		document.getElementById("row_port"+port+"_auth_password").className = "data_invisible";
		document.getElementById("row_port"+port+"_confirm_password").className = "data_invisible";
		document.getElementById("row_port"+port+"_asserted_enable").className = "data_invisible";
		document.getElementById("row_port"+port+"_asserted_identity_uri").className = "data_invisible";
		document.getElementById("row_port"+port+"_asserted_identity_displayname").className = "data_invisible";
	}
}

function sip_port_asserted_enable_change(e, port)
{
	if (e.checked) {	// enabled
		document.getElementById("row_port"+port+"_asserted_identity_uri").className = "data_visible";
		document.getElementById("row_port"+port+"_asserted_identity_displayname").className = "data_visible";
	} else {
		document.getElementById("row_port"+port+"_asserted_identity_uri").className = "data_invisible";
		document.getElementById("row_port"+port+"_asserted_identity_displayname").className = "data_invisible";
	}
}

function chk_mwi(obj,port){

	if(obj.checked==true){
		
		document.getElementById("row_port"+port+"_mwi_auth_username").className = "data_visible";
		document.getElementById("row_port"+port+"_mwi_auth_password").className = "data_visible";
		document.getElementById("row_port"+port+"_mwi_auth_password").className = "data_visible";
		document.getElementById("row_port"+port+"_mwi_confirm_password").className = "data_visible";
		document.getElementById("row_port"+port+"_mwi_refresh_timeout").className = "data_visible";
	}else{
		document.getElementById("row_port"+port+"_mwi_auth_username").className = "data_invisible";
		document.getElementById("row_port"+port+"_mwi_auth_password").className = "data_invisible";
		document.getElementById("row_port"+port+"_mwi_auth_password").className = "data_invisible";
		document.getElementById("row_port"+port+"_mwi_confirm_password").className = "data_invisible";
		document.getElementById("row_port"+port+"_mwi_refresh_timeout").className = "data_invisible";
	}
//


}

function submitchk(f)
{

	
	if (!valid(f.sip_port0_username.value, is_string, "Port 1 username should not have space.") ||
			!valid(f.sip_port0_auth_username.value, is_string, "Port 1 auth username should not have space.") ||
			!string_equal(f.sip_port0_auth_password.value, f.sip_port0_confirm_password.value, "Port 1 confirm password mismatches.")  
			// ||!string_equal(f.sip_port0_mwi_auth_password.value, f.sip_port0_mwi_confirm_password.value, "Port 1 MWI confirm password mismatches.")
		) {
			return false;
	}
		
	if (f.sip_port0_asserted_enable.checked){
		if (!valid(f.sip_port0_asserted_identity_uri.value, is_string, "Port 1 Asserted Identity URI should not have space.") ||
			!valid(f.sip_port0_asserted_identity_displayname.value, is_string, "Port 1 Asserted Identity Display Name should not have space.")){
				return false;
			}
	}

	

	if (fxs_num=="2"){
		if (	!valid(f.sip_port1_username.value, is_string, "Port 2 username should not have space.") ||
				!valid(f.sip_port1_auth_username.value, is_string, "Port 2 auth username should not have space.") ||
				!string_equal(f.sip_port1_auth_password.value, f.sip_port1_confirm_password.value, "Port 2 confirm password mismatches.")  
				//||!string_equal(f.sip_port1_mwi_auth_password.value, f.sip_port1_mwi_confirm_password.value, "Port 2 MWI confirm password mismatches.")
			) {
				return false;
		}
			
		if (f.sip_port1_asserted_enable.checked){
			if (!valid(f.sip_port1_asserted_identity_uri.value, is_string, "Port 2 Asserted Identity URI should not have space.") ||
				!valid(f.sip_port1_asserted_identity_displayname.value, is_string, "Port 2 Asserted Identity Display Name should not have space.") ){
					return false;
				}
		}
	}
	return true;
}

