// SignUp Selector

function ccnconf(countryId) {
  
	var vfull = document.getElementById(countryId).value;
	var vCountryCodeUS = document.getElementById('countryCodeUS').value;
	if (vfull == vCountryCodeUS)
		{
			document.getElementById('state').style.display='block';
			document.getElementById('province').style.display='none';
		}  
		else
		{
			document.getElementById('state').style.display='none';
			document.getElementById('province').style.display='block';
		}  
}

function selectPaymentMethod(radioButton) {
	
	var pamentMethod = radioButton.value;

    if (pamentMethod == '1') {
        document.getElementById('payment_method_cc').style.display = 'block';
        document.getElementById('payment_method_paypal').style.display = 'none';

	}
	if (pamentMethod == '2') {
        document.getElementById('payment_method_cc').style.display = 'none';
        document.getElementById('payment_method_paypal').style.display = 'block';

	}  
}

function recharge() {
  
	var fill = document.getElementById('automatic-recharge').checked;
	if (fill)
		{
			document.getElementById('Recharge-level').style.display='block';
		}
	else
		{
			document.getElementById('Recharge-level').style.display='none';
		}  
	
}

function promo() {
  
	var fills = document.getElementById('promotion-code').checked;
	if (fills)
		{
			document.getElementById('promo-code').style.display='block';
			document.getElementById('promo-code-popup').style.display='none';
		}
	else
		{
			document.getElementById('promo-code').style.display='none';
			document.getElementById('promo-code-popup').style.display='block';
		}  
	
}

function successArea(){
	setTimeout(function(){
		$("div.successArea").fadeOut("slow", function () {
		$("div.successArea").remove();
		});
	}, 5000);
}

/** 
 * Function called onload and onclick ( input viewDestinationMinutes class) 
 * that does the get request to our url and parses the result.
 * Receives the form as parameter.
 */
function displayProductMaxMinutes(form){//it uses a specific form because a field like sourceRegion.id could coexist with another one named the same attached to another form.
    var sourceRegionId = form.elements["sourceRegion.id"].value;
    var destinationRegionId = form.elements["destinationRegion.id"].value;
    var productId = form.elements["product.id"].value;
    var productAccessType = form.elements["productAccessType"].value;
    if (destinationRegionId > 0) {
    	$.ajax({
    		type: "GET",
    		url: "/eshop/productlist/viewProductMaxMinutesEmpty.htm",
    		data: ({ "sourceRegion.id": sourceRegionId, "destinationRegion.id": destinationRegionId, "product.id": productId,"productAccessType": productAccessType }),
    		success: function(data){
    			document.getElementById("productRateContainer").innerHTML=data;
    		},
    		error: function(data,options,error){
    			document.getElementById("productRateContainer").innerHTML='Error Code '+data.status;
    		}
    	});
    }
}

/** 
 * Function that generate the login/my account buttons from the top.
 *   
 */
function populateRightTopDinamicDiv(language){
	var urlTopRight = '';
	if (language == 'es') {
		urlTopRight ='/' + language;
	} 
	var randomKey = Math.floor(Math.random() * 1000000);
	urlTopRight = urlTopRight + "/eshop/top/getTopRightCornerEmpty.htm";
	$.ajax({
		type: "GET",
		url: urlTopRight,
		data:({ "key": randomKey}),
		success: function(data) {
			$('#rightTopDinamicDiv').html(data);
			$('#rightTopDinamicDiv').show();
		},
		error: function(data,options,error) {
			$('#rightTopDinamicDiv').show();
		}
	});
}

/** 
 * Function that generates the phone contact info.
 */
function populatePhoneContactInfo(language){
	var urlPhoneContactInfo = '';
	if (language == 'es'){
		urlPhoneContactInfo ='/' + language;
	}
	var urlPhoneContactInfo = urlPhoneContactInfo + "/eshop/misc/getPhoneContactInfoEmpty.htm";
	$.ajax({
		type: "GET",
		url: urlPhoneContactInfo,
		data:({}),
		success: function(data){
			$('#phoneContactInfoDivId').append(data);
		},
		error: function(data,options,error){
			$('#phoneContactInfoDivId').innerHTML='';
		}
	});
}

/** 
 * Function called to check the ie warning cookie. 
 */
function checkIEWarningCookie(){
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
    {
            x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
            y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
            x=x.replace(/^\s+|\s+$/g,"");
            if (x=="ieWarningCookie")
            {
            	return true;
            }
    }
    
    return false;
}

/** 
 * Function called to create cookie. 
 */
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/** 
 * Function that generate the ie older version warning div.
 * ---- need international message ...  
 */
function populateIeOlderVersionWarningDiv(language){
	if (($.browser.msie && $.browser.version.substr(0,1) < 8 ) && (checkIEWarningCookie() == false)) {
		if (language == "en") {
			document.getElementById("ieOlderVersionWarningDinamicDiv").innerHTML='<div id="warningIe" class="warningIe"><div><img src="/images/nobelcom/global/ie_warning.gif">You are using an old browser. To enjoy a safer and better browsing experience on our website, we recommend you to upgrade <a class="colorRed" target="_blank" href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home">to a newer version.</a></div><div id="clickme" class="closeWarning">Close <img src="/images/nobelcom/global/closeWarning.gif"></div></div>';
		} else if (language == "es") {
			document.getElementById("ieOlderVersionWarningDinamicDiv").innerHTML='<div id="warningIe" class="warningIe"><div><img src="/images/nobelcom/global/ie_warning.gif">Usted esta utilisando un navegador viejo. Para disfrutar de un mejor hojear m&aacute;s seguro y experiencia en nuestro sitio web, nosotros recomendamos que actualice <a class="colorRed" target="_blank" href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home">a una versi&oacute;n m&aacute;s nueva.</a></div><div id="clickme" class="closeWarning">Cedrar <img src="/images/nobelcom/global/closeWarning.gif"></div></div>';
		}
	} else {
		document.getElementById("ieOlderVersionWarningDinamicDiv").innerHTML='';
	}
}

