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 =  'processing';
		}
		if(http_request.readyState == 2){
		 document.getElementById(div).innerHTML =  'processing';
		}
		if(http_request.readyState == 3){
		 document.getElementById(div).innerHTML =  'processing';
		}
		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 track(url, 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 =  'processing';
		}
		if(http_request.readyState == 2){
		 document.getElementById(div).innerHTML =  'processing';
		}
		if(http_request.readyState == 3){
		 document.getElementById(div).innerHTML =  'processing';
		}
		if (http_request.readyState == 4){
		    if (http_request.status != 200){
			  alert('There was a problem with the request.' + http_request.status);
		    }
		}
	}

}

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', '/admin/featured.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(div).innerHTML =  'processing';
		}
		if(http_request.readyState == 2){
		 document.getElementById(div).innerHTML =  'processing';
		}
		if(http_request.readyState == 3){
		 document.getElementById(div).innerHTML =  'processing';
		}
		 if (http_request.readyState == 4) {
		    if (http_request.status == 200) {
			    
				response  = http_request.responseXML.documentElement;
			 	//var method = response.getElementsByTagName('method')[0].firstChild.data;
			 	var result = response.getElementsByTagName('result')[0].firstChild.data;
				
				//document.getElementById(m_div).innerHTML = method;
				document.getElementById(r_div).innerHTML = result;
				
				new Effect.Pulsate(m_div, {duration: 1});
				new Effect.Highlight(r_div);
				
		    } else {
			 alert('There was a problem retrieving the XML data:\n' + http_request.statusText);
		    }
		 }
	}
}



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 activ(id, params){
	makePOSTRequest('/backoffice/activate.php?', 'id_' + id, params);
}

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

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

function trackclicks(params){
	track('/trackclicks.php?', 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 )) + "&profile_id=" + encodeURI( document.getElementById("profile_id").value );
      makePOSTRequest('/ajaxcomments/previewcomment?', div, poststr);
}
   
   
function process_comment(obj){
	  var div="results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value ))+ "&profile_id=" + encodeURI( document.getElementById("profile_id").value );
      makePOSTRequest('/ajaxcomments/submitcomment?', 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 );
		}
}