// Browser checks
var t = this, d = document, w = window, na = navigator, ua = na.userAgent;
var isOpera = w.opera && opera.buildNumber;
var isWebKit = /WebKit/.test(ua);
var isOldWebKit = t.isWebKit && !w.getSelection().getRangeAt;
var isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
var isIE6 = t.isIE && /MSIE [56]/.test(ua);
var isGecko = !t.isWebKit && /Gecko/.test(ua);
var isMac = ua.indexOf('Mac') != -1;

var IE = isIE;
if (!IE) document.captureEvents(Event.MOUSEMOVE);

document.onmousedown = click;
document.onmousemove = getMouseXY;
var flash_counter = 0;
var tempX = 0;
var tempY = 0;
var tc;
var move_arrow;
var flash_objects = new Array();

function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

function show_my_content(id) {
	
	/*var cover = $('cover');
	if (cover.className == 'body_trans') {
		cover.className = 'body_notrans';
	} else {
		cover.className = 'body_trans';
	}*/
	var elem = $(id);
	if (elem.style.display == '' || elem.style.display == 'block') {
		elem.style.display = 'none';
	} else {
		elem.style.display = 'block';
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "', 1)",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "', 0)",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id, way) {
    var object = $(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	object.display = opacity / 100 == 0 && way == 1 ? 'none' : 'block';
}

function change_tabs(current_tab, all_tabs) {
	current_tab++;
	if (current_tab > all_tabs ) {
		current_tab = 1;
	}
	if ($('is_paused').value == 0) {
		tc = setTimeout("change_tabs(" + current_tab + ", " + all_tabs + ")", 3000);
	}
	for (i = 1; i <= all_tabs; i++) {
		if (i != current_tab) {
			var other_tab = $('tab'+i);
			other_tab.className = 'fl spotlight_tab_top_border';
			var other_spot = $('spot'+i);
			other_spot.style.display = 'none';
		}
	}
	$('current_number').innerHTML = current_tab+'/'+all_tabs;
	$('selected_tab').value = current_tab-1;
	var tab = $('tab'+current_tab);
	tab.className = 'fl spotlight_tab';
	var spot = $('spot'+current_tab);
	spot.style.display = '';
    
}

function select_tab(current_tab, all_tabs) {
	for (i = 1; i <= all_tabs; i++) {
		if (i != current_tab) {
			var tab = $('tab'+i);
			tab.className = 'fl spotlight_tab_top_border';
			var spot = $('spot'+i);
			spot.style.display = 'none';
		} else {
			$('current_number').innerHTML = i+'/'+all_tabs;
			$('selected_tab').value = i;
			var tab = $('tab'+i);
			tab.className = 'fl spotlight_tab';
			var spot = $('spot'+i);
			spot.style.display = '';
		}
	}
}

function forward_tab(tab_num, way, all_tabs) {
	clearTimeout(tc);
	if (way == 'left') {
		if (tab_num == 0) tab_num = all_tabs;
		tab_num--;
	}
	if (way == 'right') {
		if (tab_num == (all_tabs - 1)) tab_num = -1;
		tab_num++;
	}
	
	$('selected_tab').value = tab_num;
	select_tab(tab_num, all_tabs);
	change_tabs(tab_num, all_tabs);
}

function check_pause(is_paused, all_tabs) {
	if (is_paused == 1) {
		tc = setTimeout("change_tabs(" + $('selected_tab').value + ", " + all_tabs + ")", 3000);
		$('is_paused').value = 0;
	} else {
		clearTimeout(tc);
		$('is_paused').value = 1;
	}
}

function makehompage() {
	var browserName=navigator.appName; 
	if (browserName=="Netscape") { 
		var makehome = $('makehome');
		if (makehome.style.display == 'none') {
			makehome.style.display = '';
		} else {
			makehome.style.display = 'none';
		}
	}
	if (browserName=="Microsoft Internet Explorer") {
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage('http://www.aol.com');
	}
}

function getMouseXY( e )
{
	e = e || window.event;
	
	if( isIE ) { // grab the x-y pos.s if browser is IE
		if( isIE6 )
		{
			tempX = 0;
			tempY = 0;
			// tempX = e.clientX + document.body.scrollLeft;
			// tempY = e.clientY + document.body.scrollTop;
		}
		else
		{
			tempX = 0;
			tempY = 0;
		}
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  
	// show the position values in the form named Show
	return tempX+'#'+tempY;
}

function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function getPosition(mousex, mousey, div) {
	var element = $(div);
	var divleft = findPosX(element);
	var divtop = findPosY(element);
	var divright = divleft+280;
	var divbottom = divtop+177;

	if ((mousex > divleft && mousex < divright) && (mousey > divtop && mousey < divbottom)) {
		return true;
	} else {
		return false;
	}
}

function click(e) {
  e = e || window.event;

  var mouseposition = getMouseXY(e).split('#');
  var mousex = mouseposition[0];
  var mousey = mouseposition[1];
  
  var divover = getPosition(mousex, mousey, 'makehome');
  
  if (navigator.appName == 'Netscape' && (e.which == 3 || divover === false)) {
      var makehome = $('makehome');
	  makehome.style.display = 'none';
  }
}

function show_divs(parentdiv, div, id) {
	var services = $('available_services');
	services.style.display = 'none';
	if (parentdiv == 'subcategs') {
		var divs = $('alertitems').getElementsByTagName('div');
		for (i = 0; i < divs.length; i++) {
			divs[i].style.display = 'none';
		}
	}
	
	var divs = $(parentdiv).getElementsByTagName('div');
	for (i = 0; i < divs.length; i++) {
		if (divs[i].getAttribute('id') == div+'_'+id) {
			divs[i].style.display = '';
		} else {
			divs[i].style.display = 'none';
		}
	}
}

function show_services() {
	var services = $('available_services');
	services.style.display = '';
}

function show_hide(id, otherdivs)
{
	// -- A list of the tabs we don't want, turned into an array
	var others = otherdivs.split('#');
	
	// -- Loop through the tabs we don't want, and invisiblise them
	for( i = 0; i < others.length; i++ )
	{
		var tab = $(others[i] + '_tab');
		var box = $(others[i]);
		tab.className = 'recommend_tab';
		box.className = "rec_invisible";
	}
	
	// -- Quick access to the controls
	var selectedTab = $(id + '_tab');
	var selectedBox = $(id);
	
	// -- Highlight the tab
	selectedTab.className = 'recommend_tab_over';
	
	// -- Make the box visible if it isn't already
	if( selectedBox.className == "rec_invisible" )
	{
		selectedBox.className = "rec_visible";
	}
}

function leave_tab(id, div) {
	if( $(id).className == 'rec_invisible' ) {
		div.className = 'recommend_tab';
	}
	else
	{
		div.className = 'recommend_tab_over';
	}
}

function ajaxFunction(target, attribs, loader_text) {
	var loader_text = (loader_text == null) ? "Please wait..." : loader_text;
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState == 1) {
			$(target).innerHTML = '<img src="themes/default/images/ajax-loader.gif" />&nbsp;'+loader_text;
		}
		if(xmlHttp.readyState == 4) {
			$(target).innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET","ajax.php?"+attribs,true);
	xmlHttp.send(null);
}

function ajaxFunctionJS(target, attribs, refresh) {
	var refresh = (refresh == null) ? 0 : refresh;
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState == 1) {
			$(target).innerHTML = 'Please wait...';
		}
		if(xmlHttp.readyState == 4) {
			$(target).innerHTML = '<span style="font-weight: bold; color: #ff0000;">Settings saved...</span>';
			if (refresh == 1) {
				history.go(0);
			}
		}
	}
	xmlHttp.open("GET","ajax.php?"+attribs,true);
	xmlHttp.send(null);
}

function change_pic(target, pic, pic_num) {
	var large = $(target).src;
	var large_src = large.split('&w=');
	var small_src = pic.split('&w=');
	
	$('selected_pic').value = pic_num;
	$(target).src = small_src[0]+'&w='+large_src[1];
}

function step_pic(id, target, all) {
	if (id > all) {
		id = 1;
	}
	
	var large = $(target).src;
	var large_src = large.split('&w=');
	var small_src = $('small_pic_'+id).src.split('&w=');
	
	$(target).src = small_src[0]+'&w='+large_src[1];
	$('selected_pic').value = id;
	
	if( all == 1 )
		return;
	
	id++;
	if( $('is_paused_pic').value == 0 )
	{
		sp = setTimeout("step_pic(" + id + ", '" + target + "', " + all + ")", 3000);
	}
}

function forward_pic(pic_num, way, all) {
	clearTimeout(sp);
	if (way == 'left') {
		if (pic_num == 1) pic_num = all+1;
		pic_num--;
	}
	if (way == 'right') {
		if (pic_num == all) pic_num = 0;
		pic_num++;
	}
	
	$('selected_pic').value = pic_num;
	step_pic(pic_num, 'main_pic', all);
}

function check_pause2(is_paused, all_pics) {
	if (is_paused == 1) {
		sp = setTimeout("step_pic(" + $('selected_pic').value + ", 'main_pic', " + all_pics + ")", 3000);
		$('is_paused_pic').value = 0;
	} else {
		clearTimeout(sp);
		$('is_paused_pic').value = 1;
	}
}

function check_phone(number, thirdparty, thirdpartyid) {
	ajaxFunction('phone_target', 'act=send_phonenumber&number='+number+'&thirdparty='+thirdparty+'&thirdpartyid='+thirdpartyid);
}

function clear_alerts(num, is_cat, anum) {
	clearTimeout(move_arrow);
	// for (j = 1; j < $('all_alerts_2').value; j++) {
	// 	$('alert_arrow_up_2_'+j).style.display = 'none';
	// }
	if (is_cat == 1)
	{
		var all_alerts = $('all_alerts_'+num).value;
		for (j = 1; j < all_alerts; j++) {
			$('alert_arrow_'+num+'_'+j).style.display = 'none';
		}
		if( anum != 0 )
			$('alert_arrow_'+num+'_'+anum).style.display = '';
	}
	
	for (i = num + 1; i <= 5; i++) {
		$('alert_cats_'+i).innerHTML = '';
		$('alert_cats_'+i).style.display = '';
	} 
	$('available_services').style.display = 'none';
}

function orszagh_sandor(num, i)
{
	var all_alerts = $('all_alerts_'+num).value;
	for (j = 1; j < all_alerts; j++) {
		$('alert_left_'+num+'_'+j).className = 'fl alert_left';
		$('alert_box_'+num+'_'+j).className = 'fl alert_box';
		$('alert_right_'+num+'_'+j).className = 'fl alert_right';
	}
	$('alert_left_'+num+'_'+i).className = 'fl alert_left_blue';
	$('alert_box_'+num+'_'+i).className = 'fl alert_box_blue';
	$('alert_right_'+num+'_'+i).className = 'fl alert_right_blue';
}

function up_arrow_move(num) {
	if( !$('all_alerts_2') || num == null )
		return;
	
	if (num == $('all_alerts_2').value) {
		num = 1;
	}
	var next_num = num + 1;
	for (j = 1; j < $('all_alerts_2').value; j++) {
		$('alert_arrow_up_2_'+j).style.display = 'none';
	}
	$('alert_arrow_up_2_'+num).style.display = '';
	
	move_arrow = setTimeout("up_arrow_move(" + next_num + ")", 1000);
}

function getFlashMovieObject(movieName)
{
	if( !isIE )
	{
		if( document.embeds && document.embeds[movieName] )
			return document.embeds[movieName];
		return $(movieName); 
	}
	else
	{
		return $(movieName);
	}
}

function playFlashMovie(movie, span, div)
{
	var flashMovie=getFlashMovieObject(movie);
	var button_div = $(div);
	var button_span = $(span);
	
	stopAllFlash(movie);
	
	flashMovie.SetVariable('command','play');
	
	button_div.onclick = 'stopFlashMovie(\''+movie+'\', \''+span+'\', \''+div+'\');';
	button_span.innerHTML = '<a class="black_link" href="javascript:void(0);" onclick="stopFlashMovie(\''+movie+'\', \''+span+'\', \''+div+'\');">STOP</a>';
}

function stopFlashMovie(movie, span, div)
{
	var flashMovie = getFlashMovieObject(movie);
	var button_div = $(div);
	var button_span = $(span);
	
	if( flashMovie )
	{
		try {
			flashMovie.SetVariable('command','stop');
			button_div.onclick = 'playFlashMovie(\''+movie+'\', \''+span+'\', \''+div+'\');';
			button_span.innerHTML = '<a class="black_link" href="javascript:void(0);" onclick="playFlashMovie(\''+movie+'\', \''+span+'\', \''+div+'\');">PLAY</a>';
		}
		catch( err ) {}
	}
}

function stopAllFlash(current_flash)
{
	for (i = 0; i < flash_objects.length; i++)
	{
		if (flash_objects[i] != current_flash)
		{
			var explode = flash_objects[i].split('_');
			stopFlashMovie(''+flash_objects[i]+'', ''+explode[0]+'_button_'+explode[2]+'', ''+explode[0]+'_div_'+explode[2]+'');
		}
	}
}

function sendPage()
{
	var error = false;
	/*
	alert(
		"your name: "+$('send_page_sender_name').value+"\n"+
		"your email: "+$('send_page_sender_email').value+"\n"+
		"recipient email: "+$('send_page_recipient_email').value+"\n"
	);
	*/
	$('send_page_error_frame').innerHTML = '';
	if ( $('send_page_sender_name').value == '' ) {
		$('send_page_error_frame').innerHTML = $('send_page_error_frame').innerHTML + 'Please fill the Name field<br />';
		error = true;
	}
	if ( $('send_page_sender_email').value == '' ) {
		$('send_page_error_frame').innerHTML = $('send_page_error_frame').innerHTML + 'Please fill Your Email Address<br />';
		error = true;
	}
	if ( $('send_page_recipient_email').value == '' ) {
		$('send_page_error_frame').innerHTML = $('send_page_error_frame').innerHTML + 'Please fill the Recipient field<br />';
		error = true;
	}
	if ( error == false ) {
		if ( echeck( $('send_page_sender_email').value ) == false || echeck( $('send_page_recipient_email').value ) == false ) {
			$('send_page_error_frame').innerHTML = $('send_page_error_frame').innerHTML + 'Please check the email formats<br />';
			error = true;
		}
	}
	if ( error == false ) {
		ajaxFunction( 'send_page_status_frame', 'act=email_this&name='+$('send_page_sender_name').value+'&sender_email='+$('send_page_sender_email').value+'&recipient_mail='+$('send_page_recipient_email').value+'&url='+document.location.href );
	}
	$('emaildiv').innerHTML = '';
	return false;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}
		if (str.indexOf(at,(lat+1))!=-1){
		    return false
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		}
	  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		}
		if (str.indexOf(" ")!=-1){
		    return false
	  }
 		return true					
}

