var http_request = false;

function makePOSTRequest(url, div, parameters){
      http_request = false;
    	if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
    	 }else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         }catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e) {}
         }
      }
	 http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
	 
	http_request.onreadystatechange = function() {
		/*if(http_request.readyState == 1){
		 document.getElementById(div).innerHTML =  'data recieved';
		}
		if(http_request.readyState == 2){
		 document.getElementById(div).innerHTML =  'sending data';
		}
		if(http_request.readyState == 3){
		 document.getElementById(div).innerHTML =  'processing data';
		}*/
		if (http_request.readyState == 4){
		    if (http_request.status == 200){
			  document.getElementById(div).innerHTML = http_request.responseText;
		    }else{
			  alert('There was a problem with the request.' + http_request.status);
		    }
		}
	}

}


function rating(url, div, param){
   if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", param.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(param);
	 
	http_request.onreadystatechange = function() {
		if(http_request.readyState == 2){
		 document.getElementById('overall_rating').innerHTML =  'processing data';
		 document.getElementById(div).innerHTML =  'processing data';
		 document.getElementById('voters').innerHTML =  'gathering voters';
		}
		 if (http_request.readyState == 4) {
		    if (http_request.status == 200) {
				response  = http_request.responseXML.documentElement;
				document.getElementById(div).innerHTML = response.getElementsByTagName('star')[0].firstChild.data;
				document.getElementById('overall_rating').innerHTML = response.getElementsByTagName('overall_rating')[0].firstChild.data;
				document.getElementById('voters').innerHTML = response.getElementsByTagName('voters')[0].firstChild.data;
		    }
		}
	}

}


function ratingawards(url, div, param){
   if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", param.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(param);
	 
	http_request.onreadystatechange = function() {
		if(http_request.readyState == 2){
		 document.getElementById(div).innerHTML =  'processing data';
		}
		 if (http_request.readyState == 4) {
		    if (http_request.status == 200) {
				response  = http_request.responseXML.documentElement;
				document.getElementById(div).innerHTML = response.getElementsByTagName('star')[0].firstChild.data;
		    }
		}
	}

}


function FeaturedRequest(m_div, r_div, logo_id) {
    	if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
      http_request.open('POST', '/toolkit/scripts/user_awards_admin.php?', true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", logo_id.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(logo_id);

    
	http_request.onreadystatechange = function() {
		if(http_request.readyState == 1){
		 document.getElementById(m_div).innerHTML =  'data received';
		}
		if(http_request.readyState == 2){
		 document.getElementById(m_div).innerHTML =  'processing';
		}
		if(http_request.readyState == 3){
		 document.getElementById(m_div).innerHTML =  'processing';
		}
		 if (http_request.readyState == 4) {
		    if (http_request.status == 200) {
			    
				response  = http_request.responseXML.documentElement;
			 	var credit = response.getElementsByTagName('credit')[0].firstChild.data;
			 	var result = response.getElementsByTagName('result')[0].firstChild.data;
				
				document.getElementById(m_div).innerHTML = result;
				document.getElementById(r_div).innerHTML = credit;
				
		    } else {
			 alert('There was a problem retrieving the XML data:\n' + http_request.statusText);
		    }
		 }
	}
}







function enterAward(logo_id, user_id, cat, opt){
	var param =  "logo_id=" + logo_id + "&user_id=" + user_id + "&cat=" + cat + "&opt=" + opt;
	FeaturedRequest(cat + "_" + logo_id, "credit", param);
}










function add_favs(logo_id, user_id){
	makePOSTRequest('/toolkit/scripts/add_favs.php?', 'id_' + logo_id, 'logo_id=' + logo_id + '&user_id=' + user_id);
}

function plus(logo_id, user_id){
	makePOSTRequest('/toolkit/scripts/float.php?', 'float_' + logo_id, 'f=up&logo_id=' + logo_id + '&user_id=' + user_id);
}

function minus(logo_id, user_id){
	makePOSTRequest('/toolkit/scripts/float.php?', 'float_' + logo_id, 'f=down&logo_id=' + logo_id + '&user_id=' + user_id);
}


function add_fav_user(fav_id, user_id){
	makePOSTRequest('/toolkit/scripts/add_fav_user.php?', 'id_' + fav_id, 'fav_id=' + fav_id + '&user_id=' + user_id);
}
















function rate_logo(logo_id, user_id, cat, value){
	rating('/toolkit/scripts/rate_logo.php?', 'id_' + logo_id + '_' + cat, 'logo_id=' + logo_id + '&user_id=' + user_id + '&cat=' + cat+ '&value=' + value);
}


function rate_logo_awards(logo_id, judge_id, cat, value){
	ratingawards('/toolkit/scripts/rate_logo_awards.php?', 'id_' + logo_id + '_' + cat, 'logo_id=' + logo_id + '&judge_id=' + judge_id + '&cat=' + cat+ '&value=' + value);
}




















function activ(id, params){
	makePOSTRequest('/backoffice/activate.php?', 'id_' + id, params);
}


function deactiv(id, params){
	makePOSTRequest('/backoffice/activate.php?', 'id_' + id, params);
}

function checkusers(obj){
	 var div = "check_username";
      var poststr = "sub_username=" + encodeURI( document.getElementById("sub_username").value );
      makePOSTRequest('/members/checkuser.php?', div, poststr);
}


function get_preview_comment(obj){
	  var div = "results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value )) + "&logo_id=" + encodeURI( document.getElementById("logo_id").value );
      makePOSTRequest('/ajax_comments/preview_comment.php?', div, poststr);
}
   
   
function process_comment(obj){
	  var div="results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value ))+ "&logo_id=" + encodeURI( document.getElementById("logo_id").value );
      makePOSTRequest('/ajax_comments/submit_comment.php?', div, poststr);
}




function get_preview_comment_blog(obj){
	  var div = "results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value )) + "&blog_id=" + encodeURI( document.getElementById("blog_id").value );
      makePOSTRequest('/ajax_comments/preview_comment_blog.php?', div, poststr);
}
   
   
function process_comment_blog(obj){
	  var div="results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value ))+ "&blog_id=" + encodeURI( document.getElementById("blog_id").value );
      makePOSTRequest('/ajax_comments/submit_comment_blog.php?', div, poststr);
}





function get_preview_comment_game(obj){
	  var div = "results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value )) + "&game_id=" + encodeURI( document.getElementById("game_id").value );
      makePOSTRequest('/ajax_comments/preview_comment_game.php?', div, poststr);
}
   
   
function process_comment_game(obj){
	  var div="results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value ))+ "&game_id=" + encodeURI( document.getElementById("game_id").value );
      makePOSTRequest('/ajax_comments/submit_comment_game.php?', div, poststr);
}


























last_tab = 'tab1';
function show(layerName) {
document.getElementById(layerName).style.display = '';
}

function hide(layerName) {
document.getElementById(layerName).style.display = 'none';
}
function show_next(tab_name) {
document.getElementById(last_tab).className = 'tab';
var curr = document.getElementById(tab_name);
curr.className='tab_hover';
hide(last_tab+'_data');
show(tab_name+'_data');
last_tab=tab_name;
}




function setTextCount( textField, remainingField, maxLength ) {
	var elTextField = document.getElementById(textField);
	var elRemainingField = document.getElementById(remainingField);
	var currentCount = elTextField.value.length;
	
		if ( currentCount > maxLength ){
			elTextField.value = elTextField.value.substring(0, maxLength);elRemainingField.value = 0;
		}else{
			elRemainingField.value = ( maxLength - currentCount );
		}
}



