function showQuestion (num) { 
	//alert(document.getElementById(q).style.display);
	
	if ((document.getElementById("q"+num).style.display == "none") || (document.getElementById("q"+num).style.display == "")) {
		closeAll();
		document.getElementById("q"+num).style.display = "inline";		
		document.getElementById("pm"+num).src = "../../../images/lp/startsavingnow/minus.gif";		
	} else {
		document.getElementById("q"+num).style.display = "none";
		document.getElementById("pm"+num).src = "../../../images/lp/startsavingnow/plus.gif";
	}
	return false;
}

function closeAll () {
	//alert("closeAll");
	var x;
	var maxquestion = 13;
	for (x = 1; x <= maxquestion; x++) {		
		document.getElementById("q" + x).style.display = "none";
		document.getElementById("pm" + x).src = "../../../images/lp/startsavingnow/plus.gif";
	}
}

// Start validation on NPA box

	function validateLNP(val)
	{
	if (chkNumericLNP(val) == true)
      { 
	 clearDivs();
	  } else {
	  //showDivs();
      $('msgDiv').innerHTML ='Please check your entry';
	  return false;
      }
	}
	
   function chkNumericLNP(strString) //  check for valid numeric strings		
   {
   //alert(strString.length + ' test');
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.value.length == 0) return true;

   //  test if strString consists of valid characters listed above
   for (i = 0; i < strString.value.length && blnResult == true; i++)
      {
      strChar = strString.value.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
      
    //  if (strString.value.length == 3){
    //alert(strString.id);
    		//if (strString.id == 'tnf_1'){
    		// $('tnf_2').focus();
    		//} else {
    		// $('tnf_3').focus();
    		//}		
    //  }
      
   return blnResult;
	}  //END check for valid numeric strings
	
	
	  function chkNumericOnly(strString)   // START NUMERIC ONLY CHECK
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }  /// END NUMERIC ONLY CHECK
	
		
function sc_pagename (new_page_name) {
	s.pageName=new_page_name;
	void(s.t());
}

 function checkLNP(div2update)
	{ 
	
		if (typeof div2update == 'undefined') {	var div2update = "lnpToolDiv"; };
		
		num2Check = $('tnf_1').value + $('tnf_2').value + $('tnf_3').value;
		if(chkNumericOnly(num2Check) == true){
		
			var url = "/ajax/lnp_ajax.php";
			//if($('referrer_id').value){
			//	var url_string='&refer_id='+ $('referrer_id').value;
			//}else{
				var url_string='';
			//}
			url= url+ "?n1=" + $('tnf_1').value + '&n2=' + $('tnf_2').value + '&n3=' + $('tnf_3').value + '&referHP=' + $('HP').value + '&show_link=true'+url_string; 				

			new Ajax.Request( url, {
			method: 'get',			
			onSuccess: function( transport ) {
				response = eval(transport.responseText);
				sc_pagename(response[0]);
				$('ajax_response').innerHTML=response[1];
				$('ajax_response').style.display='block';
				$(div2update).style.display='none';
			}
			});				
		}
	}
	function show_lnp_form(field_prefix) {
		$(field_prefix).style.display='block';
		$('ajax_response').style.display='none';
	}

 function checkLNPbakeOff()
	{
		num2Check = $('tnf_1').value + $('tnf_2').value + $('tnf_3').value;
		if(chkNumericOnly(num2Check) == true){
		
			var url = "/ajax/lnp_ajax_bakeoff.php";
			var pars = "npa=" + $('tnf_1').value + '&nxx=' + $('tnf_2').value + '&theRest=' + $('tnf_3').value + '&referP=' + $('HP').value; 	
			
			var myAjax = new Ajax.Updater( 
							'lnpToolDiv', 
							url, 
								{
									 method: 'get', 
									 parameters: pars 
								});
		}
	}
	
function processRequest() 
	{ 
	if (myAjax.readyState == 4){ 
	var holdOn = '<img src="../images/phone_cord_anim.gif" alt="Checkgin" hspace="2">';
  		document.getElementById('lnpToolDiv').innerHTML = holdOn;
	}
	if (myAjax.status == 200) {
		}
	}
	
