var discountMultiplier = 1.0; // Changed back from 0.5 to 0.8 by AM - Friday, 24 August 2007

var max=0;

function loadurl(myurl) {
var load = window.open(myurl,'','');
}

//function textlist() {
//max=textlist.arguments.length;
//for (i=0; i<max; i++)
//this[i]=textlist.arguments[i];
//}
//tl = new textlist(
//"Our Guarantee to you...",
//"No subscription to buy our games...",
//"No unsolicited sms messages...",
//"Replacement game guarantee...",
//"No hidden message charges...",
//"Fast and efficient service...",
//"24 hour customer helpline.",
//""
//);
//var x = 0; pos = 0;
//var l = tl[0].length;
//function textticker() {
// if(tl[x].substring(0, pos)=="") var end=""; else var end="_";
//document.getElementById('tickform').tickfield.value = tl[x].substring(0, pos) + end;
//if(pos++ == l) {
//pos = 0;
//setTimeout("textticker()", 2000);
//if(++x == max) x = 0;
//l = tl[x].length;
//} else
//setTimeout("textticker()", 75);
//}



function listShowHide(id, first, last)
{
  var i = 1; first = parseInt(first); last = parseInt(last);

  for(i=first; i<last; i++)
  {
    if('dt_'+i != id && document.getElementById('dt_'+i))
    document.getElementById('dt_'+i).style.display='none';
    if(document.getElementById('dt_'+i+'_img')) document.getElementById('dt_'+i+'_img').src = 'img/list_closed.gif';
  }

  oObj = document.getElementById(id);
  if(oObj.style.display=='none')
  {
    oObj.style.display='block';
    src = 'img/list_open.gif';
  }
  else
  {
    oObj.style.display='none';
    src = 'img/list_closed.gif';
  }


  if(document.getElementById(id+'_img')) document.getElementById(id+'_img').src = src;
}

function popup(mylink, windowname)
{
  if (! window.focus)return true;
  var href;
  if (typeof(mylink) == 'string') href=mylink;
  else href=mylink.href;
  window.open(href, windowname, 'width=480,height=450,scrollbars=yes');
  return false;
}

function addFav(pageTitle,pageURL)
{
  pageTitle = document.title;
  if (window.sidebar) window.sidebar.addPanel(pageTitle, pageURL, "");
  else if(window.opera && window.print)
  {
    var elem = document.createElement('a');
	elem.setAttribute('href',pageURL);
	elem.setAttribute('title',pageTitle);
	elem.setAttribute('rel','sidebar');
	elem.click();
  }
  else if(document.all) window.external.AddFavorite(pageURL, pageTitle);
}

