﻿// JScript File

function Redirect(url, openWindow, windowName) 
{
   try
   {
     if(openWindow == 'true')
     {
        launchApplication(url, windowName);
     
//         var taskBarHeight = 35;
//         newWin = window.open(url, 'YouiSecure','scrollbars=yes,resizable=yes,directories=no,status=yes,location=no,toolbar=no,titlebar=0,screenX=0,screenY=0,left=0,top=0,menubar=yes,hotkeys=no'); 
//         
//         /* Maximise as much as possible */
//         newWin.moveTo(0,0); 
//         newWin.resizeTo(screen.width,(screen.height - taskBarHeight)); 
//         newWin.focus();
//         return newWin;
     }
     else
     {
        window.location.href = url;
     }
   }
   catch (ex)
   {
      //alert("Unable to open up URL using Redirect() method.\n"+ex.message);
   }
}

function launchApplication(l_url, l_windowName)
{  
    //alert("l_url = " + l_url);
    //alert("l_windowName = " + l_windowName);
    //alert("launchApplication = " + launchApplication);
    if(typeof launchApplication.winrefs == 'undefined' )  
    {    
        launchApplication.winrefs = {};  
        //alert("launchApplication.winRefs = " + launchApplication.winrefs);        
    }  
    //alert("launchApplication.winrefs[l_windowName] = " + launchApplication.winrefs[l_windowName]);
    if ( typeof launchApplication.winrefs[l_windowName] == 'undefined' || launchApplication.winrefs[l_windowName].closed )  
    {    
        var l_width = screen.availWidth;    
        var l_height = screen.availHeight;    
        var l_params =  'status=1' + 
                        ',resizable=1' +
                        ',scrollbars=1' + 
                        ',width=' + l_width + 
                        ',height=' + l_height + 
                        ',left=0' + 
                        ',top=0';
       
       // alert("width= " + l_width);
       // alert("height= " + l_height);
       // alert("params= " + l_params);
       launchApplication.winrefs[l_windowName] = window.open(l_url, l_windowName, l_params);    
       launchApplication.winrefs[l_windowName].moveTo(0,0);    
       launchApplication.winrefs[l_windowName].resizeTo(l_width, l_height);  
     } 
     else 
     { 
        //alert("already open");  
        alert("We have noticed you already have a quote open.  Please complete or close your current quote before starting a new quote");
        launchApplication.winrefs[l_windowName].focus()  
     }
}

function RedirectModal(url, openWindow,width,height,scrollbars) 
{
   try
   {
     if(openWindow == 'true')
     {
         newWin = window.open(url, "",'scrollbars=' + scrollbars + ',resizable=no,directories=no,status=yes,location=no,toolbar=no,titlebar=0,screenX=0,screenY=0,left=0,top=0,menubar=yes,hotkeys=no,width=' + width + ',height=' + height); 
                  
         return newWin;
     }
     else
     {
        window.location.href = url;
     }
   }
   catch (ex)
   {
      alert("Unable to open up URL using RedirectModal() method.\n"+ex.message);
   }
}