
function picCommentRequest(pageNum, ipp, id){
	var ajaxRequest;
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser does not support AJAX.");
				return false;
			}
		}
	}
	ajaxRequest.open("GET", "/picCommentRequest.php?ipp="+ipp+"&video_id="+id+"&page="+pageNum+"&rn="+Math.random(), true);
	ajaxRequest.send(null);
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(ajaxRequest.status == 200){
			document.getElementById("pictureComments").innerHTML = ajaxRequest.responseText;
			}else{
			document.getElementById("pictureComments").innerHTML = "Server Not Responding";
			}
		}
	}
}

function commentAdd()
{
	var ajaxRequest;
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser does not support AJAX.");
				return false;
			}
		}
	}
	
	var comment = document.getElementById("cmt_comment").value;
	var video = document.getElementById("cmt_id").value;
	var cpcode = document.getElementById("c_code").value;
	
	if(document.getElementById("cmt_comment").value.length < 2)
	{
		document.getElementById("commentResponse").innerHTML = "Please enter a comment";
	}
	else
	{
		if(document.getElementById("cmt_comment").value.length > 500)
		{
			document.getElementById("commentResponse").innerHTML = "Comment Too Long";
		}
		else
		{
		
			ajaxRequest.open("GET", "/comment.php?comment="+comment+"&id="+video+"&type=picture&rn="+Math.random()+"&captcha="+cpcode, true);
			ajaxRequest.send(null);
			ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4)
				{
					if(ajaxRequest.status == 200)
					{
					document.getElementById("commentResponse").innerHTML = ajaxRequest.responseText;
					picCommentRequest('1', '10', video);
					
						if(ajaxRequest.responseText == "Comment Added!")
						{
							document.getElementById("commentBox").style.display = "none";
						}
					}
					else
					{
					document.getElementById("commentResponse").innerHTML = "Server Not Responding";
					}
				}
		}
	}
}
}
function limitText(limitNum) {
	if (document.getElementById("cmt_comment").value.length > limitNum) {
		document.getElementById("cmt_comment").value = document.getElementById("cmt_comment").value.substring(0, limitNum);
	} else {
		document.getElementById("cmtLimit").innerHTML = limitNum - document.getElementById("cmt_comment").value.length;
	}
}

function rate(rating, id){
	var ajaxRequest;
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser does not support AJAX.");
				return false;
			}
		}
	}
	ajaxRequest.open("GET", "/ratings.php?type=picture&id="+id+"&rating="+rating+"&rn="+Math.random(), true);
	ajaxRequest.send(null);
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(ajaxRequest.status == 200){
			document.getElementById("picRating").innerHTML = ajaxRequest.responseText;
			}else{
			document.getElementById("picRating").innerHTML = "Server not Responding";
			}
		}
	}
}

function bookmark(url,title)
{
	  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
	  {
		  window.external.AddFavorite(url,title);
	  } 
	  else if (navigator.appName == "Netscape") 
	  {
		window.sidebar.addPanel(title,url,"");
	  }
}