function twodp(amount)
{
    amount -= 0;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function addzero(amount)
{
  amount = amount.toString();
  if(amount.substring(amount.length-1, 1) == '.') amount = amount + '0';
  return amount;
}

function validate_form()
{
    if(document.getElementById('order_form').os1.value != 'STORE')
    {
    
		
		    var country = document.getElementById('order_form').on0.value;
				var num     = document.getElementById('order_form').os0.value;
       	num = num.replace(/[^0-9]/g,""); //remove all non-numeric characters.

        if (num == '' || num<1) {alert("Enter your mobile phone number"); return false;}

        country = country.toLowerCase();

        switch(country)
        {
            case "at":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "43"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "6"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+43'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "au":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "1"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "1"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "61"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "1"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "1"){num = num.substr(1,(num.length-1));}
                num = "0"+num;
                //if(num.substr(1,1) != "4"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                document.getElementById('order_form').os0.value = num;

            break;

            case "be":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "32"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "4"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+32'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "br":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "55"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(2,1) != "7" && num.substr(2,1) != "8" && num.substr(2,1) != "9"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+55'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "cz":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,3) == "420"){num = num.substr(3,(num.length-3));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,2) != "60" && num.substr(0,2) != "72" && num.substr(0,2) != "72" && num.substr(0,2) != "77"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+420'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "dk":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "45"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

//                if(num.substr(0,2) != "60" && num.substr(0,2) != "72" && num.substr(0,2) != "72" && num.substr(0,2) != "77"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+45'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "ie":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,3) == "353"){num = num.substr(3,(num.length-3));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                num = "0"+num;
                //if(num.substr(0,3) !="083" && num.substr(0,3) !="085" && num.substr(0,3) !="086" && num.substr(0,3) !="087" && num.substr(0,3) !="088"){ alert(num + " is not a valid Irish mobile phone number");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                document.getElementById('order_form').os0.value = num;
            break;

            case "fi":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,3) == "358"){num = num.substr(3,(num.length-3));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "4" && num.substr(0,2) != "50"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+358'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "fr":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "33"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "6"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+33'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "de":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "49"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,2) != "15" && num.substr(0,2) != "16" && num.substr(0,2) != "17"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+49'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "gr":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "30"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,2) != "69"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+30'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "hk":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,3) == "852"){num = num.substr(3,(num.length-3));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "9" && num.substr(0,1) != "6") { alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+852'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "hu":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "36"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,2) != "15" && num.substr(0,2) != "16" && num.substr(0,2) != "17"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                num = '+36'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "it":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "39"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "3"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+39'+num;

                document.getElementById('order_form').os0.value = num;
            break;

            case "lu":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,3) == "352"){num = num.substr(3,(num.length-3));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "6" && num.substr(2,1) != "1"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+352'+num;

                document.getElementById('order_form').os0.value = num;
            break;

            case "nl":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "31"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                //if(num.substr(0,1) != "6"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = "+31"+num;

                document.getElementById('order_form').os0.value = num;
            break;

            case "nz":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "64"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
//                alert(num);
                //if(num.substr(0,1) != "2"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = "+64"+num;

                document.getElementById('order_form').os0.value = num;
            break;

            case "jp":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "81"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(1,1) != "0"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+81'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "no":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "47"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "9" && num.substr(0,1) != "4"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+47'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "pl":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "48"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "5" && num.substr(0,1) != "6" && num.substr(0,1) != "7" && num.substr(0,1) != "8"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+48'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "pt":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,3) == "351"){num = num.substr(3,(num.length-3));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,2) != "96" && num.substr(0,2) != "91"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+351'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "sa":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,3) == "966"){num = num.substr(3,(num.length-3));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "5"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+966'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "sg":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "65"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "8" && num.substr(0,1) != "9"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+65'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "si":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,3) == "386"){num = num.substr(3,(num.length-3));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "6"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+48'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "za":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "27"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "7" && num.substr(0,1) != "8"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+27'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "es":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "34"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "6"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+34'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "se":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "46"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "7"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+46'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "ch":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "41"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}

                //if(num.substr(0,1) != "7"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}

                num = '+41'+num;
                document.getElementById('order_form').os0.value = num;
            break;

            case "gb":
            case "uk":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,2) == "44"){num = num.substr(2,(num.length-2));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                num = "0"+num;
                if(payment_processor=='sms')if(num.substr(1,1) != "7"){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length != 11){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                document.getElementById('order_form').os0.value = num;
            break;

            case "us":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "1"){num = num.substr(1,(num.length-1));}
                //if(num.length != 10){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                document.getElementById('order_form').os0.value = num;
            break;

            case "ca":
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "0"){num = num.substr(1,(num.length-1));}
                if(num.substr(0,1) == "1"){num = num.substr(1,(num.length-1));}
                //if(num.length != 10){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                document.getElementById('order_form').os0.value = num;
            break;

            case "ot":
            case "ot2":
                //if(num.length != 10){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                if(num.length == 0){ alert("The number you have entered is not in the correct\nformat for the country you have selected");return false;}
                document.getElementById('order_form').os0.value = num;
            break;
            default:
                alert("We're sorry but the game you have chosen\nisn't available in your selected country.\n\nIf you haven't chosen a country,\nplease do so to complete your order.")
                return false;
            break;
        }
        if(payment_processor != 'sms') document.getElementById('return').value = "http://mobilegamesunlimited.com/return.php?msisdn="+num;
        //alert("OK: "+num);
    }
    return true;
}

function toggle_countrydropdown(element)
{
  var top, left;
  if(navigator.family =="nn4")
  {
    if (toggle[element] == 1)
    {
      top = 0;
      left = -400;
      toggle[element]= 0;
    }
    else
    {
      top = document.toggle_1.top;
      left = document.toggle_1.left;
      toggle[element] = 1
    }
    document.dd_0.top = top+20;
    document.dd_0.left = left;
  }
  else if(navigator.family =="ie4")
  {
    if (toggle[element] == 1)
    {
      top = 0;
      left = -400;
      toggle[element]= 0;
    }
    else
    {
      top = toggle_1.offsetTop;
      left = toggle_1.offsetLeft;
      toggle[element] = 1
    }
    dd_0.style.top = top+20;
    dd_0.style.left = left;
  }
  else if(navigator.family =="gecko")
  {
    var noPx = document.childNodes ? 'px' : 0;
    if (toggle[element] == 1)
    {
      top = 0;
      left = -400;
      toggle[element]= 0;
    }
    else
    {
      top = document.getElementById("toggle_1").offsetTop;
      left = document.getElementById("toggle_1").offsetLeft;
      toggle[element] = 1
    }
    document.getElementById("dd_0").style.top = top+20 + noPx;
    document.getElementById("dd_0").style.left = left + noPx;
  }
}