function startOver(HP,div2update)	{
	if (typeof div2update == 'undefined') {	
		var div2update = "lnpToolDiv";
	}
	var url = "/ajax/lnp_ajax.php";
	var pars = "startOver=y" + "&referHP=" + HP;	
	
	$(div2update).innerHTML = "<form action=\"\" method=\"post\" name=\"lnp\" onsubmit=\"return false;\" style=\"padding: 0; margin: 0;\"><input type=\"text\" id=\"tnf_1\" name=\"LNPareaCode\" maxlength=\"3\" size=\"3\" value=\"\" tabindex=\"1\"> - <input type=\"text\" id=\"tnf_2\" name=\"LNPexchange\"  maxlength=\"3\" size=\"3\" value=\"\" tabindex=\"2\"> - <input type=\"text\" id=\"tnf_3\" name=\"LNP_theRest\" maxlength=\"4\" size=\"4\" value=\"\" tabindex=\"3\"><input type=\"hidden\" id=\"HP\" name=\"referHP\" value=\"homepage\">&nbsp;&nbsp;<input type=\"submit\" value=\"submit\" id=\"submitBtn\" alt=\"submit\" title=\"submit\" name=\"LNP_submit_btn\" onClick=\"checkLNP('box');\"></form>";
			
	/* var myAjax = new Ajax.Updater( 
							div2update, 
							url, 
								{
									 method: 'get', 
									 parameters: pars 
								}); */
	}
	
function startOverbakeOff(HP)
	{
	var url = "/ajax/lnp_ajax_bakeoff.php";
			var pars = "startOver=y" + "&referHP=" + HP;	
			
			var myAjax = new Ajax.Updater( 
							'lnpToolDiv', 
							url, 
								{
									 method: 'get', 
									 parameters: pars 
								});
	}	

function clearDivs(val) 
	{
		  $('msgDiv').innerHTML ='&nbsp;';
		//var element = $('msgDiv');
		//Element.hide(element);
	}	
	
function showDivs(val)
	{
		//var element = $('msgDiv');
		//  Element.show(element);
	}

// end Validation on NPA box	

var ie45,ns6,ns4,dom = false;
if (navigator.appName == "Microsoft Internet Explorer") ie45 = parseInt(navigator.appVersion) >= 4;
else if (navigator.appName == "Netscape"){
	ns6 = parseInt(navigator.appVersion) >= 5;
	ns4 = parseInt(navigator.appVersion) < 5;}
dom = ie45 || ns6;

var switchHTML = new Array;
var openHTML = '';
var re = /<script>/i;

function saveHTML(id, _HTML) {
	if(ns4) return;
	
	switchHTML[id] = _HTML;
	
}

