<!--

if(document.images){ // preload whirl for currency change
var whirl = new Image();
whirl.src = "/images/whirl.gif";
var pole = new Image();
pole.src = "/images/pole.gif";
var arrow_up = new Image();
arrow_up.src = "/images/drop_arrow_up.png";
var arrow_down = new Image();
arrow_up.src = "/images/drop_arrow_down.png";
var arrow_up_win = new Image();
arrow_up_win.src = "/images/drop_arrow_up_w.png";
var arrow_down_win = new Image();
arrow_down_win.src = "/images/drop_arrow_down_w.png";
}


var ie = isIE();


function toggleBundle(bundle)
{
if(document.getElementById('bundle_'+bundle).style.display=='' || document.getElementById('bundle_'+bundle).style.display=='none') {
		document.getElementById('bundle_'+bundle).style.display='block';
		document.getElementById('arrow_'+bundle).innerHTML = "<img src='/images/drop_arrow_down.png'>";
	}
else { 
		document.getElementById('bundle_'+bundle).style.display='none';	
		document.getElementById('arrow_'+bundle).innerHTML = "<img src='/images/drop_arrow_up.png'>";
	}
	return false;
}


function isIE()
{
var detect = navigator.userAgent.toLowerCase();
if(!(navigator && navigator.userAgent && navigator.userAgent.toLowerCase)) {
  	        return false;
  	    } else {
  	        if(detect.indexOf('msie') + 1) { return true; }
  	        }
}


function toggle(obj) { // toggle bundles

// Moz. or IE
var sibling=(obj.nextSibling.nodeType==3)? obj.nextSibling.nextSibling : obj.nextSibling;
// hide or show
if(sibling.style.display=='' || sibling.style.display=='block') {
	sibling.style.display='none'; // hide if clicked and opened
    if(ie) obj.firstChild.firstChild.src='/images/drop_arrow_up_w.png'; //windows gets a different pic
    else obj.firstChild.firstChild.src='/images/drop_arrow_up.png';
    }
else {
	sibling.style.display='block'; // show if clicked and closed
    if(ie) obj.firstChild.firstChild.src='/images/drop_arrow_down_w.png'; //windows gets a different pic
    else obj.firstChild.firstChild.src='/images/drop_arrow_down.png';
    }
}


function initCollapse() {
// note: content is hidden first via div style
var oDT=document.getElementById('collapse_content').getElementsByTagName('dt');
for (var i=0; i < oDT.length; i++) {
	oDT[i].onclick=function() {toggle(this)};
    var oSpan=document.createElement('span');
    var plusminus = document.createElement('img'); // we're putting an arrow in front of each title here
    if(ie) plusminus.src='/images/drop_arrow_up_w.png'; //windows gets a different pic
    else plusminus.src='/images/drop_arrow_up_w.png';    
    oSpan.appendChild(plusminus);
    oDT[i].insertBefore(oSpan, oDT[i].firstChild);
    oDT[i].style.cursor='pointer';
    toggle(oDT[i]);
	}
oDT=null;
document.getElementById('collapse_content').style.display = 'block'; // show content
}



var post_type = '';

function changeCurrency(cur)
{
var currency = cur.options[cur.selectedIndex].value;
	//document.getElementById('whirl').innerHTML="<img src='/images/whirl.gif' hspace='3'>";
	document.getElementById('whirl_text').innerHTML="calculating live currency ... ";
	for (var i=0; i < prices.length; i++) {
	 if(document.getElementById('price'+i))
		  document.getElementById('price'+i).innerHTML = "<center><img src='/images/pole.gif' width='65' height='12'></center>";
		}
	var url = "/cgi-bin/money.pl";
	parameters = "amount=100&form=false&convert="+currency; //get exchange rate to selected currency
	post_type = 'currency';
	makePOSTRequest('GET', url, parameters,post_type);
}


function numberFormat(amount) {
    amount -= 0;
    amount = (Math.round(amount*100))/100;
    return (amount == Math.floor(amount)) ? amount + '.00' 
              : ( (amount*10 == Math.floor(amount*10)) ? 
                       amount + '0' : amount);
}



