<!-- Begin
var submitCount=0;
var lastState=0;

function setup()
{
    text_focus();
    if (document.contact) {
        expand_phone();
    };

}

function expand_phone()
{
    var form = document.contact;

    var contact_type = new Array("", "owner_", "billing_");
    var phone_type = new Array("fax", "phone");

    var phone_regex = /^\+(\d{0,3})\.(\d{1,12})(?: *x(\d{1,4}))?$/;

    for (i=0; i<contact_type.length; i++) {
        for (j=0; j<phone_type.length; j++) {
            field = contact_type[i] + phone_type[j];
            if (form[field]) {
                match = form[field].value.match(phone_regex);
                if (match) {
                    //alert("Does match the phone regexp.: " + form[field].value + " for field: " + field);
                    form[field+"_cc"].value = match[1];
                    form[field+"_num"].value = match[2];
                    if (match[3]) {
                        form[field+"_ext"].value = match[3];
                    }
				}

            }
        }
    }
}

function selectByValue(el, val)
{
    for (i=0; i<el.options.length; i++) {
        if (el.options[i].value == val) {
            el.selectedIndex = i;
            break;
        }
    }
}

function selectAll()
{
    var nCol=0, nSel=0, state, item;

    for (i=0, x=1; i < document.fdomain_lookup.elements.length; i++) {
        item = document.fdomain_lookup.elements[i];
        if (item.name.indexOf('domain') != 0) {
            continue;
        }

        if (item.type == 'checkbox') {
            item.checked = ! lastState;
        }
    }

    lastState = ! lastState;
}


function restoreImage(obj) {
	if (obj && obj.src) {
		obj.src = obj.orig_src;
	}
	window.status = '';

    return true;
}

