function appendText(node,txt)
{
	node.appendChild(document.createTextNode(txt));
}

function appendElement(node,tag,id,htm)
{
	var ne = document.createElement(tag);
	if(id) ne.id = id;
	if(htm) ne.innerHTML = htm;
	node.appendChild(ne);
}



function SrvType(username, session_id, in_stock)
{
	for (var i = 0; i < document.service_type.srvTypeSelection.length; i++)
	{
		if (document.service_type.srvTypeSelection[i].checked)
		{
			xajax_ajaxSrvType(document.service_type.srvTypeSelection[i].value, username, session_id, in_stock); 
		}
	}	
}



function show_ac()
{
        var f = document.forms['smsCapableForm'];
        if (f == null || f.elements['smsCapable'].checked == true)
	{
		document.getElementById('ac_div_yes_sms').style.visibility = "visible"; 
		document.getElementById('ac_div_no_sms').style.visibility = "hidden"; 
	}
	else
	{
		document.getElementById('ac_div_yes_sms').style.visibility = "hidden"; 
		document.getElementById('ac_div_no_sms').style.visibility = "visible"; 
	}
}


function changePricePulldown(selectedCountryCodeA2)
{
   var myRe= new RegExp ("countryCodeA2="+selectedCountryCodeA2, "g");
   for (var i=0; i<document.jumpy.pullDownPrice.options.length; i++) {
	var myArray = myRe.exec(document.jumpy.pullDownPrice.options[i].value);
	if (myArray)
	{
		document.jumpy.pullDownPrice.options[i].selected = true;
	}
   }
}


function initialPriceIFrame()
{
  var URL = document.jumpy.pullDownPrice.options[document.jumpy.pullDownPrice.selectedIndex].value;
  document.getElementById('pricePulldownDivID').innerHTML = '<iframe name="pricePulldownIFrameName" id="pricePulldownIFrameName" frameBorder=0 scroll="auto"; src="' + URL + '" style="width: 450px; height: 185px"></iframe>';
//document.write('<iframe name="pricePulldownIFrameName" id="pricePulldownIFrameID" frameBorder=0 scroll="auto"; src="' + URL + '" style="width: 450px; height: 185px"></iframe>');
}


function pullDownPrice__OnChangeCallback() 
{
	URL = document.jumpy.pullDownPrice.options[document.jumpy.pullDownPrice.selectedIndex].value;
	if (navigator.userAgent.indexOf('MSIE') > 0 || navigator.userAgent.indexOf('Opera') > 0)
	{
		document.getElementById('pricePulldownDivID').innerHTML = '<iframe name="pricePulldownIFrameName" id="pricePulldownIFrameID" frameBorder=0 scroll="auto"; src="' + URL + '" style="width: 450px; height: 185px"></iframe>';
	}
	else
	{
		var ifrm = document.getElementById('pricePulldownIFrameName');
		ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
	        ifrm.document.open();
		ifrm.document.location = URL;
		ifrm.document.close();
	}
	
//	ifrm.document.write('<iframe name="pricePulldownIFrameName" id="pricePulldownIFrameID" frameBorder=0 scroll="auto"; src="' + URL + '" style="width: 450px; height: 185px"></iframe>');
//  	document.jumpy.pullDownPrice.options[document.jumpy.pullDownPrice.selectedIndex].selected = true;
}


function cartToPaypal(cartCount, num_dids_owned, nextPage, isPPAccount, expiredPPAccount)
{
	if (expiredPPAccount)
	{
		alert("This VirtuFon website account is expired.  If you wish to purchase new service, please sign out and then purchase service using a different/new username.");
		reload();
		return;

	}

	if (!isPPAccount)
	{
		alert("This VirtuFon website account is configured for purchase via credit card.  It can't be used for Paypal purchases.  If you wish to buy service with Paypal, please sign out and place your order using a different/new username.");
		reload();
		return;

	}
	if (num_dids_owned >= 1)
	{
		alert("VirtuFon website accounts paid by Paypal can contain only a single virtual phone number.  (Accounts paid by credit card can contain more than one virtual phone number).  If you wish to possess multiple virtual phone numbers paid via PayPal, please create separate accounts on this website.");
		reload();
		return;
	}
	if (cartCount > 1)
	{
		alert("Virtual numbers purchased with PayPal can only be purchased one at a time.  Please delete some numbers from your cart.  If you need multiple virtual numbers, please place a separate order for each number or purchase with a credit card.");
	}
	else
	{
		parent.location=nextPage;
	}
}



function printURL()
{
        var f = document.forms['ac_select_form'];
	alert(f.elements['areaCode'].value);
}           


function submitPorting(failPage)
{
        var f = document.forms['porting_form'];
	if (f.elements['porting_country'].value == "0")
	{
		alert('Please select a country.');
		parent.location=failPage;
	}
	else
	{
		f.submit();
	}
}           


