// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 28;

function getFlashChat(rootLink, flashvars) {
  // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
  var hasProductInstall = top.DetectFlashVer(6, 0, 65);

  // Version check based upon the values defined in globals
  var hasRequestedVersion = top.DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

  if ( hasProductInstall && !hasRequestedVersion ) {
    // DO NOT MODIFY THE FOLLOWING FOUR LINES
    // Location visited after installation is complete if installation is required
    var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
    var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;

    top.AC_FL_RunContent(
    "src", rootLink+"/res/playerProductInstall",
    "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
    "width", "100%",
    "height", "100%",
    "align", "middle",
    "id", "roundChat",
    "quality", "high",
    "bgcolor", "#ffffff",
    "name", "roundChat",
    "flashvars", "values="+flashvars,
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer"
    );
  } else if (hasRequestedVersion) {
    // if we've detected an acceptable version
    // embed the Flash Content SWF when all tests are passed
    top.AC_FL_RunContent(
    "src", rootLink+"/res/roundChat",
    "width", "100%",
    "height", "100%",
    "align", "middle",
    "id", "roundChat",
    "quality", "high",
    "bgcolor", "#ffffff",
    "name", "roundChat",
    "flashvars", "values="+flashvars,
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer"
    );
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = 'Alternate HTML content should be placed here. '
    + 'This content requires the Adobe Flash Player. '
    + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
    window.document.getElementById("flash_chat").innerHTML =alternateContent;// insert non-flash content
  }
}

function showSnapshot(tmpRes) {
  //alert("showSnapshot: " + tmpRes);
  xajax_snapshot_showPicture(tmpRes);
}
/***************
* activates send button when resource was successfully imported
*/
function videoReady(id) {
  xajax_showVideoCommentsForm(id);
}
var containerId = "video_view_container";

function checkVersion(requiredMajorVersion, requiredMinorVersion, requiredRevision, containerId, flashVars, toCheck, swf, root, objW, objH) {
  var hasReqestedVersion;
  var containerVideo = window.document.getElementById(containerId);
  if (toCheck==1) hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  else hasReqestedVersion = true;
  //alert("required: " + hasReqestedVersion);
  if (hasReqestedVersion) {
    // if we've detected an acceptable version
    // embed the Flash Content SWF when all tests are passed
    var object = AC_FL_RunContentReturn(
    "wmode", "transparent",
    "src", root+"/"+swf,
    "width", objW,
    "height", objH,
    "align", "middle",
    "id", swf,
    "quality", "high",
    "bgcolor", "#000000",
    "name", swf,
    "allowScriptAccess","always",
    "type", "application/x-shockwave-flash",
    'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
    "pluginspage", "http://www.adobe.com/go/getflashplayer",
    'flashVars', ""+flashVars+"",
    'allowFullScreen', 'true',
    'containerId', ""+containerId+""
    );
    //containerVideo.innerHTML = object;
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = "<div align='center' style='height:"+objH+"px;width:"+objW+"px;background-color:#000000;padding-top:50px;color:#FFFFFF;align:center;'>"
    + "This content requires the Adobe Flash Player " + requiredMajorVersion + "." + requiredMinorVersion + "." + requiredRevision + " (or later).<br>"
    + "<a href='http://www.adobe.com/go/getflash/' target='_blank' class='cams'>Get Flash</a></div>"
    containerVideo.innerHTML = alternateContent;  // insert non-flash content
  }
}

function showExternalChatIframe() {
  var domain = window.document.getElementById('ext_domain');
  var w = window.document.getElementById('ext_w');
  var bkg = window.document.getElementById('ext_bkg');
  var ext_title = window.document.getElementById('ext_title');
  var ext_desc = window.document.getElementById('ext_desc');
  var ext_name = window.document.getElementById('ext_name');
  var ext_email = window.document.getElementById('ext_email');
  
  if(domain.value != "" && w.value != "" && bkg.value != "" && ext_title.value != "" && ext_desc.value != "" && ext_name.value != "" && ext_email.value != "") {
    top.xajax_showExternalChatIframe(domain.value, w.value, bkg.value, ext_title.value, ext_desc.value, ext_name.value, ext_email.value);
  } else {
    var stat = window.document.getElementById('ext_iframe');
    stat.innerHTML = "Specify domain, width, background, site title, site description, your name & your email.";
  }
}

