﻿var rcVideoId;

function myWrite(txt) {
	document.write(txt);
}

function getFlashMovieObject(movieName) {
  if(window.player) {
    return window.document["player"];
  } else {
    return document.player;
  }
}

function play(vid) {
  rcVideoId = vid;
  getFlashMovieObject("player").SetVariable("vid", vid);
}

function star2text(star) {
	var txt = "";
	switch(star) {
		case 1:
		txt = "Фигня";
		break;
		case 2:
		txt = "Так себе";
		break;
		case 3: 
		txt = "Смотреть можно";
		break;
		case 4:
		txt = "Понравилось";
		break;
		case 5:
		txt = "Супер!";
		break;
	}
	document.getElementById("s2t").innerHTML = txt;
}

function clearStar2text() {
	document.getElementById("s2t").innerHTML = "";
}

function getControl_OLD() {
  var sc = "";
  sc+="<div style='float:left; width:100px; height:12px;'>Ваша оценка</div> <div id='all_stars' style='float:left; width:60px; height:12px;'><ul class='star-rating'>";
  sc+="<li><a onmouseover='star2text(1);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(1)' class='one-star'>1</a></li>";
  sc+="<li><a onmouseover='star2text(2);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(2)' class='two-stars'>2</a></li>";
  sc+="<li><a onmouseover='star2text(3);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(3)' class='three-stars'>3</a></li>";
  sc+="<li><a onmouseover='star2text(4);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(4)' class='four-stars'>4</a></li>";
  sc+="<li><a onmouseover='star2text(5);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(5)' class='five-stars'>5</a></li>";
  sc+="</ul></div><div id='s2t' style='width:100px; height:12px; padding-left: 5px;'></div>";
  return sc;
}

function getControl() {
  var sc = "";
	sc+="<div style='float:left; width:160px; text-align:right; margin-right: 5px; height:12px; border: 0px solid black;'>Ваша оценка</div>";
	sc+="<div id='all_stars' style='float:left; width:60px; height:12px; border: 0px solid black;'>";
	sc+="<ul class='star-rating'>";
	sc+="<li><a onmouseover='star2text(1);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(1)' class='one-star'>1</a></li>";
	sc+="<li><a onmouseover='star2text(2);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(2)' class='two-stars'>2</a></li>";
	sc+="<li><a onmouseover='star2text(3);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(3)' class='three-stars'>3</a></li>";
	sc+="<li><a onmouseover='star2text(4);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(4)' class='four-stars'>4</a></li>";
	sc+="<li><a onmouseover='star2text(5);' onmouseout='clearStar2text();' href='javascript:" + fPrefix + "rate(5)' class='five-stars'>5</a></li>";
	sc+="</ul>";
	sc+="</div>";
	sc+="<div id='s2t' style='text-align: left; float:left; width:150px; height:12px; margin-left: 5px; border: 0px solid black;'></div>";
	return sc;
}
		
function isIE() {
  return (navigator.appVersion.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Opera") < 0);
}

function gradStarControl(val) {
	if(val<=100) {
		if(isIE()) {
			document.getElementById("rateControlDiv").style.filter = "alpha(opacity=" + val + ")";
		} else {
			document.getElementById("rateControlDiv").style.opacity = val/100;
		}
		val+=10;
		setTimeout("gradStarControl(" + val + ")", 100); 		
	}
}

function showStarControl(userRank) {
		if(document.getElementById("rateControlDiv")) {
			
			if(isIE()) {
				document.getElementById("rateControlDiv").style.filter = "alpha(opacity=0)";
			} else {
				document.getElementById("rateControlDiv").style.opacity = "0";
			}
			
		  if(userRank > 0) {
		    document.getElementById("rateControlDiv").innerHTML = getControl();
		    showStarsImage(userRank);
		  } else {
		    document.getElementById("rateControlDiv").innerHTML = getControl();
		  }
		  
		  gradStarControl(0);
	  }
}

function showRateControl(userRank) {
	if(isIE()) {
		if(document.readyState == "complete") {
			showStarControl(userRank);
	  } else {
	  	setTimeout("showRateControl(" + userRank + ")", 200);
	  }
  } else {
  	showStarControl(userRank);
  }
}

function getHTTPObject() {
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
     try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (E) {
        xmlhttp = false;
     }
  }

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function _rate(stars) {
	txt = "Для голосования требуется регистрация, займет секунд 10. Что делать будем?"
	answer = confirm(txt);
	if(answer) {
  	register();
  }
}

function _comment() {
	txt = "Для комментариев требуется регистрация, займет секунд 10. Что делать будем?"
	answer = confirm(txt);
	if(answer) {
		register();
	}
}

function login() {
  document.location.href="/login";
}

function register() {
	document.location.href = "/register";
}

function spread() {
  top.document.getElementById("rightColumn").innerHTML = '<iframe src="/rc/siteEmail.da" width="330" frameborder="0" scrolling="no" height="250"></iframe>';
}

function clearSiteTo(obj) {
	if(obj.value.indexOf("Emails") == 0) {
		obj.value = "";
	}
}


function rate(stars) {
  d = new Date();
  var xmlHttpObj = getHTTPObject();
  xmlHttpObj.open("GET", "/rc/rate.da?vid=" + rcVideoId + "&stars=" + stars + "&ts=" + d.getTime() , true);
  if (xmlHttpObj.readyState == 1) {
    xmlHttpObj.send(null);
  }
  showStarsImage(stars);
  clearStar2text();
}

function showStarsImage(stars) {
  //document.getElementById("rateControlDiv").style.paddingBottom = "1px";
  var txt = '';//'<span style="padding-left:5px;">';
  es = 5 - stars;
  for(var i=0; i<stars; i++) {
  	txt += '<img src="/imgs/stars/star.gif">';
  }
  for(var i=0; i<es; i++) {
  	txt += '<img src="/imgs/stars/stare.gif">';
  }
//  txt += '</span>';
  document.getElementById("all_stars").innerHTML = txt;
//  star2text(stars);
}

function rsthp() {
  var xmlHttpObj = getHTTPObject();
  xmlHttpObj.open("GET", "/rc?genre=%D0%9C%D1%83%D0%B7%D1%8B%D0%BA%D0%B0&category=%D0%9A%D0%BB%D0%B8%D0%BF%D1%8B" , true);
  if (xmlHttpObj.readyState == 1) {
    xmlHttpObj.send(null);
  }
}

function BookmarkUs() {
  var title = "RussianClip.com"; 
  var url = "http://www.russianclip.com";
  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url, "");
  } else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title); 
  } else if(window.opera && window.print) { // Opera Hotlist
    return true; 
  }
}

function spreadTheWord() { 
  top.document.getElementById("rightColumnContent").innerHTML = '<iframe src="/rc/siteEmail.da" width="330" frameborder="0" scrolling="no" height="250"></iframe>';
}

function previewSiteEmail() {
  window.open("/rc/siteEmail.da?preview=true", "_blank", "height=400,innerHeight=400,width=520,innerWidth=520,left=20,screenX=20,top=40,screenY=40,scrollbars,dependent");
}

function navhover_on(obj) {
  obj.style.background = "url('/rc/imgs/btnbg.gif') no-repeat";
}

function navhover120_on(obj) {
  obj.style.background = "url('/rc/imgs/btnbg120.gif') no-repeat";
}

function navhover_off(obj) {
  obj.style.background = "";
}