// JavaScript Document


// visual functions
// navigation movement funciton
function CountLeft(field, count, max) { 
	if (field.value.length > max)
 		field.value = field.value.substring(0, max);
 	else 
 		count.value = max - field.value.length;
 		if (field.value.length > (max-15))   
			count.style.color = '#CA4D46';
		else
			count.style.color = '#716552';
}

function man_user(the_path, to_do, user_id) {
	method = "post";
	path = the_path;
	var form = document.createElement("man_form");
	form.setAttribute("method", method);
	form.setAttribute("action", path);
	form.setAttribute("todo", to_do);
	form.setAttribute("userid", user_id);
	document.body.appendChild(form);    // Not entirely sure if this is necessary
    form.submit();
}
function post_to_url(path, params, method) {
    method = method || "post"; // Set method to post by default, if not specified.
    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);
        form.appendChild(hiddenField);
    }
    document.body.appendChild(form);    // Not entirely sure if this is necessary
    form.submit();
}

// used to show user data //
function fetchData(url, objectID, userID, res) {
	var pageRequest = false;
	if (window.XMLHttpRequest) pageRequest = new XMLHttpRequest();
	else if (window.ActiveXObject) pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
	else return false;
	pageRequest.onreadystatechange = function() {
		var object = document.getElementById(objectID);
		object.innerHTML = pageRequest.responseText;
		if (res == 'image') {
			var imgh = $('#imagemain').height();
			var imgw = $('#imagemain').width();
			//$('#imagemain').css({'height': imgh, 'width': imgw});
			$('#imagebox').css({'height': (imgh+20), 'width': imgw});
		} 
		for (ii=1; ii< 6; ii++) {
			if ($('#my_video_'+ii)){
				$('#my_video_'+ii).VideoJS();
			}
		}
		//if (res =='light') {
			//$('#lightmain').css({'height': 480, 'width': 790});
			//$('#'+objectID).css({'height': 500, 'width': 790});
		//}
	}
	browh = (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.body.offsetHeight);
	var tmpurl = url + '?itmid=' + userID + '&browh=' + browh;
	pageRequest.open('GET', tmpurl,true);
	pageRequest.send(null);
}

 
$(document).ready(function(){
	$("#topsearch").focusin(function() {
		$(this).find("input").attr('value', '');
		$(this).find("input").css('color','#000');
	});
	$("#topsearch").focusout(function() {
		$(this).find("input").attr('value', 'SEARCH');
		$(this).find("input").css('color','#CCC');
	});
	
    $(".ghead").click(function () { 
		if ($(this).parent().find("#sub_nav").is(":hidden")) {
    	  $(this).parent().find("#sub_nav").slideDown();
		  $(this).parent().find("#openclose").html("&minus;"); 
		} else {
			$(this).parent().find("#sub_nav").slideUp(); 
			$(this).parent().find("#openclose").html("+");
		}
    });
});

