function dontSubmit(){
	if( window.event ) //iexplorer
	{
		      event.returnValue=false;
	}
}
function dontRefresh(event) 
{
	var key;
	if (window.event)
	   key = window.event.keyCode;
	else if (event)
	   key = event.which;

	if (key==116) {
		if (window.event){
			window.event.keyCode=0; 
			window.event.returnValue=false;
		}	
		return false
	}	
	return true;
}

function cancel()
{
	//alert('CANCEL');
	//ev.stopPropagation();
  return false;
}
function goPage(obj)
{
	document.form1.operation.value=obj;
	document.form1.submit();
}

function goMobileSignup()
{
	document.form1.operation.value = "signupD";
	document.form1.selectedPlan.value = "107";
	document.form1.submit();
}

function Trim(STRING){
STRING = LTrim(STRING);
return RTrim(STRING);
}

function RTrim(STRING){
while(STRING.charAt((STRING.length -1))==" "){
STRING = STRING.substring(0,STRING.length-1);
}
return STRING;
}


function LTrim(STRING){
while(STRING.charAt(0)==" "){
STRING = STRING.replace(STRING.charAt(0),"");
}
return STRING;
}
function findCountryIndex(destinationArea){
		var countryIndex=1;
		
		for (i=0; i<document.form1.countryRates.options.length; i++) {
	      	if(document.form1.countryRates.options[i].text.toLowerCase() == destinationArea.toLowerCase()){
	     		countryIndex=i;
	     		break;
	     	}	      
     	}	
		
		document.form1.countryRates.selectedIndex =countryIndex;	
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}



function CommaFormatted(amount)
{
	amount = CurrencyFormatted(amount);
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}

