/*

	WDEx Generel order form based functions
	
*/




/*

	WDEx Whois Code
	
	wdexwhois() - Is trigging the whois
	wdexwhoisdisplay() - Prepare the output and fetch the results that are ready
	wdexwhoisdisplayslow() - Fetch the last results from the database

*/


// Function to send whois search to the server for the "first" time
function wdexwhois(GlobalLocationProfile, domain) {
	
	// Put up the proccessing message
	new Ajax('/action.php?action=whoisprocessing&lang=' + GlobalLocationProfile, { method: 'get', update: $('step1_result_holder')}).request();
	$("step1_options_holder").setStyle("display", "none");
	$("step1_options_submit_holder").setStyle("display", "none");	
	$("step1_result_holder").setStyle("display", "block");	
	
	// Load variable
	var d = $('whois');
	
	if(domain.length >= 2){
		d1 = domain;
	}
	else{
		d1 = d.value;
	}
	
	// Send the whois to server
	new Ajax('/action.php?action=whois&value=' + d1, { method: 'get'}).request();
	
	// Start polling for whois answers
	setTimeout("wdexwhoisdisplay('" + GlobalLocationProfile + "')", 4000);

}

function wdexwhoisdisplay(GlobalLocationProfile) {
	var d = $('whois');
	new Ajax('/action.php?action=wdexwhoisdisplay&value=' + d.value + '&lang=' + GlobalLocationProfile, { method: 'get', update: $('step1_result_inner')}).request();
	setTimeout("wdexwhoisdisplayslow('" + GlobalLocationProfile + "')", 5000);
}


function wdexwhoisdisplayslow(GlobalLocationProfile) {

	var tld = ['com','net','org','info','biz','no','co.uk'];

	for ( var i=0, len=tld.length; i<len; ++i ){
  
		if(!$('whois_result_radiobutton_' + tld[i])){
			var d = $('whois');
			$('whois_result_' + tld[i]).setStyle("display", "none");
			new Ajax('/action.php?action=whoisfetchone&value3=msg&value2=' + tld[i] + '&value=' + d.value + '&lang=' + GlobalLocationProfile, { method: 'get', update: $('whois_result_text_'+ tld[i])}).request();
			new Ajax('/action.php?action=whoisfetchone&value3=radiobutton&value2=' + tld[i] +'&value=' + d.value, { method: 'get', update: $('whois_result_' + tld[i])}).request();
			$('whois_result_' + tld[i]).setStyle("display", "block");
		}
	}
}





function wdexdomainsettings(status, domain, idna_domain, tld, webdealdomain, GlobalLocationProfile){

	new Ajax('/action.php?action=domainoptions&value1=' + status + '&value2=' + domain + '&value3=' + idna_domain + '&value4=' + tld + '&value5=' + webdealdomain + '&lang=' + GlobalLocationProfile, { method: 'get', update: $('step1_options_holder')}).request();
	$("step1_options_holder").setStyle("display", "block");
	$("step1_options_submit_holder").setStyle("display", "none");

}




/*

	WDEx Layout functions
	
	step1_showsubmitbutton(lang) - Show the next button on step1 according to the language

*/

function step1ShowSubmit(GlobalLocationProfile){

	if(GlobalLocationProfile == 'no'){
		$('step1_options_submit_holder').innerHTML = '<div id="step1_options_submit"><br /><center><a href="#" onclick="document.form3.submit();return false;"><img src="/img/next_no.gif" alt="" /></a></center></div>';	
	}
	else{
		$('step1_options_submit_holder').innerHTML = '<div id="step1_options_submit"><br /><center><a href="#" onclick="document.form3.submit();return false;"><img src="/img/next_en.gif" alt="" /></a></center></div>';		
	}

	$("step1_options_submit_holder").setStyle("display", "block");

}









// Validate Coupon Code
function wdexcoupon(v) {
	var d = $('coupon');
	new Ajax('/action.php?action=validatecoupon&value=' + d.value + '&key=' + v, { method: 'get', update: $('step2_coupon_result')}).request();
}


function updateAddressForm(GlobalLocationProfile){
	
	// Load variables
	var c = $('country_iso');
	var at = $('account_type');

	// Load form
	new Ajax('/action.php?action=loadaddressform&value=' + c.value + '&value2=' + at.value + '&lang=' + GlobalLocationProfile, { method: 'get', update: $('step3_address')}).request();
}

function checkPostcodeNO(){

	var p = $('postcode');
	var pl = p.value;
	
	var c = $('city');
	var s = $('state');

	if(pl.length == 4){
		
		new Ajax('/action.php?action=findcity&value=NO&value2=' + pl, { method: 'get', onComplete: setCity}).request();
		new Ajax('/action.php?action=findstate&value=NO&value2=' + pl, { method: 'get', onComplete: setState}).request();
		
	}

}

function setCity(r){
	var c = $('city');
	c.value = r;
}

function setState(r){
	var s = $('state');
	s.value = r;
}

// Validate Address form

function submitStep4(v){

	if ($('acceptagreement').checked == false) {
		alert ('Please accept the service agreement');
		return false;
	} 
	else {
		document.form8.submit();
		return false;
	}

}


