REGEX_EMAIL = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/;
REGEX_DOMAIN = /^(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/;
//REGEX_DOMAIN = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/

function changeCurrency(value) {	// Currency Converter
	currency = value;
	$('price_currency').update(value);
	showPrice();
}

function showCurrencyMenu() {
	clearTimeout(intHideCurrencyMenu);
	$('currency_menu').show();
}

var intHideCurrencyMenu;
function hideCurrencyMenu() {
	clearTimeout(intHideCurrencyMenu);
	intHideCurrencyMenu = setTimeout("$('currency_menu').hide()",500);	
}
	
function clearDiv(id) {
	$(id).update('');
}

function clearRadioChecked(id) {
	var i;
	var rgrp = document.getElementsByName(id);
	for (i=0; i<rgrp.length; i++) {
		rgrp[i].checked = false;
	}
}

function in_array(what, where) {	
	var a=false;
	for(var i=0;i<where.length;i++) {	 
		if(what == where[i]){	    
			a=true;        
			break;	  
		}	
	}	
	return a;
}

function DomainSpellCheck(e){
        var key;
        var keychar;

        if (window.event)
           key = window.event.keyCode;
        else if (e)
           key = e.which;
        else
           return true;
        keychar = String.fromCharCode(key);
        keychar = keychar.toLowerCase();

        // control keys
        if ((key==null) || (key==0) || (key==8) || 
            (key==9) || (key==13) || (key==27) )
           return true;

        // alphas and numbers and dash
        else if ((("abcdefghijklmnopqrstuvwxyz0123456789-_").indexOf(keychar) > -1))
           return true;
        else
           return false;
    }

function clearRadioChecked(ID) {
		var i;
		var rgrp = document.getElementsByName(ID);
		for (i=0; i<rgrp.length; i++) {
			rgrp[i].checked = false;
		}
	}

function fieldCheck(value) {
		if (!$F(value)) { 
			$(value+'_title').className = 'error'; 
			$(value).style.border = '1px solid red';
			$(value).focus() 
		} else {
			$(value+'_title').className = '';
			$(value).style.border = '';
		}
	}
	
function checkField(id) {	
	if ($(id).type == 'checkbox') {
		if ($(id).checked == false) { 
			$(id+'_title').update('<div class="error errormsg">You must check the box below to continue.</div>');
		}
		return false;
	}
	
	if (!$F(id)) { 
		$(id+'_title').className = 'error';
		new Insertion.After($(id+'_title'), '<div class="errormsg">required field</div>');
		$(id).style.border = '1px solid red';
		$(id).focus();
	} else {
		$(id+'_title').className = ''; 
		$(id).style.border = '1px solid #888';
	}
}

function checkEmail(id) {
	if (!$F(id).match(REGEX_EMAIL) && $F(id)) {
		$(id+'_title').className = 'error'; 
		new Insertion.After($(id+'_title'), '<div class="errormsg">invalid email address</div>');
		$(id).style.border = '1px solid red';
		$(id).focus();		
		return false;
	} else if ($F(id)) {
		$(id+'_title').className = ''; 
		$(id).style.border = '1px solid #888';
	}
}

function validateDomain(id) {
	if (!$F(id).match(REGEX_DOMAIN) && $F(id)) {
		return false;
	}
	return true;
}

function showErrorMsg(id, text) {
	$(id).update('<span class="errormsg">'+text+'</span>');
}

function clearErrorMsg(id) {
	$(id).update('');
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

/*
	function for amount field check
*/
function amountCheck(e){
        var key;
        var keychar;

        if (window.event)
           key = window.event.keyCode;
        else if (e)
           key = e.which;
        else
           return true;
        keychar = String.fromCharCode(key);
        keychar = keychar.toLowerCase();

        // control keys
        if ((key==null) || (key==0) || (key==8) || 
            (key==9) || (key==13) || (key==27) )
           return true;

        // alphas and numbers and dash
        else if ((("0123456789.").indexOf(keychar) > -1))
           return true;
        else
           return false;
}

/*
	function for number field check
*/
function integerCheck(e){
        var key;
        var keychar;

        if (window.event)
           key = window.event.keyCode;
        else if (e)
           key = e.which;
        else
           return true;
        keychar = String.fromCharCode(key);
        keychar = keychar.toLowerCase();

        // control keys
        if ((key==null) || (key==0) || (key==8) || 
            (key==9) || (key==13) || (key==27) )
           return true;

        // alphas and numbers and dash
        else if ((("0123456789").indexOf(keychar) > -1))
           return true;
        else
           return false;
}

/*
	function for use of service radio action
*/
var service_use = 'personal';
function setServiceUse(value) {
	service_use = value;
	if (value == 'personal') {
		$('ccompany_div', 'cphone_div').invoke('hide');
		$('ccompany', 'cphone').invoke('removeClassName', 'required');
	} else if (value == 'business') {
		$('ccompany_div', 'cphone_div').invoke('show');
		$('ccompany', 'cphone').invoke('addClassName', 'required');
	}	
	return false;
}

/*
	function for payment method select box action
*/
function showPaymentMethod(value) {
	payment_method = value;	
	if (value == 'credit card') {
		$$("#pay_cc").each(function(node){node.show()});
		$$("#pay_other").each(function(node){node.hide()});
	} else if (value == 'others') {
		$$("#pay_cc").each(function(node){node.hide()});
		$$("#pay_other").each(function(node){node.show()});
	} else {
		$$("#pay_cc").each(function(node){node.hide()});
		$$("#pay_other").each(function(node){node.hide()});
	}	
	return false;
}

/*
	function for disable blue box fields
*/
function disableBlueBox() {
		$$('.bluebox').each(function(node){ node.disabled = true; })
		$('register_available', 'manage_taken', 'relookup_action').invoke('hide');
		
		if (domain_action == 'register') {
			$('lookup_text').update('<font style="line-height:1.2em">You have confirmed to register new domain <b>'+prevCheckValue+'</b><br><a href="javascript:void(0)" onclick="$(\'coupon_div\').show()">Click here if you have coupon code to use</a>, else please proceed to the form below.</font>');
		} else if (domain_action == 'manage') {
			$('lookup_text').update('<font style="line-height:1.2em">You have confirmed to let us manage your domain <b>'+prevCheckValue+'</b><br><a href="javascript:void(0)" onclick="$(\'coupon_div\').show()">Click here if you have coupon code to use</a>, else please proceed to the form below.</font>');
		}
}