function showHideHTML(id) {
	if(ns4) return;
	
	el = document.all ? document.all[id] : dom ? document.getElementById(id) : document.layers[id];
	
	if(openHTML.id == el.id)	{ el.innerHTML = "";  openHTML = ""; return; }
	else						{ openHTML.innerHTML = ""; }
	
	if(el.innerHTML == "" || re.test(el.innerHTML)) {
		el.innerHTML = switchHTML[id];
	} else {
		el.innerHTML = "";
	}
	
	openHTML = el;
	
}
	function checkIt(string)
	{
		place = detect.indexOf(string) + 1;
		thestring = string;
		return place;
	}

	var detect = navigator.userAgent.toLowerCase();
	var OS,browser,version,total,thestring;
	
	if (checkIt('konqueror')) { 
		browser = "Konqueror";
		OS = "Linux";
	} else if (checkIt('safari')) browser = "Safari" 
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "Internet Explorer"
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";
	
	if (!version) version = detect.charAt(place + thestring.length);
	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}

	isMacIE5 = ("Internet Explorer" && OS == "Mac" && parseFloat(version) >= 5);
	
	
	//Start Motion Point script
	
	var MP = {
<!-- mp_trans_disable_start --> 
  Version: '1.0.19',
  Domains: {'es':'espanol.vonage.com'},		
  SrcLang: 'en',
<!-- mp_trans_disable_end -->
  UrlLang: 'mp_js_current_lang',
  SrcUrl: unescape('mp_js_orgin_url'),
<!-- mp_trans_disable_start --> 	
  init: function(){
    if (MP.UrlLang.indexOf('p_js_')==1) {
      MP.SrcUrl=location.href;
      MP.UrlLang=MP.SrcLang;
  }
},
getCookie: function(name){
  var start=document.cookie.indexOf(name+'=');
  if(start < 0) return null;
  start=start+name.length+1;
  var end=document.cookie.indexOf(';', start);
  if(end < 0) end=document.cookie.length;
  while (document.cookie.charAt(start)==' '){ start++; }
  return unescape(document.cookie.substring(start,end));
},
setCookie: function(name,value,path,domain){
  var cookie=name+'='+escape(value);
  if(path)cookie+='; path='+path;
  if(domain)cookie+='; domain='+domain;
  var now=new Date();
  now.setTime(now.getTime()+1000*60*60*24*365);
  cookie+='; expires='+now.toUTCString();
  document.cookie=cookie;
},
switchLanguage: function(lang){
  if(lang!=MP.SrcLang){
    var script=document.createElement('SCRIPT');
    script.src=location.protocol+'//'+MP.Domains[lang]+'/'+MP.SrcLang+lang+'/?1023749632;'+escape(MP.SrcUrl);
	document.body.appendChild(script);
  } else if(lang==MP.SrcLang && MP.UrlLang!=MP.SrcLang){
    var script=document.createElement('SCRIPT');
    script.src=location.protocol+'//'+MP.Domains[MP.UrlLang]+'/'+MP.SrcLang+MP.UrlLang+'/?1023749634;'+escape(location.href);
	document.body.appendChild(script);
  }
  return false;
},
switchToLang: function(url) {
    var mplink=document.createElement('A');
	if (mplink.click) { // using location.href will cause IE6 to not report referrer
		mplink.href=url;
        document.body.appendChild(mplink);
        mplink.click();
	} else {
	    location.href=url; 
	}
}
<!-- mp_trans_disable_end -->	
};


	function getQueryVar (variable) {
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				return pair[1];
			}
		}
		return false;
	} 
function link_tracking (description) {
	var s=s_gi(account);
	s.linkTrackVars='None';
	s.linkTrackEvents='None';
	s.tl(true,'o',description);
}

//Rates Popup functions
 function openRates (country,div,plan) {
        if ($(div + '_minus').style.display != 'none') {
            //if minus is visible then close the row
            $(div + '_plus').show();
            $(div + '_minus').hide();
            $$('.'+div+'Rates').each(function(x){x.remove();});
            return false;
        }
        $(div + '_plus').hide();
        $(div + '_minus').show();
        $(div).insert({after:'<tr id="'+ div +'Wait" class="rateTableRates"><td colspan="5"><img src="/images/common/ajax_loader_orange.gif" /></td></tr>'});
        new Ajax.Request('/includes/calling_plans/icr/icr.php',{
                        parameters: {country:country,plan:plan, div:div},
                        method: 'post',
                        onSuccess: function (transport) {
                            $(div + 'Wait').remove();
                            $(div).insert({after:transport.responseText});
                        },
                        onFailure: function () {
                            //throw unavailable alert
                            alert('Sorry, the service is unavailable at the moment.  Please try again later.')
                        }            
        });
        return false;
    }

function ratesLightboxJump (country) {
	var main_top = document.getElementById('rateTableDiv').offsetTop;
	var sub_top=document.getElementById(country).offsetTop;
	var offset=0;
	var return_value=false;
	var user_agent=navigator.userAgent.toLowerCase();
	if (navigator.appName=='Microsoft Internet Explorer') {
		if (ie_version()>=8) {
			offset=-10;
		} else {
			return_value=true;
		}
	} else if (user_agent.indexOf('webkit')>=0) {
		offset=0;
	} else if (user_agent.indexOf('firefox')>=0) {
		offset=-22;
	}

	if (return_value==false) {
		document.getElementById('rateTableDiv').scrollTop=sub_top-main_top+offset;
		return false;
	} else {
		return true;
	}
}

