﻿function getURL(url){
    window.location = url;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
var DLExtended = {
	start: function(){
		var tab = $('tn_themes');
		var box = $('downloadsExtended');
		var fix = new Element('iframe', {'id': 'hoverFix'}).inject(box,'after');
		
		tab.addEvents({
			'mouseenter': function(){ DLExtended.popAdd(tab,box,fix); },
			'mouseleave': function(){ DLExtended.popRmv(tab,box,fix); }
			//'click': function(e){ e = new Event(e).stop(); }
		});
		box.addEvents({
			'mouseenter': function(){ DLExtended.popAdd(tab,box,fix); },
			'mouseleave': function(){ DLExtended.popRmv(tab,box,fix); }
		});
	},
	
	popRmv: function(tab,box,fix){
		box.removeClass('gameOn');
		fix.removeClass('gameOn');
		tab.removeClass('show');
	},
	
	popAdd: function(tab,box,fix){
		box.addClass('gameOn');
		fix.addClass('gameOn');
		tab.addClass('show');
	}
}


function getHttp(){var xmlHttp = null; try {xmlHttp = new XMLHttpRequest();} catch (e) {var progIds = ['MSXML2.XMLHTTP', 'Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0'];var success = false;for (var iterator = 0; (iterator < progIds.length) && ( ! success); iterator ++) {try {xmlHttp = new ActiveXObject(progIds[iterator]); success = true;}catch (e) {}}if (! success){return null;}} return xmlHttp;}
function call(url,handler,data){http = this.getHttp(); if(!http) alert('No HTTP Object'); http.onreadystatechange = function(){if (http.readyState == 4) {if (http.status == 200) {if (http.responseXML != null) {return eval(handler+'(http.responseXML)');}}}return false;}; http.open("POST", url, true); http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); http.send(data);}


// THEME FUNCTIONS
var themes_by_author_current = 10;
function themesByAuthor(author){
    try{
        call('api.php?o=author&a=get&author='+author+'&s='+themes_by_author_current, 'themesByAuthor_RSP','');
        document.getElementById('themes_by_author_a').innerHTML = '<img src="http://www.symbianthemes.us/img/loading_txt.gif" alt="Loading..." />';
    }
    catch(error){}
}

function themesByAuthor_RSP(data){
	var root = data.childNodes; if(root[1] != null){var i = 1;} else {var i = 0}; var xml_nodes = root[i].childNodes;
    for(j = 0; j < xml_nodes.length; j++){
        if(xml_nodes[j].nodeName == 'themes'){
            var s = xml_nodes[j].getAttribute('start'); themes_by_author_current = s; var ta = document.getElementById('themes_by_author_a');
            if(s == 0){ta.innerHTML = 'View the latest themes from this author!';}
            else{ta.innerHTML = 'More themes!';}
            var tdiv = document.getElementById('themes_by_author');
            tdiv.innerHTML = xml_nodes[j].firstChild.nodeValue;
        }
    }
    return;
}
function themeVote(id){
	try{
		call('api.php?o=theme&a=vote&theme='+id, 'themeVote_RSP','');
		document.getElementById('theme_vote_'+id).innerHTML = '<center><img class="loading_theme_vote" src="http://www.symbianthemes.us/img/loading_txt.gif" alt="Loading..." /></center>';
		
	}
	catch(error){}
}

function themeVote_RSP(data){
	var root = data.childNodes;
	if(root[1] != null){var i = 1;}
	else {var i = 0};	
	var xml_nodes = root[i].childNodes;
	for(j = 0; j < xml_nodes.length; j++){
		if(xml_nodes[j].nodeName == 'theme'){
			var theme_id = xml_nodes[j].getAttribute('id');
			var theme_status = xml_nodes[j].getAttribute('status');
			
			var ta = document.getElementById('theme_vote_'+theme_id);
			if(theme_status == 0){
				ta.innerHTML = 'You have voted for this theme in the last 24 hours!';
			}
			else{
				ta.innerHTML = 'Thank you for your vote!';
			}
		}
	}
	return;
}  




function themeLike(id){
	try{
		call('api.php?o=theme&a=like&theme='+id, 'themeLike_RSP','');
		document.getElementById('iLikeThisTheme').innerHTML = 'Loading...';
		
	}
	catch(error){}
}

function themeLike_RSP(data){
	var root = data.childNodes;
	if(root[1] != null){var i = 1;}
	else {var i = 0};	
	var xml_nodes = root[i].childNodes;
	for(j = 0; j < xml_nodes.length; j++){
		if(xml_nodes[j].nodeName == 'theme'){
			var theme_status = xml_nodes[j].getAttribute('message');
			document.getElementById('iLikeThisTheme').innerHTML = theme_status;
		}
	}
	return;
}  
