// Globals
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
 function validateLength(oSrc, args)
  {
     if(args.Value != "")
        args.IsValid = (args.Value.length >= 6);
     else
        args.IsValid = true;
  }
//function to load the Flash Dynamically to avoid the problem of inactivation
function LoadFlash(width, height, filePath)
{
	// Version check based upon the values entered above in "Globals"
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
   
	// Check to see if the version meets the requirements for playback
	if (hasReqestedVersion) {
		// if we've detected an acceptable version
		// embed the Flash Content SWF when all tests are passed
		document.write('<object width='+width+' height='+height+' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">');
        document.write('<param name="URL" value="'+filePath+'">');    
        document.write('<param name="Quality" value="High">');
        document.write('<param name="Menu" value="-1">');
        document.write('<param name="Scale" value="ShowAll">');
        document.write('<param name="DeviceFont" value="0">');
        document.write('<param name="WMode" value="opaque">');
        document.write('<param name="Src" value="'+filePath+'">');
        document.write('<param name="Play" value="1">');
        document.write('<param name="EmbedMovie" value="0">');
        document.write('<param name="autoStart" value="-1">')
        document.write('<param name="AllowScriptAccess" value="always">')
        document.write('<embed src="'+filePath+'" quality="high" WMode="opaque" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width='+width+' height='+height+'> </embed>')    
        document.write('</object>');
	} else {  // flash is too old or we can't detect the plugin
	    // insert non-flash content
	    var alternateContent = '<font color="#8A8687">Flash plugin could not be detected or it is an older version. <a href="http://www.macromedia.com/go/getflash/" target="_blank">Please install/upgrade your Flash plugin.</a></font>';
	    
		document.write('<table width='+width+' height='+height+' cellpadding="0" cellspacing="0">');
        document.write('<tr>');
        document.write('<td>');
        document.write(alternateContent); 
        document.write('    </td>');
        document.write('  </tr>');
        document.write('</table>');
	}
    
}
function LoadMoview(url)
{

	// Version check based upon the values entered above in "Globals"
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
   
	// Check to see if the version meets the requirements for playback
	if (hasReqestedVersion) {
		// if we've detected an acceptable version
		// embed the Flash Content SWF when all tests are passed
        document.write('<object id="mp3player" align="left" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"  codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" height="20" width="250">');
        document.write('<param name="movie" value="../App_Themes/Grail/Images/mp3player.swf" />');
        document.write('<param name="menu" value="false" />');
        document.write('<param name="quality" value="high" />');
        document.write('<param name="wmode" value="transparent" />');
        document.write('<param name="devicefont" value="true" />');
        document.write('<param name="bgcolor" value="#ffffff" />');
        document.write('<param name="flashvars" value="file='+url+'"/>');
        document.write('<embed align="left" bgcolor="#ffffff" devicefont="true" flashvars="file='+url+'" height="20" menu="false" name="mp3player" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="../App_Themes/Grail/Images/mp3player.swf" type="application/x-shockwave-flash" width="250" wmode="transparent"></embed>');
        document.write('</object>');
	} else {  // flash is too old or we can't detect the plugin
	    // insert non-flash content
	    var alternateContent = '<font color="red"><strong>Flash plugin could not be detected or it is an older version. <a href="http://www.macromedia.com/go/getflash/" target="_blank">Please install/upgrade your Flash plugin.</a></strong></font>';
		document.write('<table width='+width+' height='+height+' cellpadding="0" cellspacing="0">');
        document.write('<tr>');
        document.write('<td>');
        document.write(alternateContent); 
        document.write('    </td>');
        document.write('  </tr>');
        document.write('</table>');
	}
    
}



function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; 
   }
}
function LTrim(s) {
    return s.replace(/^\s*/, "");
}

function RTrim(s) {
    return s.replace(/\s*$/, "");
}

function trim(s) {
    return RTrim(LTrim(s));
}
function checkIfFilethere(newFile,oldFile,overwrite){    
  
    try{
        var newFileName = document.getElementById(newFile);
        var oldFileName = document.getElementById(oldFile);    
        if(newFileName!=null && oldFileName!=null) {    
            newFileName = trim(newFileName.value);        
            oldFileName = trim(oldFileName+'');              
            if(oldFileName!='' && newFileName!='') {
                var index1 = newFileName.toLowerCase().lastIndexOf("\\");
                var index2 = oldFileName.toLowerCase().lastIndexOf("/");
              
                if(index1>0 && index2>0) {
                    newFileName = newFileName.substring(index1+1);
                    oldFileName = oldFileName.substring(index2+1);
                    newFileName = encodeURI(newFileName);  
                  
                    if(newFileName == oldFileName) {
                        var agree=confirm("File name: '"+decodeURI(newFileName)+"' already exists.  Do you want to replace existing file?");
                        if (agree){
                            document.getElementById(overwrite).value=1;
	                        return true ;
	                    }
                        else
	                        return false ;
                    }
                }
            }
        } 
        return true;
    }catch(e) {
    
        return true;
    }    
}

function checkIfImagethere(newFile,oldFile,overwrite){    
   
    try{
     var newFileName = document.getElementById(newFile);
        var oldFileName = document.getElementById(oldFile);    
        if(newFileName!=null && oldFileName!=null) {    
            newFileName = trim(newFileName.value);        
            oldFileName = trim(oldFileName.src+'');        
          
            if(oldFileName!='' && newFileName!='') {
                var index1 = newFileName.toLowerCase().lastIndexOf("\\");
                var index2 = oldFileName.toLowerCase().lastIndexOf("/");
              
                if(index1>0 && index2>0) {
                    newFileName = newFileName.substring(index1+1);
                    oldFileName = oldFileName.substring(index2+1);
                    newFileName = encodeURI(newFileName);  
                   
                    if(newFileName == oldFileName) {
                        var agree=confirm("File name: '"+decodeURI(newFileName)+"' already exists.  Do you want to replace existing file?");
                        if (agree){
                            document.getElementById(overwrite).value=1;
	                        return true ;
	                    }
                        else
	                        return false ;
                    }
                }
            }
        } 
        return true;
     }catch(e) {
        return true;
    }    
}

function confirmDelete()
{
    var agree=confirm("Are you sure you wish to delete the entry?");
    if (agree)
	    return true ;
    else
	    return false ;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function toggleTR(obj) {
    document.getElementById("TRurlID").style.display='none';
    document.getElementById("TRfileID").style.display='nove';
    if(this.value == 'file') {
        document.getElementById("TRfileID").style.display='';
    } else {
        document.getElementById("TRurlID").style.display='';
    }         
                
}

function popUp(URL, height, width) {

	factor = 1;
	if (height > screen.availHeight || width > screen.availWidth) {
		if (screen.availHeight/height > screen.availWidth/width) {
			factor = screen.availWidth/width;
		} else {
			factor = screen.availHeight/height;
		}
	}					
	height = Math.floor(height * factor);
	width = Math.floor(width * factor);
	window.open(URL, 'pic', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=' + width + ',height=' + height + ',left = 5,top = 5');
}

