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){
	$.ajax({
		type: "POST",
		url: "/toolkit/scripts/add_favs.php",
		data: 'logo_id=' + logo_id + '&user_id=' + user_id,
		success: function(html){
			$("#id_" + logo_id).html(html);
			$("#flag-content-afavs").fadeOut("fast");
		}
	});
	
	}

/*	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){
	$.ajax({
		type: "POST",
		url: "/toolkit/scripts/float.php",
		data: 'logo_id=' + logo_id + '&user_id=' + user_id,
		success: function(html){
			$("#float_" + logo_id).html(html);
			$("#flag-content-afloat").fadeOut("fast");
		}
	});
	
	}
	
/*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 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?', 'onid_' + id, params);
}

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


















function inbook(id, params){
	$.ajax({
		type: "POST",
		url: "/book/inbook.php?",
		data: "onid_" + id + "&" + params,
		success: function(resp){
			$("#onid_" + id).html($('#inner_1' , resp).html());
			$("#total").html($('#inner_2' , resp).html());
		}
	});
	
}


















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






function getpreviewcomment(obj){
	  var div = "results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value )) + "&logo_id=" + encodeURI( document.getElementById("logo_id").value );
      makePOSTRequest('/ajax_comments/previewcom.php?', div, poststr);
}
   
   
function processcomment(obj){
	  var div="results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value ))+ "&logo_id=" + encodeURI( document.getElementById("logo_id").value );
      makePOSTRequest('/ajax_comments/submitcom.php?', div, poststr);
}




function getpreviewcommentforum(obj){
	  var div = "results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value )) + "&topic_id=" + encodeURI( document.getElementById("topic_id").value );
      makePOSTRequest('/ajax_comments/previewcomforum.php?', div, poststr);
}
   
   
function processcommentforum(obj){
	  var div="results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value ))+ "&topic_id=" + encodeURI( document.getElementById("topic_id").value );
      makePOSTRequest('/ajax_comments/submitcomforum.php?', div, poststr);
}








function getpreviewtopic(obj){
	  var div = "results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value )) + "&subject=" + encodeURI( escape( document.getElementById("subject").value));
      makePOSTRequest('/threads/previewtopic.php?', div, poststr);
}
   
   
function processtopic(obj){
	  var div="results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value )) + "&forum_id=" + encodeURI( document.getElementById("forum_id").value) + "&subject=" + encodeURI( escape( document.getElementById("subject").value)) + "&tag=" + encodeURI(document.getElementById("tag").value);
      makePOSTRequest('/threads/submittopic.php?', div, poststr);
}



function processtopicupdate(obj){
	  var div="results";
      var poststr = "comments=" + encodeURI( escape( document.getElementById("comments").value )) + "&new_forum_id=" + encodeURI( document.getElementById("new_forum_id").value) + "&topic_id=" + encodeURI( document.getElementById("topic_id").value) + "&subject=" + encodeURI( escape( document.getElementById("subject").value)) + "&tag=" + encodeURI(document.getElementById("tag").value);
      makePOSTRequest('/threads/submittopicupdate.php?', div, poststr);
}




$(function () {
    var tabContainers = $('div#detail > div');
    
    $('div#detail ul.navigation_reg a').click(function () {
        tabContainers.hide().filter(this.hash).show();
        
        $('div#detail ul.navigation_reg a').removeClass('selected');
        $(this).addClass('selected');
        
        return false;
    }).filter(':first').click();
});




function report_spam( comment_id, user_id ){
	$.ajax({
		type: "POST",
		url: "/ajax_comments/report_spam.php",
		data: "&comment_id=" + comment_id + "&reporter=" + user_id,
		success: function(html){
			$("#s_" + comment_id).html(html)
			$("#s_" + comment_id).fadeOut("slow");
		}
	});
	
	}


function report_spam_topic(topic_id, user_id ){
	$.ajax({
		type: "POST",
		url: "/ajax_comments/report_spam_topic.php",
		data: "&topic_id=" + topic_id + "&reporter=" + user_id,
		success: function(html){
			$("#s_" + topic_id).html(html)
			$("#s_" + topic_id).fadeOut("slow");
		}
	});
	
	}
	
function report_spam_forum_post(post_id, user_id){
	$.ajax({
		type: "POST",
		url: "/ajax_comments/report_spam_post.php",
		data: "&post_id=" + post_id + "&reporter=" + user_id,
		success: function(html){
			$("#s_" + post_id).html(html)
			$("#s_" + post_id).fadeOut("slow");
		}
	});
	
	}


function selectfilter_g(filter, activate){
	$.ajax({
		type: "POST",
		url: "/selectfilter_g.php",
		data: "&filter=" + filter + "&activate=" + activate,
		success: function(html){
			$(".filter_" + filter).html(html)
			location.reload(); 
		}
	});
	
	}


function selectfilter_o(order, activate){
	$.ajax({
		type: "POST",
		url: "/selectfilter_o.php",
		data: "&order=" + order + "&activate=" + activate,
		success: function(html){
			$(".order_" + order).html(html)
			location.reload(); 
		}
	});
	
	}



function remove_tag(id){
	$.ajax({
		type: "POST",
		url: "/members/remove_tags.php",
		data: "id=" + id,
		success: function(html){
			$("#tag_" + id).html(html);
			$("#tag_" + id).fadeOut("slow");
		}
	});
	
}
	
function remove_personal_tag(id){
	$.ajax({ 
		type: "POST",
		url: "/members/remove_personal_tags.php",
		data: "id=" + id,
		success: function(html){
			$("#tag_" + id).html(html);
			$("#tag_" + id).fadeOut("slow");
		}
	});
	
	}
	
	
function remove_topictag(id){
	$.ajax({
		type: "POST",
		url: "/threads/remove_topictags.php",
		data: "id=" + id,
		success: function(html){
			$("#tag_" + id).html(html);
			$("#tag_" + id).fadeOut("slow");
		}
	});
	
	}

function forgot_pass(){
	$.ajax({
		type: "POST",
		url: "/prc_forgotpassword.php",
		data: "username=" + document.getElementById("username").value + 
			 "&email=" + document.getElementById("emailaddress").value,
		success: function(html){
			$("#response_pass").html(html);
			}
	});
	
	}
	
function reset_pass(){
	$.ajax({
		type: "POST",
		url: "/prc_passwordreset.php",
		data: "id=" + document.getElementById("id").value,
		success: function(html){
			$("#response_pass").html(html);
			}
	});
	
	}  
	


 $(document).ready(function(){
    
		$(".jumpmenu").change(function() {
			var val = $(this).val();
			if (val != '') {
				location.href = val;
			}
		});
	   
		$(".flags-target").ezpz_tooltip({
			contentPosition: 'aboveStatic',
			showContent: function(content) {
				content.fadeIn('fast');
			},
			hideContent: function(content) {
				// if the showing animation is still running, be sure to stop it
				// and clear the animation queue. otherwise, repeatedly hovering will
				// cause the content to blink.
				content.stop(true, true).fadeOut('fast');
			}

		});
	
		
			$('.deletep, .delete_favs_users, .delete, .delete_account, .delete_favs').click(function(event) {
				location.href = $(this).attr('href');
			}).confirm();


	
		 // example 2
		 $(".thefile").prettyfile({
		   setvalue: false,
		   html: "<span class='upld'>Choose File</span>"
		 });

		 $(".avatar_file").prettyfile({
		   setvalue: false,
		   html: "<span class='avat'>Choose Avatar</span>"
		 });
		   
		// $('.pagination a').roundCorners(13);
		// $('.pagination .current').roundCorners(13);
		// $('.pagination .disabled').roundCorners(13);

		$("#swimmers").click(function() {
			$(".pos_float").slideToggle('slow');
			return false;
		});
		
		
    });
  
  

	 
	 
	sfHover = function() {
		var sfEls = document.getElementById("user_profile_menu").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);
		
