// url_suffix[0] is reserved
var url_suffix = new Array(
		"", // empty
		"", // empty
		"", // empty
		".tzo.com",
		".dyn.dhs.org",
		".dyn-interfree.it",
		"", "", "", "", "",
		"", "", "", "", "",
		"", "", "", "", "",
		"", "", "", "", "",
		".dlinkddns.com",
		".dlinkddns.com.cn"
);

var ddnsSrvName = new Array(
		"", "", "",  // empty
		"", "", "",  // tzo, dhs, interfree
		"", "", "", "", "", // empty
	   	"", "", "", "", "", 
		"", "", "", "", "", 
		"", "", "", "", "",
		"members.dyndns.org", // D-Link
		"www.dlinkddns.com.cn" // D-Link China
);

function validRegisterForm()
{
    var sform = document.ddnsregister;
	
	//check pre-hostname
	if (sform.prehostname.value  == "")
	{
	    alert("Please enter hostname!");
		sform.prehostname.focus();
		sform.prehostname.select();
	    return false;
	}
	
	if (checkemail(sform.email) == false)
		return false;
		
	return true;
}

function ForgetKey()
{
	if (!validRegisterForm())	return 1;
	dr = document.getElementsByName("ddnsregister")[0];
	document.getElementsByName("method")[0].value = "forgetkey";
	document.getElementsByName("hostname")[0].value = 
	    document.getElementsByName("prehostname")[0].value + ".safe100.net";
	//email = document.getElementsByName("email")[0].value;
	dr.submit();
}

function RegisterHost()
{
	if (!validRegisterForm())	return 1;
	dr = document.getElementsByName("ddnsregister")[0];
	document.getElementsByName("method")[0].value = "register";
	document.getElementsByName("hostname")[0].value = 
	    document.getElementsByName("prehostname")[0].value + ".safe100.net";
	//hostname = document.getElementsByName("hostname")[0];
	//email = document.getElementsByName("email")[0];
	key = document.getElementsByName("key")[0];
	if (key.value  == "")
	{
	    alert("Please enter key!");
		key.focus();
		key.select();
	    return 1;
	}
	confirmkey = document.getElementsByName("confirmkey")[0];
	if (key.value != confirmkey.value)
	{
		alert("The confirm key differs from the key. \nPlease try again.");
        key.focus();
        key.select();
		return;
	}
	else
		dr.submit();
}

function copyRegister2DDNS()
{
	document.getElementsByName("hostname_ddns")[0].value = document.getElementsByName("prehostname")[0].value;
	document.getElementsByName("ddns_usernameemail")[0].value = document.getElementsByName("email")[0].value;
	document.getElementsByName("ddns_passwordkey")[0].value = document.getElementsByName("key")[0].value;
}

function submitDDNS()
{
    var sform = document.ddnsoption;
	var prvd = sform.ddns_provider;
	
	//set the enable value
	if (sform.enable_ddns.checked)	sform.ddns_enable.value = "1";
	else							sform.ddns_enable.value = "0";
	
	//check hostname
	if (sform.hostname_ddns.value == "")
	{
	    alert("Please enter hostname!");
		sform.hostname_ddns.focus();
		sform.hostname_ddns.select();
	    return false;
	}
	
	if (!checkInString(sform.hostname_ddns))
	    return false;
	
	sform.ddns_hostname.value = sform.hostname_ddns.value + url_suffix[prvd[prvd.selectedIndex].value];
	
	// check username or email
    if (prvd[prvd.selectedIndex].value == 3){
		if (checkemail(sform.ddns_usernameemail) == false)
		    return false;
	} else {
	    if (sform.ddns_usernameemail.value == "")
		{
		    alert("Please enter username!");
			sform.ddns_usernameemail.focus();
			sform.ddns_usernameemail.select();
		    return false;
		}
		
		if (!checkInString(sform.ddns_usernameemail))
			return false;
			
		if (!checkInString(sform.ddns_passwordkey))
			return false;
	}
}


