// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function Validationcheck(cur)
{
	var string1 = document.getElementById('video_file').value;
	var mp = document.getElementById('video_file1').value;
	var thumbnail = document.getElementById('thumbnail_file').value;
	var string2 = document.getElementById('video_title').value;
	//var iChars = "!@#$%^&*()+=-[]\\\/{}|\":<>?";
	var iChars = "!@#$%^*+=-[]\\\/{}|\"<>?";
	var space = /\S/;
	
	if(string1 == "" && mp == "" && thumbnail == "" && string2 == "") 
	{
		alert("Please Select FLV Video File. \n Please Select MP4 Video File. \n Please Select Thumbnail. \n Please Specify Video Title ")
		return false;
	}
	else if(string1 =="")
	{
		alert("Please Select FLV Video File")
		return false;
	}
	else if(mp =="")
	{
		alert("Please Select MP4 Video File")
		return false;
	}
	else if(thumbnail == "")
	{
		alert("Please Select Thumbnail")
		return false;
	}
	
	else if((string2 =="") || (!space.test(string2))) 
	{
	alert("Please Specify Video Title")
		return false;
	}
	
	else if((string2.length < 4) ||(string2.length > 50))
	{
		alert( "The Title should exist between 4-50 character length")
		return false;
	}
	for (var i = 0; i < string2.length; i++) {
         if (iChars.indexOf(string2.charAt(i)) != -1) {
           alert ("Video Title has special characters. \nThese are not allowed.\n");
         return false;
        }
    }	
    return true;
}

function validateEditForm(cur)
{
	var title = document.getElementById('title').value;
	var space = /\S/;
//	var iChars = "!@#$%^&*()+=-[]\\\/{}|\":<>?";
	var iChars = "!@#$%^*+=-[]\\\/{}|\"<>?";
	
	for (var i = 0; i < title.length; i++) {
		if (iChars.indexOf(title.charAt(i)) != -1) {
		    alert ("Video Title has special characters. \nThese are not allowed.\n");
			return false;
		}
	}
	if ((title == "") || (!space .test(title)))
	{
		alert("Please Specify Video Title");
		return false;
	}
	else if((title.length < 4) ||(title.length > 50))
	{
		alert( "The Title should exist between 4-50 character length")
		return false;
	}
	
	
	return true;
}

 function validateFormOnSubmit(cur)
 {
 	var old_pass=document.getElementById('old_password').value;
	var new_pass=document.getElementById('new_password').value;
    var	confirm_pass=document.getElementById('confirm_password').value;
	var alpha = /\D/;
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	var space = /\S/;
	if ((old_pass == "") && (new_pass == "") && (confirm_pass == "")) 
	{
		alert("Enter Current Password.\n Enter New Password.\n Enter Confirm New Password");
		return false;

	}
	else if ((old_pass == "") || (!space .test(old_pass)))
		{
		alert("Enter Current Password");
		return false;
	}
	else if ((new_pass == "") ||(!space .test(new_pass)))
	{
		alert("Enter New Password");
		return false;
	}
		else if((confirm_pass == "") || (!space .test(confirm_pass)))
    {
		alert("Enter Confirm New Password");
		return false;
	}	
	 	else if((new_pass.length < 4)||(new_pass.length >10 ))
    {
		alert("New Password should exist between 4-10 character length ")
	    return false;
	}
	else if((confirm_pass.length < 4)||(confirm_pass.length >10 ))
    {
		alert("Confirm New Password should exist between 4-10 character length ")
	    return false;
	}
	else if (new_pass != confirm_pass)
	{
		alert("Password does not match");
		return false;
	}	
		
	for (var i = 0; i < new_pass.length; i++) {
         if (iChars.indexOf(new_pass.charAt(i)) != -1) {
           alert ("New Password allows only alphabets");
         return false;
        }
    }	
	for (var i = 0; i < confirm_pass.length; i++) {
		if (iChars.indexOf(confirm_pass.charAt(i)) != -1) {
			alert("Confirm New Password allows only alphabets");
			return false;
		}
	}
	$('change_password_active').id = 'change_password_inactive'
	return true;
 }
  
  function Validationchecklogin(cur)
  {
  	var password=document.getElementById('password').value;
	var login=document.getElementById('login').value;
	if (login == "")
	{
		alert("Please enter Login");
		return false;
	}
	else if (password == "")
	{
		alert("Please enter Password");
		return false;
	}
	return true;
 	}
	
 function toggleChangePassword(){
    cp_div = document.getElementById('change_password_form');
	if(cp_div.style.display == "block"){
		cp_div.style.display = "none"
		$('change_password_active').id = 'change_password_inactive'
		
	}
	else{
		cp_div.style.display = "block"
		$('change_password_inactive').id = 'change_password_active'
	}
}

 function removeVideoElement(video_element){
	parentDiv = document.getElementById('edit_video');
	childDiv = document.getElementById(video_element);
	parentDiv.removeChild(childDiv);
 }

 function toggleVideoElementClass(video_id, video_class){
	document.getElementById(video_id).className = video_class;
 }

 function updateVideo(videoFile) {
	var so = new SWFObject("/players/video_autoplay.swf", "lg_video_player", "445", "370", "8", "#FFFFFF");
    so.addVariable("flvsrc", videoFile);
    so.addVariable("autoplay", true);
    so.write("lg_video_player_container");
 }
 
 function removeCategoryElement(category)
 { 
	childDiv = document.getElementById(category).innerHTML="";
 }
 