function ppBuyNow(failPage, auth)
{
	var f = document.forms['ppForm'];
	if (auth)
	{
		f.submit();
	}
	else
	{
		alert("Please complete step 1 first.");
		parent.location=failPage;
	}
}


 function toggleBilling(form)
 {
  var idx;
  var z = document.cust_info_form.ship_usebill;
  if (z.checked == true) {
                        form.BillToName_First.value = form.firstname.value;
                        form.BillToName_Last.value = form.lastname.value;
                        form.BillToAddress1.value = form.addr1.value;
                        form.BillToAddress2.value = form.addr2.value;
                        form.BillToCity.value = form.m_city.value;
                        form.BillToState.value = form.state.value;
         for (var i=0; i<document.cust_info_form.BillToCountry.options.length; i++) {
            if (document.cust_info_form.BillToCountry.options[i].value == document.cust_info_form.country.options[document.cust_info_form.country.options.selectedIndex].value)
            {
                document.cust_info_form.BillToCountry.options[i].selected = true;
            }
         }
                        form.BillToZip.value = form.zip.value;
      } else {
                        form.BillToName_First.value = '';
                        form.BillToName_Last.value = '';
                        form.BillToAddress1.value = '';
                        form.BillToAddress2.value = '';
                        form.BillToCity.value = '';
                        form.BillToState.value = '';
                        form.BillToZip.value = '';
   document.cust_info_form.BillToCountry.selectedIndex = 0;

  }
     }



function checkForJava()
{
        if (!navigator.javaEnabled())
        {      
		parent.location='/cgi/java.required.html';

        }
}  


 function zerchiPopulate(form, tt)
 {
  var idx;
  var z = document.cust_info_form.zerchiPop;
  if (z.checked == true) {


   form.username.value = tt;
   form.pw1.value = "asdfasdf";
   form.pw2.value = "asdfasdf";
   form.email.value = "bob@jones.com";


   form.phone.value = "512-555-1212";

                        form.BillToName_First.value = "Bob";
                        form.BillToName_Last.value = "Jones";
                        form.BillToAddress1.value = "106 Main St.";
                        form.BillToAddress2.value = "";
                        form.BillToCity.value = "Austin";
                        form.BillToState.value = "TX";
   form.BillToZip.value = "78734";
         form.BillToCountry.selectedIndex = 0;

   form.ccnum.value = "4111111111111111";
   form.ccyear.value = "2012";
   form.ccmonth.value = "06";
   form.ccname.value = "Bob Jones";
   form.yes_to_terms.checked = true;
   form.ccscode.value = "1234";
  }
     }


        function cartSubmit() {
          document.cart_form.submit();
        }


 function demo_no_delete() {
   alert("Sorry, demo accounts cannot delete services.");
 } 

        function submitRingto(form) {
          var f = document.forms['validate_ringto_form'];
          f.elements['action'].value = "validate_ringto";
          f.submit();
        }
        
        function submitSkypeUsername(form) {
          var f = document.forms['validate_skype_username_form'];
          f.elements['action'].value = "validate_skype_username";
          f.submit();
        }

        function submitFaxEmail(form) {
          var f = document.forms['validate_fax_email_form'];
          f.elements['action'].value = "validate_fax_email";
          f.submit();
        }
        

        function ringtoBackup(form) {
          var f = document.forms['validate_ringto_form'];
          f.elements['action'].value = "select_areacode";
          f.submit();
        }


        function ringtoBackup_2(form) {
          var f = document.forms['validate_skype_username_form'];
          f.elements['action'].value = "select_areacode";
          f.submit();
        }


        function ringtoBackup_3(form) {
          var f = document.forms['validate_fax_email_form'];
          f.elements['action'].value = "select_areacode";
          f.submit();
        }


        function acselectBackup(vfscript, sid,u) 
	{
	  window.location=vfscript+'?action=signup&session_id='+sid+'&username='+u;
        }

	function checkACPageLoad()
	{
		var avp = GetCgiAVPs();
		var sms = GetCgiValue(avp, "sms");
		if (sms == '1')
		{
			var f = document.getElementById('srvTypeSelection');
			f.style.display = 'none';
		}
	}



	function acPageLoad()
	{
	        var f = document.forms['smsCapableForm'];
		if (f == null)
		{
			return;
		}
	        f.elements['smsCapable'].checked = false;
		var f2 = document.forms['ac_select_form1'];
		f2.areaCodeURL.options[0].selected = true;
		var f3 = document.forms['ac_select_form2'];
		f3.areaCodeURL.options[0].selected = true;
	}


        function ac_proceed() 
	{
		var URL = "";
		URL = document.ac_select_form1.areaCodeURL.options[document.ac_select_form1.areaCodeURL.selectedIndex].value;
		window.location.href = URL;
        }


        function submitGetOrderPurchaseInfo(form, formname) {
          var f = document.forms[formname];
          f.elements['action'].value = "getOrderPurchaseInfo";
          f.submit();
        }


        function submitAddSvcToCart(form) {
          var f = document.forms['add_svc_to_cart_form'];
          f.elements['action'].value = "add_service_to_cart";
          f.submit();
        }

        function submitAddSvcToCart_2(form) {
          var f = document.forms['add_svc_to_cart_form_2'];
          f.elements['action'].value = "add_service_to_cart";
          f.submit();
// code below not safari compatible
//        form.action.value = "add_service_to_cart";
//        form.submit();
        }


        function addSvcBackup(form) {
          var f = document.forms['add_svc_to_cart_form'];
          f.elements['action'].value = "check_areacode";
          f.submit();
        }

        function addSvcBackup_2(form) {
          var f = document.forms['add_svc_to_cart_form_2'];
          f.elements['action'].value = "check_areacode";
          f.submit();
        }



	function OpenCIDAnnounceHelp()
	{
		window.open('/cgi/cid.announce.help.html','privWin','width=550,height=700,left=100,top=100,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No'); 
	 	NewWindow.focus();
	}


	function OpenJavaInstructions()
	{
		window.open('/cgi/java.setup/java.setup.html','privWin','width=1000,height=700,left=0,top=0, toolbar=Yes,location=No,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No'); 
		NewWindow.focus();
	}


