function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

function commentValidate(){
	var name = document.VideoBean.name.value;
	if(name == ''){
		alert("Please enter your name");
		document.VideoBean.name.focus();
		return false;
	}

	var email = document.VideoBean.email.value;
	if(email == ''){
		alert("Please enter your email");
		document.VideoBean.email.focus();
		return false;
	}

	var comment = document.VideoBean.comment.value;
	if(comment == ''){
		alert("Please enter your comments");
		document.VideoBean.comment.focus();
		return false;
	}
	var verificationCode = document.VideoBean.verificationCode.value;
	if(verificationCode == ''){
		alert("Please enter verification code");
		document.VideoBean.verificationCode.focus();
		return false;
	}
	return true;
}
function setComment(videoID){
	if(commentValidate()){ 
	var name = document.VideoBean.name.value;
	var email = document.VideoBean.email.value;
	var comment = document.VideoBean.comment.value;
	var verificationCode = document.VideoBean.verificationCode.value;
	var userID = document.VideoBean.userID.value;
	
	
	var url = "/submitVideo.do?step=setVideoCommnet&name="+name+"&email="+email+"&comment="+comment+"&videoID="+videoID+"&verificationCode="+verificationCode+"&userID="+userID;
	//alert(url);
	var req = getAjexRequest();
	req.open("POST", url, true);
	//alert(req.readyState);
	req.onreadystatechange = setVideoCommnet;
	req.send(null);	
	}
}

var tempthis="";
function setLikeOrDislike(videoID, likeOrDislike, value){
	
	var isLogin = document.videoForm.islogin.value;
	//alert("isLogin---" + isLogin);
//	document.getElementById(likeOrDislike)
	if(tempthis=="yes"){
		alert("You have already rated this video");
	}else{
	if(isLogin=="Yes"){
	var url = "/submitVideo.do?step=setLikesDislikes&videoID="+videoID+"&likeOrDislike="+likeOrDislike+"&value="+value;
	var req = getAjexRequest();
	req.open("POST", url, true);
	//alert(req.readyState);
	req.onreadystatechange = getLikeOrDislikeResponse;
	req.send(null);
	}else if(isLogin=="No"){
		alert("Kindly login to rate this.");
	}
	}	
}

function getLikeOrDislikeResponse(){
		if (req.readyState == 4) {
			if (req.status == 200) {
			
				var splitRes = req.responseText.split('@@');
				var atag = document.getElementById(splitRes[1]);
				atag.innerHTML = splitRes[0] +"  "+splitRes[1]+"s";
				tempthis='yes';
			}
		}
}

function getAjexRequest(){
		if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return req;
}

function setVideoCommnet(){
	if (req.readyState == 4) {
		if (req.status == 200) {
				if(req.responseText.indexOf('Please')>=0){
					alert(req.responseText);
					document.VideoBean.verificationCode.value="";
				}else{
				if(req.responseText=='true'){
				alert("Your comment has been saved");
				document.VideoBean.name.value="";
				document.VideoBean.email.value="";
				document.VideoBean.comment.value="";
				document.VideoBean.verificationCode.value="";
				document.location.reload()
				}
			}
		}
	}
}


function setURL(){
	document.videoForm.url.value=getUrlVars();
}