/* ---- */

var AdvR = "", AdvT = "";

function showLayer( id )
{
	if( AdvT != "" && AdvR != "" )
	{
		hideLayer(id);
		return;
	}
	
	hideFlash();
	
	// -- IE6 bug in which selects show over the semitransparent border
	if( isIE6 )
		hideSelects();
	
	var arrayPageSize = getPageSize();
	var cover = $('cover');
	
	// set height of Overlay to take up whole page and show
	cover.style.height = (arrayPageSize[1] + 'px');
	cover.style.display = 'block';
	
	// -- Div Sizing
	var ChildDiv = $(id);
	var ParentDiv = ChildDiv.parentNode;
	var viewportMiddlepoint = parseInt(document.viewport.getHeight());
	var controlHeight = parseInt(ChildDiv.style.height);
	var controlPadding = parseInt(ChildDiv.style.padding);
	
	if( isNaN(controlPadding) )
		controlPadding = 0;
	
	var lightboxTop = Math.round((viewportMiddlepoint - (controlHeight + controlPadding)) / 2);
	
	if( isIE6 )
	{
		// alert("Viewport Middlepoint: " + viewportMiddlepoint + "\n"
		// 	+ "Control Height: " + controlHeight + "\n"
		// 	+ "Control Padding: " + controlPadding + "\n"
		// 	+ "Lightbox Top: " + lightboxTop);
		
		// ParentDiv.style.top = '100px';
	}
	else
	{
		ParentDiv.style.top = lightboxTop + 'px';
	}
	
	opacity('cover', 0, 70, 300);
	opacity(id, 0, 100, 200);
}
function hideLayer( id )
{
	opacity('cover', 70, 0, 300);
	opacity(id, 100, 0, 200);
	showFlash();
	
	// -- IE6 bug in which selects show over the semitransparent border
	if( isIE6 )
		showSelects();
}