var d=window.document;
var Columns=16;
function drawPalette(p){
	d.getElementById("palette").innerHTML = "";
  s=d.getElementById(p).value;
  a=s.match(/#(\w{6})/ig);    //for  hex- #CCCCCC,#999999,#666666,...
  j=0;s2='<table bgColor=black>';
  while(a[j]){
  	s2+='<tr>';
    for(i=0;i<Columns;i++)if(a[j])s2+='<td'
    	+'  style=\"font-size:4px;cursor:pointer;background-color:'+a[j++]+';\" width=\"4\" height=\"5\" onclick=\"top.selectColor(this);\"></td>';
      s2+='</tr>';
  }
  //d.body.innerHTML+=s2+'</table>';
   d.getElementById("palette").innerHTML += s2+'</table>';
   d.getElementById("palette").style.display = "";
}
function hidePalette() {
  d.getElementById("palette").style.display = "none";
}
// selectColor
function selectColor(div) {
	 var color = div.style.backgroundColor;
	 //alert("color: "+color+"div: "+div);
	 color = rgbNormal(color);
	 window.document.getElementById("ext_bkg").value = color;
	 d.getElementById("palette").style.display = "none";
}

function rgbNormal(color) {
	 color = color.toString();
	 var re = /rgb\((.*?)\)/i;
	 if(re.test(color)) {
		 compose = RegExp.$1.split(",");
		 var hex = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'];
		 var result = "#";
		 for (var i = 0; i < compose.length; i++) {
			 rgb = parseInt(compose[i]);
			 result += hex[parseInt(rgb / 16)] + hex[rgb % 16];
		 }
		 return result;
	 } else return color;
}
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
function sendNotActivityMails(root_url) {
  var container = window.document.getElementById('mail_sender_cont');
  container.innerHTML = "<img src='"+root_url+"/images/ajax-loader.gif' alt='Loader img' />";
  top.xajax_sendNotActivityMails();
}
function nextSendNotActivityMails(num) {
  top.xajax_sendNotActivityMails(num);
}
function saveFakeStream() {
  var name = window.document.getElementById('fake_name');
  var msg = window.document.getElementById('fake_msg');
  var id = window.document.getElementById('fake_video_id');
  var res = window.document.getElementById('snapshot_result');
  
  if(name.value != "" && msg.value != "" && id.value != "") {
    top.xajax_saveFakeStream(name.value, msg.value, id.value);
  } else {
    res.innerHTML = "Specify name & your chat message.";
  }
}
function addNewVideoId(id) {
  window.document.getElementById('fake_video_id').value = id;
  //newVideoId.value = id;
}

function saveDonation() {
  var msg = window.document.getElementById('don_msg');
  var url = window.document.getElementById('don_url');
  var res = window.document.getElementById('snapshot_result');

  if(msg.value != "" && url.value != "") {
    top.xajax_saveDonation(msg.value, url.value);
  } else {
    res.innerHTML = "Specify name & your chat message.";
  }
}

var save_button_ready =1;
var count =15;
var t;
function clearCommentForm(){

 save_button_ready = 0;
 window.document.getElementById('save_btn').disabled = true;
 window.document.getElementById('comment').value = "";
  t = setInterval(countDown, 1000);
}
function countDown(){
 if(count>0) window.document.getElementById('save_btn').value="Saved. Wait "+count;
  else {
    window.document.getElementById('save_btn').disabled = false;
    window.document.getElementById('save_btn').value="Save";
    count=15;
    save_button_ready =1;
    clearInterval(t);
 }
 count--;
}
function mgr(obj) {
  var frm = document.forms['send_mail'];
  var mid = frm.elements['m_mid'];
  if(obj.value == '-1') {
    mid.disabled = true;
    mid.style.background = '#F1F1ED';
  } else {
    mid.disabled = false;
    mid.style.background = '';
  }
}

function subm(obj) {
  top.xajax_contuctUsSendMail(top.xajax.getFormValues('send_mail'));
}