<!-- Begin
var submitCount=0;
var lastState=0;
var intl_phone_regex = /^\+(\d{1,3})\.(\d{1,12}(?: *x(?:\d{1,4}))?)$/;


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");

    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(intl_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];
				}

            }
        }
    }
}

function split_phone(phone_num)
{
    var phone_regex = /^(\d{4,12})(?: *(?:ext|x)(\d{1,4}))?$/;
    var phone = new Object();

    phone.num = "";
    phone.ext = "";
    match = phone_num.match(phone_regex);
    if (match) {
        if (match[1]) 
            phone.num = match[1];
        if (match[2]) 
            phone.ext = match[2];
    }
    return phone;
}

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 toggleByClass(cname) {
    var state = $('.'+cname+':[checked=true]').length > $('.'+cname+':[checked=false]').length ? true : false;
    $('.'+cname).attr('checked', !state);
    return false;
}

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 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 set_class(id, newClass)
{
	var element;

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

	element.className = newClass;
}

function validateAuthcode(code, cira)
{
    var sChars = '!@#$%^&*()_';
    var nums = '0123456789';
    var letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var sCharfound = false;
    var nFound = false;

    if (code.length < 6) {
        alert("The auth code must be between 6 and 16 characters in length.");
        return false;
    }
    if (cira) {
        sCharfound = true;
    } else {
        for (var i = 0; i < code.length; i++) {
            if (sChars.indexOf(code.charAt(i)) != -1) {
                sCharfound = true;
                break;
            }
        }
    }
    for (var i = 0; i < code.length; i++) {
        if (nums.indexOf(code.charAt(i)) != -1) {
            nFound = true;
            break;
        }
    }
    for (var i = 0; i < code.length; i++) {
        if (letters.indexOf(code.charAt(i)) != -1) {
            if (nFound && sCharfound) {
                return true;
            }
        }
    }
    alert("The auth code must contain at least one number, one letter, and one of the special characters ! @ # $ % ^ & ( ) _");
    return false;
}