function swapImage(obj, new_img, alt_text) {
    if (!obj.orig_src) {
        obj.orig_src = obj.src;
    }
    obj.src = new_img;
    window.status = alt_text;

    return true;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
      var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
          if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
          d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
            if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
              for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
                if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
     if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function selectRenewalCol(val)
{
    var myform = document.renewal;
    var nRow=0, nSel=0, state, item;

    for (i=0, x=1; i < myform.elements.length; i++) {
        item = myform.elements[i];

        if (item.type != 'radio') {
            continue;
        }
        if (item.type == 'radio' && (x % 3) == val) {
            if (item.checked) {
                nSel+=1;
            }
            nRow+=1;
        }
        x+=1;
    }

    state = (nSel > nRow/2) ? false : true;

    for (i=0, x=1; i < myform.elements.length; i++) {
        item = myform.elements[i];

        if (item.type != 'radio') {
            continue;
        }
        if (item.type == 'radio' && (x % 3) == val) {
            item.checked = state;
        }
        x+=1;
    }
}

function toggleCol(val,rowsize)
{
    var nRow=0, nSel=0, state, item;

	if (val == rowsize) {
		val = 0;
	}
    for (i=0, x=1; i < document.fdomain_lookup.elements.length; i++) {
        item = document.fdomain_lookup.elements[i];
        if (item.name.indexOf('domain') != 0) {
            continue;
        }
        if (item.type == 'checkbox' && (x % rowsize) == val) {
            if (item.checked) {
                nSel+=1;
            }
            nRow+=1;
        }
        x+=1;
    }

    state = (nSel > nRow/2) ? false : true;

    for (i=0, x=1; i < document.fdomain_lookup.elements.length; i++) {
        item = document.fdomain_lookup.elements[i];

        if (item.name.indexOf('domain') != 0) {
            continue;
        }

        if (item.type == 'checkbox' && (x % rowsize) == val) {
            item.checked = state;
        }
        x+=1;
    }
}

function toggleRow(val,rowsize)
{
    var nCol=0, nSel=0, state, item;

    for (i=0, x=1; i < document.fdomain_lookup.elements.length; i++) {
        item = document.fdomain_lookup.elements[i];
        if (item.name.indexOf('domain') != 0) {
            continue;
        }

        if (item.type == 'checkbox' && (x < val) && (x >= val-rowsize)) {
            if (item.checked) {
                nSel+=1;
            }
            nCol+=1;
        }
        x+=1;
    }

    state = (nSel > nCol/2) ? false : true;

    for (i=0, x=1; i < document.fdomain_lookup.elements.length; i++) {
        item = document.fdomain_lookup.elements[i];

        if (item.name.indexOf('domain') != 0) {
            continue;
        }

        if (item.type == 'checkbox' && (x < val) && (x >= val-rowsize)) {
            item.checked = state;
        }
        x+=1;
    }
}

function text_focus()
{
    if (document.flogin && document.location.href.match(/\?reg_domain=/i)) {
        if(document.flogin.reg_domain.value != "") {
            document.flogin.reg_username.focus();
        } else if (document.fdomain_lookup && document.fdomain_lookup.new_domains) {
            document.fdomain_lookup.new_domains.focus();
        }
    } else if(document.fdomain_lookup) {
        if(document.fdomain_lookup.new_domains) {
            document.fdomain_lookup.new_domains.focus();
        }
    } else if(document.flogin_affiliate) {
        document.flogin_affiliate.affiliate_username.focus();
    } else if(document.ccard) {
        document.ccard.p_cc_num.focus();
    } else if(document.contact) {
        if (document.contact.first_name) {
            document.contact.first_name.focus();
        } else {
            document.contact.owner_first_name.focus();
        }
    } else if(document.dns) {
        document.dns.fqdn1.focus();
    } else if(document.reset_password) {
        document.reset_password.password.focus();
    } else if(document.main_pass) {
        document.main_pass.password.focus();
    } else if(document.subuser) {
        document.subuser.sub_username.focus();
    } else if(document.ownership) {
        document.ownership.domain.focus();
    } else if(document.testimonial) {
        document.testimonial.first_name.focus();
    } else if(document.lost_password) {
        document.lost_password.reg_domain.focus();
    } else if(document.manage) { // must be the last one
        document.manage.domain.focus();
    }
	return true;
}


function Rcertify() 
{
    var popupWin = window.open('http://www.bbbonline.org/cks.asp?id=10308127445432206', 'Participant','location=yes,scrollbars=yes,width=450,height=300'); 
        window.name = 'opener';
} 

function help_window(url)

{
    var helpWindow = window.open(url,"helpWindow","alwaysLowered=0,alwaysRaised=1,channelmode=0,width=500,height=500,dependent=0,directories=0,fullscreen=0,hotkeys=0,location=0,menubar=0,resizable=1,addresbar=0,scrollbars=1,status=0,titlebar=0,toolbar=0,z-lock=0");

    helpWindow.select;

    helpWindow.focus();
}


function click_feedback() 
{
    if (submitCount == 0) {
        // accept the form submission
        //    alert("First Click");
        submitCount++;
        return true;
    } else {
        // deny the form submission
        alert("Double clicking is not allowed in browsers; it submits information twice, causing duplicate transactions!");
        return false;
    }
}

function verify_cb(form,service_id)
{
    var count_key = "cb_count:" + service_id;
    var count = form.elements[count_key].value;

    if (count > 0) {
        return true;
    } else {
        return false;
    }
}

function verify_selection(form,service_id)
{
    var action_key = "action:" + service_id;
    var val = form.elements[action_key].value;
    if (val == "none") {
        alert("Please, select a valid action from the pull-down menu.");
        return false;
    } else {
        if (val == "apply" || val == "delete") {
            if (! verify_cb(form,service_id)) {
                alert("You must select at least one mailbox for this action.");
                return false;
            }
        }
        if (val == "delete") {
            var prompt = "You are about to delete the selected email account(s).\nThis will delete the mailboxes and their content.  THERE IS NO UNDO ONCE THE MAILBOXES ARE DELETED.\n\nAre you sure you want to do this?";
            return confirm(prompt);
        }
    }
}

function select_product() {
    if (document.products) {
        var idx = document.products['selected_product'].selectedIndex;

        // These are set in the data/buy_services.tt.html template
        var product_info       = String(document.products['selected_product'].options[idx].value).split(':');
        var name               = product_info[0];
        var unit_price         = product_info[2];
        var unit_monthly_price = product_info[3];

        if (name == "none") {
            document.products['unit_price'].value = "";
            document.products['unit_monthly_price'].value = "";
            document.products['total_price'].value = "";
            return true;
        }

        var qty = Math.floor(document.products['qty'].value);
        var total_price = qty * unit_price;

        document.products['qty'].value = qty;
        document.products['unit_price'].value = "$" + (unit_monthly_price * 12).toFixed(2);
        document.products['unit_monthly_price'].value = "$" + (unit_monthly_price * 1).toFixed(2);
        document.products['total_price'].value = "$" +total_price.toFixed(2);
    }

    return true;
}

function forceSelection(form, prefix, name)
{
    var status = true;
    var state = prefix + 'state';
    var province = prefix + 'province';
    var country = prefix + 'country';

    if (name == 'country') {
        form[state].selectedIndex = 0;
        form[province].selectedIndex = 0;
    } else if (name == 'province') {
        form[country].selectedIndex = 0;
        form[state].selectedIndex = 0;
    } else if (name == 'state') {
        form[country].selectedIndex = 0;
        form[province].selectedIndex = 0;
    } else {
        status = false;
    }

    return status;
}

function submit_form(form)
{
    if (form.onsubmit) {
        return form.onsubmit();
    } else {
        return form.submit();
    }
}

function set_class(id, newClass)
{
	var element;

	if (document.getElementById(id)) {
		element = document.getElementById(id);
	} else {
		element = document.getElementById(id);
	}

	element.className = newClass;
}

