// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
function sampleFlaMovie_DoFSCommand(command, args) {
//  alert("this fired");
  var sampleFlaMovieObj = InternetExplorer ? sampleFlaMovie : document.sampleFlaMovie;
  //
  if (args != undefined){
		vid_index = args;
		div_id = "video_" + args + "_view_count";

		input = $(div_id);
		if (input != undefined){
			count = parseInt(input.value);
			input.value = count + 1;
		}
	}
  //
}
// Hook for Internet Explorer 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) 
{
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub sampleFlaMovie_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call sampleFlaMovie_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}

var vid_index = 0;
function updateViewCount(index) {
    if (index != undefined){
		vid_index = index;
		div_id = "video_" + index + "_view_count";

		input = $(div_id);
		if (input != undefined){
			count = parseInt(input.value);
			input.value = count + 1;
		}
	}
}

function getViewCount() {
	vid_index = 0;
	div_id1 = "video_" + vid_index + "_view_count";
	vid_index = 1;
	div_id2 = "video_" + vid_index + "_view_count";
	input1 = $(div_id1);
	input2 = $(div_id2);
	count1 = 0;
	count2 = 0;
	if (input1){
		count1 = parseInt(input1.value);
		input1.value = 0;
	}
	if (input1){
		count2 = parseInt(input2.value);
		input2.value = 0;
	}
	return "user_view_count[" + count1 + "]&pro_view_count[" + count2 + "]";
}
		
function add_video_to_text(index) {
    if (index != undefined){
		input = $('post_article');
		change = ' :Video:' + index + ': ';
		insertAtCursor( input, change);
	}
}

function toggle_videos(div, offsetDiv){
	trigger = $(offsetDiv);
	display = $(div);
	var posX = (trigger.offsetLeft / 1) + (trigger.offsetWidth / 1) + 15;

	display.style.position = 'absolute';
	display.style.left = posX + "px";
	display.style.bottom = "20px";
	Element.toggle(div);
}

function clear_field(fieldID){
	if (fieldID != undefined){
		input = $(fieldID);
		input.value = '';
	}
}
		
function insertAtCursor(myField, myValue)
{
	if (document.selection)
    {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	else if (myField.selectionStart || myField.selectionStart == '0')
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	}
	else
	{
		myField.value += myValue;
	}
}

function update_field(fieldID, myValue){
	if (fieldID != undefined){
		input = document.getElementById(fieldID);
		input.value = myValue;
	}
}

function jumpScroll(x, y)
{
    window.scroll(x,y);
}

function updateRatingGraphic(div_prefix, rating)
{
	for (var i = 1; i <= 5; i++)
	{
		element = $(div_prefix + i);
		if (i <= rating){
			element.src = "/images/starON.png";
		}
		else{
			element.src = "/images/starOFF.png";
		}
   }
}