var ie = (window.navigator.userAgent.toLowerCase().indexOf("msie") != -1)? true : false;

var xhr_handler = function() {
	alert(this.responseText);
}

function v_manager(action,meme_id,post_id) {
  if(action && meme_id) {
		detailswindow = window.open("/videos/admin/?type=" + action + "&videoid=" + meme_id + "&postid=" + post_id);
		detailswindow.focus();
  }
}

function v_xhr_manager(action,meme_id,post_id) {
  if(action) {
		q = "/videos/admin/?type=" + action + "&videoid=" + meme_id + "&postid=" + post_id;
		$.ajax({
			url: q,
			async: true,
			success:  function(msg){
    			alert( msg );
			}
		})
  }
}

function switchTabs(video_id, type, on) {
	$("ul.wultabs > li").removeClass("active");
	$('#rtype'+on).addClass("active");
	
	var url;
	if(type == 0) url = '/video/posts/' + video_id;
	else if(type == 1) url = '/video/comments/' + video_id+"?reply=true";
	else if(type == 2) url = '/video/similars/' + video_id;
	else if(type == 3) url = '/video/' + video_id + "?tab=3";
	var params = '';

	$.ajax({
		type: "GET",
		url: url,
		data:params, 
		success: function(html){
			loadUrl=url;pStart=15;
			if ($('#tabcontent')) {
				$('#tabcontent').remove();
			}
			if ($('#navigate')) {
				$('#navigate').remove();
			}
			$('.gizmoPagination').remove();
			($("#tabset")).after(html);
			if(top.document.getElementById("formItem_recaptcha")){customRecaptcha();}
		}
	});
	return false;
}

function saveCommentVideo(event){
  var frm=event=(ie)?top.event.srcElement:event.target;
  while(frm.nodeName!="FORM")
    frm=frm.parentNode;
	var checkAlert="";
	var filled=0;
	for(i=0;i<frm.elements.length;i++){
	  elm=frm.elements[i];
	  n=elm.name;
	  if(n=="login" && elm.value.length<1){checkAlert+="\n"+top._mustHaveLogin;}
	  else if(n=="title" && elm.value.length>0){filled=1;}
	  else if(n=="comment" && elm.value.length>0){filled=1;}
	  else if(n=="referrer" && elm.value.length<1){elm.value=window.document.referrer;};
	};
	if(filled==0){
	  checkAlert+="\n"+top._mustSaveComment;
	};
	if(checkAlert.length<1){
	  frm.submit();
	  if(event.win)
	    top.closeWikioWindow(event);
	}
	else{alert(checkAlert);};
}

function videoVote(event,id){
	var event=(ie)?top.event.srcElement:event.target;
	while(event.nodeName!="A"){event=event.parentNode;};
	id=(event.tgtid)?event.tgtid:id;
	if(top.frames["stdfrm"] && id){
		var score=top.document.getElementById("sc"+id);
		if(score && !score.rated){
			for(i=0;i<event.childNodes.length;i++){
				e=event.childNodes[i];
				if(e.nodeType==1){
					if(e.nodeName=="STRONG"){e.childNodes[0].nodeValue=isNaN(parseInt(e.childNodes[0].nodeValue))?1:parseInt(e.childNodes[0].nodeValue)+1;};
					if(e.nodeName=="SPAN"){e.childNodes[0].nodeValue=top._hasvoted};
				}
			}
			score.rated=true;
			event.className=event.className+" clicked";	
			$.ajax({type: "GET",url: "/video/vote/"+id});
		}
	}
}

