var TURL = document.location.href;				//TURL = This URL.	 eg. wedran.com/pay/index.html
var PURL = parent.document.location.href;		//PURL = parent URL. eg. wedran.com/
var MURL, tmp="";

if (language == "") language = default_language;

function getMURL(l) {                          // MURL = Mixed URL (Interface + page URL), l = layout
    if (l == "" || l == default_layout) 
	    if (language == default_language)
		    tmp = "";                          //wedran.com/?legal/
	    else
		    tmp = language + "/";              //wedran.com/se/?legalt/
    else
	    if (language == default_language)
		    tmp = l + "/";                     //wedran.com/basic/?legal/
	    else
		    tmp = language + "/" + l + "/";    //wedran.com/se/basic/?legalt/

    var tmp2 = TURL.substr(BURL.length); 
	    tmp2 = tmp2.replace(/\index.html/gi, "");
	    
    return BURL + tmp + "?" + tmp2;
}

if (parent.interface_name) { //interface is open -> Check if correct layout/language

    if ( (!parent.edit_mode && layout == "") || layout == parent.layout || (parent.edit_mode && layout == "" && parent.layout == default_layout)) { //correct layout
    
        MURL = getMURL(parent.layout);
    
        if (language == parent.language) { //correct language
           document.write("<script src='" + BURL + "system/interfaces/" + parent.interface_name + "/" + parent.layout + "/content.js'></script>");
        
        } else { //correct layout & INcorrect language -> open same layout in another language

			parent.location = MURL;
        }

    } else { //incorrect layout (page has different layout than open layout)

        parent.location = getMURL(layout);

    }
		
} else { //interface is not open -> Decide which interface/layout/language-combination to open

	window.location = getMURL(layout);
}