﻿function xchangeImagesArray(array) {
	var d = document; var img;
	for (var i=0; i<array.length; i+=2) {
		img = null; var n = array[i];
		if (d.images) {img = d.images[n];}
		if (!img && d.getElementById) {img = d.getElementById(n);}
		if (img) {img.src = array[i+1];}
	}
}

function xchangeImages() {
	xchangeImagesArray(xchangeImages.arguments);
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable=no,toolbar=no,location=no,scroll=yes,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable=no,toolbar=no,location=no,directories=no,status=no,scroll=no,scrollbars=no,menubar=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}


function LettersToNumbers(name)
{
	var PhoneNumber = name.value.toUpperCase();
	var alphalist = new Array ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
	var numlist = new Array (2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9);

	var startpos = 0;
	for (i=0; i < alphalist.length; i++);
	{
		while ( PhoneNumber.indexOf(alphalist[i], startpos) != -1 )
		{
			startpos = PhoneNumber.indexOf(alphalist[i], startpos);
			PhoneNumber = PhoneNumber.substring(0,startpos) + numlist[i] + PhoneNumber.substring(startpos+1, PhoneNumber.length);
		}
		startpos = 0;
	}
	return PhoneNumber;
}

function sanitizeAndCheckApp()
{
	document.LogIn.app.value = document.LogIn.app.value.replace(/-|\(|\)|\s/gi, "");
	if(document.LogIn.app.value.match(/^\d{10}$|^\d{7}$/))
	{
		if(document.LogIn.app.value.match(/^8005458308$|^5458308$/) || document.LogIn.app.value.match(/^8663553684$/))
		{
			document.LogIn.action = 'https://weblink.freedomvoice.com/login/loginSubmit&login=';
			document.LogIn.action += document.LogIn.login.value;
			document.LogIn.action += '&password=' + document.LogIn.password.value;
			window.location = document.LogIn.action;
		}
	}
}

function login()
{
	document.LogIn.app.value = document.LogIn.app.value.replace(/-|\(|\)|\s/gi, "");
	if(document.LogIn.app.value.match(/^\d{10}$|^\d{7}$/))
	{
		if(document.LogIn.app.value.match(/^8005458308$|^5458308$/) || document.LogIn.app.value.match(/^8663553684$/))
		{
			document.LogIn.action = 'https://weblink.freedomvoice.com/login/loginSubmit&login=';
			document.LogIn.action += document.LogIn.login.value;
			document.LogIn.action += '&password=' + document.LogIn.password.value;
			window.location = document.LogIn.action;
		}
	}
}


function loaded()
{
	var f = $$('input','a');
	f.each( function(node){
	   if(node.className != 'disregard' && node.id !== 'weblink')
	      node.onclick=this.handler.bind(node);
	});
}
function handler(e)
{
	if( !this.href )
		return;
	DoPopup = false;
	if( this.href.indexOf(document.domain) == -1 )
	{
		__utmLinker(this.href);
		return false;
	}
}
function checkTestdriveEmail() {
    var emailRegxp = new RegExp(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$/);
    var errors = false;

 		 if( (document.testdrive.email.value.length<2) || !emailRegxp.test(document.testdrive.email.value) )
		 {
						 alert("Please enter a valid 'email'");
						 document.testdrive.email.focus();
						 return false;
		 }		 
		
		document.testdrive.submit()
		return true;
}
/*
DoPopup = <?php echo $DoPopup[$theme] ?>;
function Leave()
{
	if( DoPopup )
		window.open('promo.html','','');
}
*/