// ----

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight); 
	return arrayPageSize;
}

// ----

function hideFlash()
{
	if (!document.getElementsByTagName){ return; }
	var elements = document.getElementsByTagName("div");

	// loop through all anchor tags
	for (var i=0; i<elements.length; i++){
		var element = elements[i];

		if( (element.getAttribute("rel") == "flashContainer") ) {
			element.style.display = "none";
		}
	}
}

function showFlash()
{
	if (!document.getElementsByTagName){ return; }
	var elements = document.getElementsByTagName("div");

	// loop through all anchor tags
	for (var i=0; i<elements.length; i++){
		var element = elements[i];

		if( (element.getAttribute("rel") == "flashContainer") ) {
			element.style.display = "block";
		}
	}
}

function hideSelects()
{
	if (!document.getElementsByTagName){ return; }
	var elements = document.getElementsByTagName("select");
	
	// loop through all anchor tags
	for (var i=0; i<elements.length; i++){
		var element = elements[i];
		if( element.className != "alwaysVisible" )
		{
			element.style.display = "none";
		}
	}
}

function showSelects()
{
	if( !document.getElementsByTagName )
		return;
	
	var elements = document.getElementsByTagName("select");

	// loop through all anchor tags
	for (var i=0; i<elements.length; i++){
		var element = elements[i];
		element.style.display = "block";
	}
}

