// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;

var recordingName='';
var isSaved = 0;

var message="Your video message is not saved. Click OK to save your recording.";  

function ConfirmClose(e)  
{  
     var evtobj=window.event? event : e;  

	
	if(evtobj == e)  
       	{  
         	//firefox   
           		if (!evtobj.clientY)  
           		{  
                 	evtobj.returnValue = message;  
			//doClose();
          	 	}  
       	}  
       	else  
       	{  
       	//IE  
         		if (evtobj.clientY < 0)  
           		{  
                 	evtobj.returnValue = message;  
			//doClose();
           		}  
       	} 
	 
	
	
} 

function doClose()
{

	if( recordingName != '' && isSaved == 0)
	{
		if(confirm(message,"Exit Recorder?"))
		{
		getFlashMovie("recorder").saveBeforeExit();	
		self.close();
		}
		else
		{
		doCleanUp();
		}
	}
	
} 


function doCleanUp()
{
	getFlashMovie("recorder").flashCleanUp();
}


function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}

function randomFileName() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 6;
	var prefix = randomFileName.arguments[0];
	//var randomstring = prefix + "_";
	var randomstring = "";
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}


function saveRecording() {
  // alert("hi test");  
	recordingName = saveRecording.arguments[0];                      
	isSaved = 1;
	window.location="saveVideoFileName.aspx?FName="+recordingName;
	
	
   
	
	//document.getElementById('ViewVideo').style.display = 'block';
//		jQuery('#layer').hide();
//		jQuery('#fixme').hide();
		//jQuery('#ViewVideo').show();

	
	
}


//function saveRecording() {
//    //alert("hii");
//   // document.body.removeChild(document.getElementById('layer'));
//    //document.body.removeChild(document.getElementById('fixme'));
//	recordingName = saveRecording.arguments[0];
//	isSaved = 1;

//	//$.get("saveVideoFileName.aspx", { "FName": recordingName},function(data){
//	//parent.location.reload();
//	    //self.close();
//	    //$("#cls").click();
//	    window.parent.location ='';
//	} );	
//	window.location="saveVideoFileName.aspx?FName="+recordingName;    

//	alert("hi");
//}

function startRecording() {
	recordingName = startRecording.arguments[0];
}

function handleVideoEvent(){
	event = handleVideoEvent.arguments[0];
	switch(event)
	{
	 case 'NO_CAMERA':
		break;
	 case 'DENY_CAMERA_ACCESS':
		break;
	 case 'NO_MIC':
		break;
	 case 'NO_CAMERA_AND_MIC':
		 document.write("No Camera and Mic found Cannot Record");
		 break;
	 default:
		break;
	}
}

function hideRecorder()
{
	document.getElementById('recorderDiv').style.display = "none";
}

function showRecorder() {

if(document.getElementById('recorderDiv').style.display == "none")
{
document.getElementById('recorderDiv').style.display = "block";
}
else
{
	document.getElementById('recorderDiv').style.display = "none";
} 
}


function init() {

// Version check for the Flash Player that has the ability to start Video Recorder (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = 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;

	AC_FL_RunContent(
		"src", "playerProductInstall",
		"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
		"width", "320",
		"height", "270",
		"align", "middle",
		"id", "recorder",
		"quality", "high",
		"bgcolor", "#ffffff",
		"name", "recorder",
		"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
	
AC_FL_RunContent(
			"src", "recorder",
			"width", "320",
			"height", "270",
			"align", "middle",
			"id", "recorder",
			"quality", "high",
			"bgcolor", "#ffffff",
			"name", "recorder",
			"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 = 'Could not lauch video recorder.'
  	+ 'This content requires the Adobe Flash Player. '
   	+ '<a href=http://www.adobe.com/go/getflash/ target="_blank">Get Flash</a>';
    document.write(alternateContent);  // insert non-flash content
  }
}


