﻿          // JScript File
       
function SaveVideos()
{
     
   var status = ValidateAddVideosForm();
    
   //if validation of any field comes out to be invalid then display error message 
   if(status == false)
   {      
        var registrationErrorsDiv = document.getElementById("WarningMsgs_RegistrationErrors");

        registrationErrorsDiv.style.display = "block";
        //errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
        document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
 
        registrationErrorsDiv.innerHTML = errors;        
        return false;   
    }
    else 
    {
        return true;
    }      
}


function ValidateAddVideosForm()
{
    
    errors = "";
    
    var status = true;
    mandatoryFieldsErrorFlag=false;
    
    // validating Title field
    var varTemp = document.getElementById("txtTitle");  
    var alertName = " Title ";
    var isMandatory = 'True';
    if(bValidate(varTemp, "General" ,isMandatory , alertName) != true)
        {   
          varTemp.focus();
		  status = false;
		  return false;    
        }
   
    // validating Description field           
    varTemp = document.getElementById("txtDescription");  
    alertName = " Description ";
    isMandatory = 'True'; 
   if(bValidate(varTemp,"",isMandatory , alertName) != true)
        { 
          varTemp.focus();
		  status = false;
		  return false;    
        }
   
   //validating uploading filename field
   varTemp = document.getElementById("FileUploadVideo");
   alertName = " Video";
   var isMandatory = 'True'; 
   if(varTemp!= null && varTemp!= "")
   {
      //Get the filename
      varTemp = varTemp.value;
      if(varTemp!= null && varTemp!= "")
      {
         //Get extension of filename
         var extension =   varTemp.substring(varTemp.length-3);
      
       //  if(extension == "flv" || extension == "swf" || extension == "peg" || extension == "FLV")
         if(extension == "flv" || extension == "FLV")     
         {  }
         else
         {
            errors +="Only flv file type is allowed for " +alertName+ '.<br/>'; 
            status = false;
		    return false;    
         }
      }
      else
      {     //if filename is empty in uploading file field
            if(mandatoryFieldsErrorFlag == false) 
			{
				errors +="Please select file for upload."+'<br/>';  
				
		        mandatoryFieldsErrorFlag = true;
		    }
		    status = false;
		    return false;    
      }
   }   
}

function DisplayVideo()
{
  
    var filename=document.getElementById("CurrentVideo").value;
   
   //document.videoPlayer.SetVariable("VideoFileName","../../Videos/Cycling.FLV");
   document.videoPlayer.SetVariable("VideoFileName","../../Videos/" + filename);
}

function DisplaySelectedVideo(videoid,filename)
{
     
			
					
    
     document.getElementById("CurrentVideo").value = filename;
    document.videoPlayer.SetVariable("VideoFileName","../../Videos/" + filename);
}


function DeleteVideoRecordConfirmation(RecordId,btnId)
{
    //return confirm('Would you like to delete this record?');
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidRecordId").value=RecordId;
    ShowConfirmBox('Would you like to delete this record?');
    return false;
}

function DisplayMessage(msg)
{
    var msg="Congratulations! Video has been successfully added.";
    
    ShowMessageBox(msg);
}
function HandleException()
 {
      if (!document.all)
       {
            window.onbeforeunload = function()
             {
               Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
              }
      }
  }

  function endRequest(sender, e)
  {
       var err = e.get_error();
        if (err)
        {
              if (err.name == "Sys.WebForms.PageRequestManagerServerErrorException") 
              {
                e.set_errorHandled(true);
              }
              if (err.name == "Sys.WebForms.PageRequestManagerParserErrorException") 
              {
                e.set_errorHandled(true);
              }
        }
  }