// ----

function preventDoubleClick( id, timer )
{
	$(id).disabled = true;
	setTimeout("preventDoubleClickEnd('" + id + "')", timer);
}

function preventDoubleClickEnd( id )
{
	$(id).disabled = false;
}

function showMyDownloads(){
    showLayer('my_content');
    
    ajaxMyAlertsRequest();
    ajaxMyDownloadsRequest();
}


function ajaxParseResponse( response )
{
	var ResponseStr = new String(response);
	var ResponseSeparator = "--==--";
	var ResponseArr = ResponseStr.split(ResponseSeparator);
	
	ResponseArr[0] = parseInt(ResponseArr[0]);
		
	return ResponseArr;
}


/** Dojo functions **/

function ajaxPurchaseRequest(parentControl, targetControl, query){
    var ajaxCallback = function(transport) {
        if(transport.responseText == "") {
            $(targetControl).innerHTML = 'An error occurred, please try again...';
        } else {
        	var response = ajaxParseResponse(transport.responseText);
        	
        	// -- If the request failed, allow them to resubmit
        	if( response[0] == 0 )
        		response[1] += "<br /><br /><input type=\"image\" src=\"/themes/default/images/ok_button.gif\" name=\"phone_send2\" id=\"phone_send2\" value=\"Ok\" onclick=\"ajaxPurchaseRequest('payforit', 'phone_target2', 'act=pay_item&number='+$('phone_number2').value+'&network='+$('network').value+'&order_url='+escape($('order_url').value));\" />";
        	
        	$(targetControl).innerHTML = response[1];
            // hideLayer(parentControl);
        }
    };
    
    prototypeAjaxRequest(query, ajaxCallback);
}