var payment_processor;
function order_game(payment_processor2, new_window)
{
	payment_processor=payment_processor2;
	if(payment_processor == 'sms')
	{
		if(validate_form())
		{
			if(document.getElementById('order_form').adcode.value   == '') document.getElementById('order_form').adcode.value   = 'MGU1000';
			document.getElementById('order_form').action = 'submit.php';
			if(new_window=='Y') document.getElementById('order_form').target = "_blank";
    	document.getElementById('order_form').submit();
  	}
  	else
		{
			return false;
		} 
 }
	else
    if(validate_form())
    {
        document.getElementById('order_form').method = 'post';
        if(payment_processor == 'pp') { document.getElementById('order_form').action = 'https://www.paypal.com/cgi-bin/webscr';    document.getElementById('order_form').amount.value = document.getElementById('order_form').amount1.value; }
        if(payment_processor == 'wp') { document.getElementById('order_form').action = 'https://select.worldpay.com/wcc/purchase'; document.getElementById('order_form').amount.value = document.getElementById('order_form').amount2.value; }
        

        if(document.getElementById('order_form').custom.value   == '') document.getElementById('order_form').custom.value   = 'MGU96';
        if(document.getElementById('order_form').M_custom.value == '') document.getElementById('order_form').M_custom.value = 'MGU99';

        document.getElementById('order_form').M_os1.value             = document.getElementById('order_form').os0.value;
        document.getElementById('order_form').M_on1.value             = document.getElementById('order_form').on0.value;
        document.getElementById('order_form').M_on2.value             = document.getElementById('order_form').on1.value;
        document.getElementById('order_form').currency.value          = document.getElementById('order_form').currency_code.value;

        //alert(document.getElementById('order_form').action);
        if(new_window=='Y') document.getElementById('order_form').target = "_blank";
        document.getElementById('order_form').submit();
    }

    //alert(document.getElementById('order_form').action);

    return false;
}

function teletype(id)
{
  messages = new Array();
  messages[1] = 'No subscription to buy our games';
  messages[2] = 'No unsolicited sms messages';
  messages[3] = 'Replacement game guarantee';
  messages[4] = 'No hidden message charges';
  messages[5] = 'Fast and effiecient service';
  messages[6] = '24 hour customer service helpline';


  this.timer     = 60;
  this.fadetimer = 40;

  this.message   = 1;
  this.messages  = messages;
  this.currmsg   = '';
  this.i         = 0;
  this.alpha     = 99;
  this.id        = id;

  this.start = function()
  {
    document.getElementById(this.id).innerHTML = '&nbsp;';
    this.alpha = 99;
    this.setAlpha(this.alpha);
    if(this.timeout) { clearTimeout(this.timeout); }
    this.timeout = setTimeout(this.id + ".typechar();", this.timer);
  }

  this.next = function()
  {
    document.getElementById(this.id).innerHTML = this.currmsg;
    this.i = 0;
    this.currmsg = '';
    this.message++;
    this.message = this.message>=this.messages.length ? 1 : this.message;

    this.fade();
  }

  this.fade = function()
  {
    this.setAlpha(this.alpha);
    this.alpha = this.alpha-5;
    if(this.timeout) { clearTimeout(this.timeout); }

    if(this.alpha>0) this.timeout = setTimeout(this.id + ".fade();", this.fadetimer);
    else this.start();
  }

  this.setAlpha = function(opacity)
  {
    oObj = document.getElementById(this.id).style;

    oObj.opacity      = (opacity / 100);                  // CSS3 Version
    oObj.MozOpacity   = (opacity / 100);                  // Mozilla Version
    oObj.KhtmlOpacity = (opacity / 100);                  // Konquerer (+variants) version
    oObj.filter       = "alpha(opacity=" + opacity + ")"; // Internet Explorer Version
  }

  this.typechar = function()
  {
    this.currmsg = this.currmsg + this.messages[this.message].substring(this.i++, this.i);
    document.getElementById(id).innerHTML = this.currmsg + '-';

    if(this.timeout) { clearTimeout(this.timeout); }
    if(this.currmsg != this.messages[this.message]) this.timeout = setTimeout(this.id + ".typechar();", this.timer);
    else this.next();
  }
}

function findPos(oObj) // Find absolute position of any DOM object.
{
	var curleft = curtop = 0;
	if (oObj.offsetParent)
    {
        do
        {
            curleft += oObj.offsetLeft;
            curtop += oObj.offsetTop;
        } while (oObj = oObj.offsetParent);

        return [curleft,curtop];
    }
    else return false;
}

function showReviewDropdown()
{
    var pos = findPos(document.getElementById('dropdownanchor'));
    var oDD = document.getElementById('orderbydropdown');

    if(oDD.style.display == 'block')
    {
        oDD.style.display='none';

        oDD.style.left = '-1000px';
        oDD.style.top  = '-1000px';
    }
    else
    {
        oDD.style.display='block';

        oDD.style.left = (pos[0]-165) + 'px';
        oDD.style.top  = (pos[1]+15 ) + 'px';
    }

    if(oDD.timeout) clearTimeout(oDD.timeout);
    oDD.timeout = setTimeout("document.getElementById('orderbydropdown').justOpened=false", 100);
    oDD.justOpened = true;
}

document.onclick = function() // Anonymous function to hide popup when clicking on screen
{
    var oDD = document.getElementById('orderbydropdown');

    if(oDD && !oDD.justOpened)
    {
        oDD.style.display='none';

        oDD.style.left = '-1000px';
        oDD.style.top  = '-1000px';
    }
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";


function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);

   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

