//------------------Steraming Server --------------------------------------------------
//Set this var while using a Streaming Server. If the media server is the same
//as the http one, set this var to ''.
//StreamingMediaPath = 'mms://194.187.78.141/';
StreamingMediaPath = "rtsp://www.si-sv2565.com/qenglish/";
//StreamingMediaPath = "";

// two arrays for different media servers. The first one contains urls of the partners that need to
// get different servers, the second one - the server paths
var SpecialUrl = new Array();
SpecialUrl[0] = "elit.qgroup4u.com";
var SpecialStreamingMediaPath = new Array();
SpecialStreamingMediaPath[0] = "rtsp://79.171.23.237/qenglish/";

/******************************************************************************************
function PathForStreaming(CurrSoundPath)

    This function gets a path and change it to the streaming server path if needed and if
    this path contins "http://"
    
    streaming server is to be used ONLY on video, so other function does the change
    this one, however, returns input path with no changes
******************************************************************************************/
function GetInstallationPath(FullMediaPath,FindString,MediaSourceDial)
{

var MediaSourceDialInternet;

    try
	    {
	    
	    // parent.parent.MediaSourceDialInternet gets from ScoLauncher and if the value 
	    // is  not "D"(Dial) return the FullMediaPath
	     if(MediaSourceDial !=null)
	        MediaSourceDialInternet=MediaSourceDial; 
	     else if(parent.parent.parent.MediaSourceDialInternet)  
	       MediaSourceDialInternet=parent.parent.parent.MediaSourceDialInternet; 
	    else if(top.opener.parent.parent.parent.MediaSourceDialInternet)
	            MediaSourceDialInternet=top.opener.parent.parent.parent.MediaSourceDialInternet; 
	    else if(top.parent.MediaSourceDialInternet)
	            MediaSourceDialInternet=top.parent.MediaSourceDialInternet;
	            
	    // if  we dont  find the MediaSourceDialInternet we return the FullMediaPath with out handle dial solution
	    else   
	       return(FullMediaPath);
	              
	   
	   if(MediaSourceDialInternet!="D")
	       return(FullMediaPath);
	    
            var sWorkingPath,s ="";
            var wsh = new ActiveXObject("WScript.Shell");
            var key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\QGROUP\\QMediaCD\\DATAPATH";
            var svalue = wsh.RegRead(key);
            var lpos;
            if(svalue.length>0)
            {
                lpos = FullMediaPath.indexOf(FindString);
                s= svalue;
               // s = s + "\\" + FullMediaPath.substring(lpos);
               s = s + FullMediaPath.substring(lpos);
                while (lpos > 0)
                {
                    lpos = s.indexOf("/");
                    s = s.replace("/","\\")
                }
                try
                    {
                        fso = new ActiveXObject("Scripting.FileSystemObject");
                        if(s.indexOf(".")>0)
                            f1 = fso.GetFile(s);
                        else
                            f1 = fso.GetFolder(s);
                        return(s);
                    }
                catch(e)
		            {	
			            alert("The Selected Course Was Not Found Please Reinstall The Q Group CD.");
			            return(FullMediaPath); 
		            }
		    
		    }
		    else return(FullMediaPath);
	    }
    catch(e)
	{	
	   return(FullMediaPath);
	}
}

function GetCDDrive(FullMediaPath)
{
    try
		{
		    var fso, d, s ="", lChar, i, fl;
            fso = new ActiveXObject("Scripting.FileSystemObject");
            for(i=97;i<=122;i++)
            {
                lChar = String.fromCharCode(i);
                try
                {
                    d = fso.GetDrive(fso.GetDriveName(lChar +":"));
                    if(d.DriveType == 4) 
                    {
                        s = d.DriveLetter + ":";
                        try
                        {
                            f1 = fso.GetFile(s + "\QData.inf");
                            var lpos;
                            lpos = FullMediaPath.indexOf("SCOs");
                            s = s + "\\" + FullMediaPath.substring(lpos);
                            while (lpos > 0)
                            {
                                lpos = s.indexOf("/");
                                s = s.replace("/","\\")
                            }
                        }
                        catch(e)
		                {	
        			        s= "";   
		                }
                        break;
                    }
                }
                catch(e)
		        {	
			        
		        }
            }
		}
		catch(e)
		{	
			return
		}
		return(s);
        fso	= null;
}
function PathForStreaming(CurrSoundPath){

    var sPathType;
    if(CurrSoundPath.indexOf("SCOs")>0)
        sPathType= "SCOs";
    else if(CurrSoundPath.indexOf("Tools")>0)
        sPathType= "Tools"; 
    else return CurrSoundPath; 
    var localPath=GetInstallationPath(CurrSoundPath, sPathType);
    if(localPath.length>0)
        return localPath;
    else
        return CurrSoundPath;
}

function PathForVideoStreaming(CurrSoundPath){

    for (i=0;i<SpecialUrl.length;i++)
    {
        if (document.location.href.indexOf(SpecialUrl[i]) > -1)
            return GetMediaPath(CurrSoundPath, SpecialStreamingMediaPath[i]);
    }
    
    return GetMediaPath(CurrSoundPath, StreamingMediaPath);
}

function GetMediaPath(CurrSoundPath, StreamingPath)
{
    if (StreamingPath!=""){

    //if there is a Streaming Server

              if(CurrSoundPath.indexOf("http://")==0){

                      var templocation=CurrSoundPath.substring(7,CurrSoundPath.length);

                      templocation=templocation.substring(templocation.indexOf("/")+1,templocation.length);

                      CurrSoundPath=StreamingPath+templocation;

              }
    }

    return CurrSoundPath;
}