function getPlanRatePerMin() {

    var xmlHttpReq = false;
    var self = this;
    var index = document.form1.countryRates.selectedIndex;
    var destinationArea = document.form1.countryRates.options[index].value;
   	qstr = 'ajaxoperation=getPlanRatePerMin&destinationArea='+destinationArea;  // NOTE: no '?' before querystring
   	
   	if(index > 0){
	    var strURL = "../service/AjaxServlet?"+qstr;
	    // Mozilla/Safari
	    if (window.XMLHttpRequest) {
	        self.xmlHttpReq = new XMLHttpRequest();
	    }
	    // IE
	    else if (window.ActiveXObject) {
	        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    self.xmlHttpReq.open('POST', strURL, true);
	    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    self.xmlHttpReq.onreadystatechange = function() {
	        if (self.xmlHttpReq.readyState == 4) {
	            updatePlanPerPinPage(self.xmlHttpReq.responseText);
	        }
	    }
	    self.xmlHttpReq.send(null);
    }
}
function getPlanRatePerMin4Country(destinationArea){
	
			qstr = 'ajaxoperation=getPlanRatePerMin&destinationArea='+destinationArea;  // NOTE: no '?' before querystring
	   		   		
		    var strURL = "../service/AjaxServlet?"+qstr;
		    // Mozilla/Safari
		    if (window.XMLHttpRequest) {
		        self.xmlHttpReq = new XMLHttpRequest();
		    }
		    // IE
		    else if (window.ActiveXObject) {
		        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		    }
		    self.xmlHttpReq.open('POST', strURL, true);
		    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		    self.xmlHttpReq.onreadystatechange = function() {
		        if (self.xmlHttpReq.readyState == 4) {
		            updatePlanPerPinPage(self.xmlHttpReq.responseText);
		        }
		    }
		    self.xmlHttpReq.send(null);
}

function getPlanRatePerMin() {

    var xmlHttpReq = false;
    var self = this;
    var index = document.form1.countryRates.selectedIndex;
    
   	
   	if(index > 0){
   		var destinationArea = document.form1.countryRates.options[index].value;
   		getPlanRatePerMin4Country(destinationArea);
   	}
}

function onefloatingdigit(rate){

	var  ret = (Math.floor(parseFloat(rate)*10))/10;
	if(parseFloat(ret) - Math.floor(parseFloat(ret)) == 0){
		ret = ret +'.0';
	} 
	
	return ret;
}

function updatePlanPerPinPage(str)
{
	var cinfo = str.split(';');
	var country = cinfo[0];
	var ratePerMinStandart = '' ;
	var ratePerMinDomestic  = '' ;
	var ratePerMinInternational = ''   ;
	var bef1 = '$'  ;
	var aft1 = '&cent;' ;
	var bef2 = '$'  ;
	var aft2 = '&cent;' ;
	var bef3 = '$'  ;
	var aft3 = '&cent;' ;
	
	add = 0;
	
	//alert(str);
	
	if(document.form1.radiobutton[1].checked){
		add = 1;
	}

	
	if(cinfo[1] != undefined){
		if(cinfo[2]>=1){
			ratePerMinDomestic =parseFloat(cinfo[1])+add/10;
			aft2 = '';
		}else{
			ratePerMinDomestic =parseFloat(cinfo[1])*100+add;
			bef2 = '';
		}
		ratePerMinDomestic = onefloatingdigit(ratePerMinDomestic);
	}else{
		aft2 = '';bef2 = '';ratePerMinDomestic='-';
	}
	

	if(document.form1.country != null)
		document.form1.country.value = cinfo[0];
		
	if(document.form1.ratePerMinStandart != null){
		document.form1.ratePerMinStandart.value      = ratePerMinStandart;
		document.form1.ratePerMinDomestic.value      = ratePerMinDomestic;
		document.form1.ratePerMinInternational.value = ratePerMinInternational;
	}

	if(ratePerMinDomestic >0){
		document.getElementById("ratePerMin1").innerHTML = "<span style=\"font-weight:bold;\"><span style=\"font-size:250%; color: #0059DF;font-weight:bold;\">"+bef2+ratePerMinDomestic+aft2+" </span>/min.</span>"
	}else{
		document.getElementById("ratePerMin1").innerHTML = "<span style=\"font-weight:bold;\"><span style=\"font-size:250%; color: #0059DF;font-weight:bold;\">N/A</span></span>"
	}

}

function updateCountryPriceLocal(){
	getPlanRatePerMin();
}

function updateCountryPriceTollFree(){
	getPlanRatePerMin();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function clearWarning(fieldname){
	if(document.getElementById(fieldname) != null)
		document.getElementById(fieldname).innerHTML = '';
}

function NavMouseOver1()
	{
		document.getElementById('imgAgentMain').src = '../images/agents/topnavigation_main_on.gif';
	}
	function NavMouseOut1()
	{
		document.getElementById('imgAgentMain').src = '../images/agents/topnavigation_main.gif';
	}
	function NavMouseOver2()
	{
		document.getElementById('imgAgentAccountInfo').src = '../images/agents/topnavigation_reviewyour_on.gif';
	}
	function NavMouseOut2()
	{
		document.getElementById('imgAgentAccountInfo').src = '../images/agents/topnavigation_reviewyouracc.gif';
	}
	function NavMouseOver3()
	{
		document.getElementById('imgAgentMarketing').src = '../images/agents/topnavigation_marketing_on.gif';
	}
	function NavMouseOut3()
	{
		document.getElementById('imgAgentMarketing').src = '../images/agents/topnavigation_marketingreso.gif';
	}
	function NavMouseOver4()
	{
		document.getElementById('imgAgentEmailBlast').src = '../images/agents/topnavigation_agentemail_on.gif';
	}
	function NavMouseOut4()
	{
		document.getElementById('imgAgentEmailBlast').src = '../images/agents/topnavigation_agentemailbla.gif';
	}
	function NavMouseOver5()
	{
		document.getElementById('imgTEL3AdvAgentReports').src = '../images/agents/topnavigation_tel3advrep_on.gif';
	}
	function NavMouseOut5()
	{
		document.getElementById('imgTEL3AdvAgentReports').src = '../images/agents/topnavigation_tel3advrep.gif';
	}
	function NavMouseOver6()
	{
	}
	function NavMouseOut6()
	{
	}
	function NavMouseOver7()
	{
		document.getElementById('imgVoIPAdvAgentReports').src = '../images/agents/topnavigation_voipadvrep_on.gif';
	}
	function NavMouseOut7()
	{
		document.getElementById('imgVoIPAdvAgentReports').src = '../images/agents/topnavigation_voipadvrep.gif';
	}
	
function showPopup(window){
    var childWindow=open('content/smartplugpopup.html','SmartPlug','status=yes,scrollbars=no,width=430,height=312,resizable=no');
    childWindow.opener = self;
	
}

function MM_openBrWindow(theURL,winName,features) { 

  window.open(theURL,winName,features);
}

function cokkieCheck(){
	if (navigator.cookieEnabled == 0) {
	  alert("You need to enable cookies for this site to load properly!");
	}
}

function toggle(obj) {
var status = document.getElementById(obj).style.display;

	if( status == 'block'){
		document.getElementById(obj).style.display = 'none';
		document.getElementById("showsnapshot").value = "1";

	}else{
		document.getElementById(obj).style.display = 'block';
		document.getElementById("showsnapshot").value = "0";
	}
}