function ajaxMyDownloadsRequest(){

    var targetControl = $('my_content_downloads');
    var query = "act=my_downloads";
    var ajaxCallback = function(transport){
        if(transport.responseText == ""){
            targetControl.innerHTML = 'You are currently no downloads available';
        } else {
            targetControl.innerHTML = transport.responseText;
        }
    };
    
    prototypeAjaxRequest(query, ajaxCallback);

}

function ajaxMyAlertsRequest(){

    var targetControl = $('my_content_alerts');
    var query = "act=my_alerts";
    var ajaxCallback = function(transport){
        if(transport.responseText == ""){
            targetControl.innerHTML = 'You are currently not subscribed to any alerts';
        } else {
            targetControl.innerHTML = transport.responseText;
        }
    };
    
    prototypeAjaxRequest(query, ajaxCallback);

}

function ajaxMyAlertsUpdate( id, shortcode, keyword, nodeid, newStatus )
{
    var targetControl = $('alStat' + id);
    var query = "act=update_alert&shortcode="+ shortcode +"&keyword="+ keyword +"&itemid="+ id +"&itemnodeid="+ nodeid +"&status="+ newStatus +"";
    
    var ajaxCallback = function(transport){
        if(transport.responseText == ""){
            // targetControl.innerHTML = 'You are currently not subscribed to any alerts';
            ajaxMyAlertsRequest();
        } else {
            targetControl.innerHTML = transport.responseText;
            ajaxMyAlertsRequest();
        }
    };
    
    prototypeAjaxRequest(query, ajaxCallback);

}

