﻿// JScript File
var framesetPage = "default.aspx";

var currPage = justTheFilename(self.location.pathname);

if (top.location == self.location && framesetPage != currPage && currPage != ""){

    var pathname = self.location.pathname;
    pathname = pathname.toLowerCase();
    
    if (pathname.indexOf("/foodbookers/") >= 0) {
        self.location.replace("/foodbookers/" + framesetPage + "?" + currPage + "?" + document.location.search);
    }
    
    else self.location.replace("/" + framesetPage + "?" + currPage + "?" + document.location.search);
    
    //self.location.replace("/foodbookers/myplacetimes/" + framesetPage + "?" + currPage + "?" + document.location.search);
}

window.onload = chgFrame;

function chgFrame(){

    if (parent.location == self.location && document.location.search){    
    
        var linkURL = justTheFilename(document.location.search);
        var contentWin = document.getElementById("content").contentWindow;
        var currURL = justTheFilename(contentWin.location.pathname);
        
        if (currURL != linkURL){
        
            contentWin.location.replace(linkURL);
        }
    }
    

}

function justTheFilename(thisFile){
    
    var thisFile2 = thisFile.toLowerCase();
    
    if (thisFile2.indexOf("??") >= 0){
        thisFile2 = thisFile2.substring(0, thisFile2.lastIndexOf("??"));
    }
    
    if (thisFile2.indexOf("myplace/") > - 1){
    
        thisFile = thisFile.substring(thisFile2.indexOf("myplace/")); 
    } 
        
    else if (thisFile2.indexOf("myuser/") > - 1){
    
        thisFile = thisFile.substring(thisFile2.indexOf("myuser/"));
    }
    
    else if (thisFile2.indexOf("management/") > - 1){
    
        thisFile = thisFile.substring(thisFile2.indexOf("management/"));
    }
    
    else if (thisFile2.indexOf("qlist/") > - 1){
    
        thisFile = thisFile.substring(thisFile2.indexOf("qlist/"));
    }
    
    else if (thisFile2.indexOf("/") > - 1){
        thisFile = thisFile.substring(thisFile2.lastIndexOf("/")+ 1);    
    }
    
    if (thisFile.indexOf("?") == 0){
        thisFile = thisFile.substring(1);
    }
    
    if (thisFile.indexOf("??") >= 0) {
    
        thisFile = thisFile.substring(0, thisFile.indexOf("??") + 1) + thisFile.substring(thisFile.indexOf("??") + 2);
    }
        
    return thisFile;
}