function doCurrency(result)
{
exchangeRate = result*0.01; // grab the live exchange rate
for (var i=0; i < prices.length; i++) {
	var price = prices[i]; // get the original price
	var total = price * exchangeRate;
	if(document.getElementById('price'+i))
	  document.getElementById('price'+i).innerHTML = "<nobr>"+getSymbol(document.forms['currencyForm'].currency.options[document.forms['currencyForm'].currency.selectedIndex].value)+numberFormat(total)+"</nobr>";
	}
//document.getElementById('whirl').innerHTML="<img src='/images/spacer.gif' width='38' height='32'>";
document.getElementById('whirl_text').innerHTML="<font color='#353535'>View prices in:</font> ";
}


function getSymbol(currency)
{
var symbols = new Array();
symbols['USD'] = '$'
symbols['EUR'] = '&euro;'
symbols['GBP'] = '&pound;'
symbols['CAD'] = '$'
symbols['AUD'] = '$'
symbols['BRL'] = '$'
symbols['NZD'] = '$'
symbols['JPY'] = '&yen;'
symbols['CNY'] = 'CNY'
symbols['RUB'] = 'r'
symbols['MXN'] = '$'
return symbols[currency];
}


function validateCode(){
var code = document.getElementById('product_code').value;
document.getElementById('product_error').innerHTML = '';
document.getElementById('product_buy').innerHTML = '';
document.getElementById('product_return').innerHTML = '';
if(!code) { document.getElementById('product_error').innerHTML = "Enter a valid code"; } //return false; 
else {
	document.getElementById('product_whirl').innerHTML = "<center><img src='/images/pole.gif' width='65' height='12'></center>";
	document.getElementById('product_return').innerHTML = "<span class='message'>Getting product code details ...</span>";
	document.getElementById('product_layer').style.display='block';
	var url = "/includes/purchase/promotionCode.php";
	parameters = "code="+code; //get the code
	post_type = 'validateCode';
	makePOSTRequest('GET', url, parameters,post_type);
  }
//return false;
}


function showCodeValidation(result)
{
var product_data = result.split('+');
document.getElementById('product_whirl').innerHTML = "";
if(product_data[1]) { // we got a price back, so the product is valid
	if(product_data[3] == '1') document.forms['purchaseForm'].action = '/purchase/continue.sc';
		else document.forms['purchaseForm'].action = '/purchase/billing.sc';
	document.getElementById('product_return').innerHTML = product_data[2];
	document.getElementById('product_price').innerHTML = "US$"+product_data[1];
	document.getElementById('product_buy').innerHTML = "<input type='image' src='/images/buttons/buy.png' value='Buy' onClick=\"startCodePurchase('"+product_data[0]+"');return false;\">";
	}
	else { // expired, invalid, or used
	document.getElementById('product_price').innerHTML = "";
	document.getElementById('product_buy').innerHTML = "";
	document.getElementById('product_return').innerHTML = "<span class='message'>"+product_data[0]+"</span>";
  }
}




// http_request functions
// var poststr = "foo1=bar&foo2=bar2";
// type: which function we are working with
// method: POST or GET
// usage: makePOSTRequest('url', poststr, type);

   var http_request = false;

   function makePOSTRequest(method, url, parameters, type) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = getContents;

	if(method=='GET'){
                 http_request.open('GET', url+"?"+parameters, true);
                 http_request.setRequestHeader("Content-type", "text/xml");
                 http_request.setRequestHeader("Content-length", parameters.length);
                 http_request.setRequestHeader("Connection", "close");
                 http_request.send(null);
         }
     if(method=='POST')  {
                 http_request.open('POST', url, true);
                 http_request.setRequestHeader("Content-type", "text/xml");
                 http_request.setRequestHeader("Content-length", parameters.length);
                 http_request.setRequestHeader("Connection", "close");
                 http_request.send(parameters);
         }
   }

   function getContents() {
   	result = 0;
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            var result = http_request.responseText;
         } else {
            alert('There was a problem with the request. Please contact support@source-mail.com');
            result = '100';
         }
      }
      if(post_type == 'currency' && result) doCurrency(result);
      else if(post_type == 'validateCode' && result) showCodeValidation(result);
      //return result;
   }
   


//-->