function prototypeAjaxRequest(query, callback){
    new Ajax.Request('ajax.php?' + query,
        {
        method:'get',
        onSuccess: callback
        }
    );
}

function noContentPopup( redirectToHome )
{
	if( redirectToHome )
		showLayer('noContentToHome');
	else
		showLayer('noContent');
}

// ----

/**
 * AJAX function call for alert subscription
 */
function alertSubscribeRequest(parentControl, targetControl, query){
    var ajaxCallback = function(transport) {
        if(transport.responseText == "") {
            $(targetControl).innerHTML = 'An error occurred, please try again...';
        } else {
        	var response = ajaxParseResponse(transport.responseText);
        	
        	// -- If the request failed, allow them to resubmit
        	if( response[0] == 0 )
        		response[1] += "<br /><br /><input type=\"image\" src=\"/themes/default/images/ok_button.gif\" name=\"phone_send2\" id=\"phone_send2\" value=\"Ok\" onclick=\"alertSubscribeSubmit();\" />";
        	
        	$(targetControl).innerHTML = response[1];
            // hideLayer(parentControl);
        }
    };
    
    prototypeAjaxRequest(query, ajaxCallback);
}

/**
 * Call the alerts subscription popup
 */
function alertSubscribeCall( url, shortcode, phoneNumber, keyword, type )
{
	$('alertSubOrderUrl').value = url;
	$('alertSubShortcode').value = shortcode;
	$('alertSubPhone').value = phoneNumber;
	$('alertSubKeyword').value = keyword;
	$('alertSubType').value = type;
	
	$('alertSubTypeText').innerHTML = (type == 1 ? 'subscribe' : 'try-out');
	
	showLayer('alertSubscribePopup');
}

/**
 * Submit the alerts subscription popup
 */
function alertSubscribeSubmit()
{
	alertSubscribeRequest('alertSubscribePopup',
		'alertSubscribeTarget',
		'act=subscribe_alert'
			+ '&order_url=' + $('alertSubOrderUrl').value
			+ '&shortcode=' + $('alertSubShortcode').value
			+ '&number=' + $('alertSubPhone').value
			+ '&subscribe_alert_keyword=' + $('alertSubKeyword').value
			+ '&subscribe_alert_type=' + $('alertSubType').value
		);
}

/**
 * Close the alerts subscription popup
 */
function alertClose()
{
	hideLayer('alertSubscribePopup');
	$('alertSubscribeTarget').innerHTML = "<input type=\"image\" src=\"/themes/default/images/ok_button.gif\" name=\"phone_send2\" id=\"phone_send2\" value=\"Ok\" onclick=\"alertSubscribeSubmit();\" />";
	$('alertSubTarget').innerHTML = '';
}

// ----

/**
 * AJAX function call for ordering
 */
function orderRequest(parentControl, targetControl, query)
{
    var ajaxCallback = function(transport) {
        if(transport.responseText == "") {
            $(targetControl).innerHTML = 'An error occurred, please try again...';
        } else {
        	var response = ajaxParseResponse(transport.responseText);
        	
        	// -- If the request failed, allow them to resubmit
        	if( response[0] == 0 )
        		response[1] += '<br /><br /><input type="image" src="/themes/default/images/ok_button.gif" name="phone_send2" id="phone_send2" value="Ok" onclick="orderSubmit();" />';
        	
        	$(targetControl).innerHTML = response[1];
            // hideLayer(parentControl);
        }
    };
    
    prototypeAjaxRequest(query, ajaxCallback);
}

/**
 * Call the order popup
 */
function orderCall()
{
	showLayer('payforit');
}

/**
 * Submit the order popup
 */
function orderSubmit()
{
	ajaxPurchaseRequest('payforit',
		'phone_target2',
		'act=pay_item&number=' + $('phone_number2').value
		+ '&network=' + $('network').value
		+ '&order_url=' + escape($('order_url').value));
}

/**
 * Close the order popup
 */
function orderClose()
{
	hideLayer('payforit');
	$('phone_target2').innerHTML = '<input type="image" src="/themes/default/images/ok_button.gif" name="phone_send2" id="phone_send2" value="Ok" onclick="orderSubmit();" />';
}