function ratesLightboxSearch1 (country) {    
    new Ajax.Request('/ajax/ipr_country_ajax.php', {
                    parameters: {country:country},
                    method:'get',
                    onSuccess: function (transport) {
                        var json = transport.responseText.evalJSON();
                        $('searchSuggestion').value = json[0];
                        trueRateLookup = json[1];
                    },
                    onFailure: function () {
                        $('searchSuggestion').value = '';
                        //do nothing at the moment
                    }
    });
    return false;
}

ratesDelay = 1;
currentRateLookup = '';
trueRateLookup = '';
function ratesLightboxSearch (e) {    
    $('searchSuggestion').clear();
    var keyCode = (window.event) ? window.event.keyCode : e.keyCode;
    var patt = /[^a-zA-Z]/g;
    $('searchCountries').value = $('searchCountries').value.replace(patt,'');
    if ((Event.KEY_RETURN == keyCode) || (e.name == 'icrRateForm')) {           
        $('searchCountries').value = trueRateLookup;                
        var div_name =  trueRateLookup.replace(patt,'');        
        ratesLightboxJump(div_name);
        $(div_name + 'Link').onclick();
        return false;
    } else if (Event.KEY_ESC == keyCode) {        
        return false;
    } 
    if ((currentRateLookup == $F('searchCountries')) && (keyCode)) {            
        return false;
    } else {
        currentRateLookup = $F('searchCountries');
    }
    
    //window.clearTimeout(ratesDelay);   
    //ratesDelay = window.setTimeout(ratesLightboxSearch1, 500, $F('searchCountries'));
    ratesLightboxSearch1($F('searchCountries'));    
    return false;
}

function ratesLightboxEvent () {
    Event.observe('searchCountries','keyup',ratesLightboxSearch);    
    //kill onfocus?
    $('searchCountries').attributes['onfocus'].value = "";
    return false;
}

function dynamic_tracking (tracking_array) {

        var keys=new Array();

        var values='';



        s=s_gi(account); //account is set in the s_code.js file



        for (var i in tracking_array) {

               if (i=='pageName') {

                       sc_pagename(tracking_array[i]); //There is a different function in omniture to change the pagename

               } else {

                       keys[keys.length]=i;

                       values+='s.'+i+'="'+tracking_array[i]+'";';

               }

        }



        variable_names=keys.join(',');



        s.linkTrackVars=variable_names; s.linkTrackEvents="event1";

        eval(values);

        s.tl(this,'o','My Link Name');

}

function more_features_toggle (element) {
	
	var more_div=document.getElementById(element+'_div');
	var more_plan=document.getElementById(element+'_plan');
	var more_img=document.getElementById(element+'_more_product_features_image');
	var more_link=document.getElementById(element+'_more_product_features_link');
	var other, other_plan
	
	if (element=='left') {
		other='right';
	} else {
		other='left';
	}
	
	other_plan=document.getElementById(other+'_plan');
	
	if (more_div.style.display=='none') {
		link_text='Less Details';
		expand_image='minus';
		state='';
		more_plan.style.height='615px';
		document.getElementById('content_index').style.height='650px';
		document.getElementById('looking_index').style.top='990px';
		document.getElementById('footer_index').style.top='1030px';
		document.getElementById('footer_nav_index').style.top='1075px';
		document.getElementById('legal_index').style.top='1095px';
	} else {
		link_text='More Details';
		expand_image='plus';
		state='none';
		more_plan.style.height='430px';
			if (other_plan.style.height!='615px') {
				document.getElementById('content_index').style.height='460px';
				document.getElementById('looking_index').style.top='803px';
				document.getElementById('footer_index').style.top='825px';
				document.getElementById('footer_nav_index').style.top='890px';
				document.getElementById('legal_index').style.top='910px';
			}
	}

	more_img.src='/images/common/vonage_'+expand_image+'.gif';
	more_link.innerHTML=link_text;
	more_div.style.display=state;
}

