<?php
$tok="";
if (file_exists(implode("/",array_slice(explode("/",realpath(".")), 0, -1)).'/tecall.json')) {
    $rep = json_decode(file_get_contents(implode("/",array_slice(explode("/",realpath(".")), 0, -1)).'/tecall.json'),true);
	if($rep&&!empty($rep["apiKey"])){
		$tok = $rep["apiKey"];
	}
}
?>
<iframe id="vh" style="width: 1200px;border: unset;"></iframe>
<iframe id="mg" style="width: 1200px;border: unset;"></iframe>
<iframe id="sg" style="width: 1200px;border: unset;"></iframe>
<script>
function gor(x){
    switch(x.charAt(0)) {
        case 'h': xmg(x.substring(1));break;
        case 's': xsg(x.substring(1));break;
        default: alert(x);
    }
}
function mor(g,x){
    var z = (x.replaceAll('\\"','"')).replaceAll(/(?:\\[rnt]|[\r\n\t])/g, " ").slice(1, -1);
    z = z.replaceAll(/onclick="clickOnElement/g,'onclick="parent.gor');
    z = z.replaceAll(/href="Þ([a-z][0-9]+)Þ"/g,'onclick="parent.gor(\'$1\')"');
    g.contentWindow.document.write(z);
    setTimeout(() => {
        g.height = g.contentWindow.document.body.scrollHeight+4;
    }, 200);
}
var typeId="<?= $_GET['i']??0 ?>",
    cap="<?= $_GET['c']??0 ?>",
    lang="<?= $_GET['l']??'en' ?>",
    myHeaders = new Headers();
myHeaders.append("X-Api-Key", "<?= $tok ?>");
myHeaders.append("Content-Type", "application/json");
function xfetch(req,data,elm){
    elm.contentWindow.document.open();
    elm.contentWindow.document.close();
    var raw = {
        "CountryCode": "DE",
        "LanguageCode": lang,
        "TypeId": typeId,
        "bodyQualColId": cap,
    };
    for(var key in data) raw[key]=data[key];
    var requestOptions = {
        method: 'POST',
        headers: myHeaders,
        body: JSON.stringify(raw),
        redirect: 'follow'
    };
    fetch("https://webservice.tecalliance.services/rmi-proxy/rest/Graphics/"+req, requestOptions)
        .then(response => response.text())
        .then(result => mor(elm,result))
        .catch(error => console.log('error', error));
}
function xvh(){
    xfetch("GenArtVehicleHtml",{},vh);
}
function xmg(x){
    xfetch("GenArtMaingroupHtml",{"mainGroupId": x},mg);
}
function xsg(x){
    xfetch("GenArtSubgroupHtml",{"subGroupId": x,"subGroupQualCol":0},sg);
}
xvh();
</script>