function videoanswer(event,id,videoid,displayPseudo,pseudo){
	var tgt=event=(ie)?window.event.srcElement:event.target;top.edit=true;
	a=top.document.getElementById("answer");if(a)a.parentNode.removeChild(a);
	tgt = $('comment'+id);
	fAnswer=top.document.createElement("FORM");fAnswer.style.marginLeft="30px";fAnswer.id="answer";fAnswer.action="/video/docomment";fAnswer.target="stdfrm";fAnswer.method="post";
	if(top.user){fAnswer.appendChild(mkHidInput("user",top.user));};
	if(top.pId){fAnswer.appendChild(mkHidInput("gparentid",top.pId));};
	if(id){fAnswer.appendChild(mkHidInput("parentid",id));};
	fAnswer.appendChild(mkHidInput("id",-1));
	fAnswer.appendChild(mkHidInput("parenttype","2"));
	fAnswer.appendChild(mkHidInput("referrer",""));
	fAnswer.appendChild(mkHidInput("videoid",videoid));
	if(top._target){fAnswer.appendChild(mkHidInput("target",top._target));};
	if(top.subscribe){fAnswer.appendChild(mkHidInput("commentalert","on"));};
	cDiv=top.document.createElement("DIV");cDiv.className="comments";fAnswer.appendChild(cDiv);
	fDiv=top.document.createElement("DIV");fDiv.className="form";cDiv.appendChild(fDiv);
	faDiv=top.document.createElement("DIV");faDiv.className="form-area";fDiv.appendChild(faDiv);
	ul=top.document.createElement("UL");faDiv.appendChild(ul);	
	liTitle=top.document.createElement("LI");ul.appendChild(liTitle);
	h3=top.document.createElement("H3");liTitle.appendChild(h3);	h3.appendChild(top.document.createTextNode(top._fillComment));
	if (displayPseudo) {
	  labelPseudo=top.document.createElement("label");liTitle.appendChild(labelPseudo);labelPseudo.appendChild(top.document.createTextNode(top._fillPseudo));
	  inputPseudo=top.document.createElement("input");inputPseudo.name="pseudo";inputPseudo.size="45";inputPseudo.maxLength="45";inputPseudo.className="text";inputPseudo.value=pseudo;liTitle.appendChild(inputPseudo);
	}
	liTitlec=top.document.createElement("LI");ul.appendChild(liTitlec);
	labelTitle=top.document.createElement("label");liTitlec.appendChild(labelTitle);	labelTitle.appendChild(top.document.createTextNode(top._fillTitle));
	tinput=top.document.createElement("input");tinput.name="title";tinput.size="70";tinput.maxLength="70";tinput.className="text";liTitlec.appendChild(tinput);
	liText=top.document.createElement("LI");ul.appendChild(liText);
	labelText=top.document.createElement("label");liText.appendChild(labelText);labelText.appendChild(top.document.createTextNode(top._fillAnswer));
	tArea=top.document.createElement("TEXTAREA");tArea.name="comment";liText.appendChild(tArea);
	liValidate=top.document.createElement("LI");ul.appendChild(liValidate);
	labelCaptcha=top.document.createElement("label");liValidate.appendChild(labelCaptcha);labelCaptcha.appendChild(top.document.createTextNode(top._pleasefillcapt));
	bubbleDiv=top.document.createElement("DIV");bubbleDiv.className="inf";liValidate.appendChild(bubbleDiv);
	bubA=top.document.createElement("A");bubA.href="#";bubbleDiv.appendChild(bubA);
	bubPopup=top.document.createElement("DIV");bubPopup.className="pop-up";bubbleDiv.appendChild(bubPopup);
	bubTop=top.document.createElement("SPAN");bubTop.className="top-bg";bubTop.appendChild(top.document.createTextNode(" "));bubPopup.appendChild(bubTop);
	bubP=top.document.createElement("P");bubPopup.appendChild(bubP);
	bubTxt=top.document.createElement("SPAN");bubTxt.appendChild(top.document.createTextNode(top._humanControl));bubP.appendChild(bubTxt);
	bubBt=top.document.createElement("SPAN");bubBt.className="bt-bg";bubBt.appendChild(top.document.createTextNode(" "));bubPopup.appendChild(bubBt);
	captchaDiv=top.document.createElement("DIV");captchaDiv.className="pic";liValidate.appendChild(captchaDiv);
	captchaImg=top.document.createElement("IMG");captchaImg.src="/captcha";captchaImg.className="captimg";captchaImg.id="captimganswser";captchaDiv.appendChild(captchaImg);
	captchaInput=top.document.createElement("INPUT");captchaInput.className="text";captchaInput.type="text";captchaInput.name="captchacodes";captchaInput.value="";captchaInput.size=5;liValidate.appendChild(captchaInput);	
	liSave=top.document.createElement("LI");ul.appendChild(liSave);
	if(top._thxforparticipating != undefined){labelThx=top.document.createElement("label");liSave.appendChild(labelThx);labelThx.appendChild(top.document.createTextNode(top._thxforparticipating));};
	saveButton=top.document.createElement("INPUT");saveButton.type="submit";saveButton.className="submit";saveButton.value=top._saveComment;liSave.appendChild(saveButton);
	answerAlert=top.document.createElement("DIV");answerAlert.className="editoralert";answerAlert.id="bcAnswer";liSave.appendChild(answerAlert);
	iBefore=tgt.nextSibling;while(iBefore.nodeType!=1){iBefore=iBefore.nextSibling;};
	tgt.parentNode.insertBefore(fAnswer,iBefore);
}
