function startx() {
}
function pdf() {
	var lh=location.href;
	var li=lh.lastIndexOf("/");
	var filename=location.href.substring(li+1,lh.length-4);
	var pdffn="../luminairePDF/"+filename+"pdf";
	window.open(pdffn);
}
function start() {
 read_project_data("lum"); 
 setflashvalues();

 //alert(location.href);
 //var zwi = location.href.lastIndexOf ("html?"); 
 var zwi=GetCookie("var1");
 //if (zwi!=-1) {
 if (zwi!=""&&zwi!="null"&&zwi!=null) {
   //window.opener.document.vars.var1.value="";
   SetCookie ("var1","");
   //var cp = location.href.substring(zwi+5,location.href.length);
   //cp=unescape(cp);
   cp=unescape(zwi);
   //alert(cp);
   var cc=cp.split("#");
   //alert(cc[0]);
   editnr=cc[0];	//diese muss bei edit gelöscht werden
   document.prod_sel.comment.value=unescape(cc[2]);
   var temp=cc[3].split("|");
   document.prod_sel.type.value=unescape(temp[1]);
   var i,temp;
   for (i=4; i < cc.length-1; ++i){
     temp=cc[i].split("|");
	 //alert(parseInt(temp[0]));
     document.prod_sel.select[i-4].selectedIndex=parseInt(temp[0]);
   }
 }
}
function goback() {
 //normal zur produkteseite, nach view zu home
 history.back();	//geht jetzt, da kein link mehr innerhalb der seite
 //var zwi = location.href.lastIndexOf ("html?"); 
 //var cp = location.href.substring(zwi+4,location.href.length);
 //if(cp.substring(0,1)=="?") location.href="../html/home.html";
 //else location.href="../html/produkte.html";
}
function printwithspec() {
 window.print(); 
 //var zwi = location.href.lastIndexOf ("/"); 
 //var cp = location.href.substring(zwi+1,location.href.length-5)+"_spec.html";
 //location.href=cp+"?print";  
}


function next(){
  var LH=location.href;
  var LIO=location.href.lastIndexOf("/");
  var HTML=LH.substr(LIO+1,LH.length);
  var nm=HTML.split(".");
//alert(nm[0]);
//alert(pg[2][2]);

var temp="";
var Suche=0;
var suchbegriff=nm[0];
   for (i=1; i < 12; ++i){
     apgl=pg[i].length;
     //alert("apgl="+apgl);
     for (j=1; j < apgl; ++j){
       if (pg[i][j][0]==suchbegriff) temp=pg[i][j+1][0];

     }
   }
ziel="../luminaire/"+temp+ ".html";
//alert(ziel);
location.href=ziel;
}

function loginasguest() {
  //window.opener.document.vars.user.value="guest";
  SetCookie ("user","guest");
  alert("You are logged in as: guest");

  location.href="myprojects.html";
}

function loginmenu(){
  //window.opener.document.vars.user.value=""
  SetCookie ("user","")
  //window.opener.document.vars.project_akt.value=""
  SetCookie ("project_akt","")
  //window.opener.document.vars.var1.value=""
  SetCookie ("var1","")
  //window.opener.document.vars.project_data.value=""
  SetCookie ("project_data","")
  SetCookie ("email","")
  location.href="../html/login.html";
}

function shownav(navname) {
  if (document.getElementById) {
    document.getElementById(navname).style.visibility="visible";
  }	else {
    //alert(document[movieName]);
  }
}
function hidenav(navname) {
  if (document.getElementById) {
    document.getElementById(navname).style.visibility="hidden";
  }	else {
    //alert(document[movieName]);
  }
}

function thisMovie(movieName) {
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    //alert(window.document.all[movieName]);
	return window.document.all[movieName];
  }	else {
    //alert(document[movieName]);
	return document[movieName];
  }
}

function setflashvalues(){
 //var IE=navigator.appName.indexOf("Microsoft")!=-1;
 //var co=IE ? window.document.lumi : window.document.embeds[1];
 //thisMovie(movieName).SetVariable('project.text', theValue);
 var co=thisMovie('lumi');
 //thisMovie("myMovie").SetVariable('project.text', "haha");
 //var co=thisMovie("myMovie");
 //alert(co);
 if (co=="[object]"){
  co.SetVariable("project.text",document.all.field11.innerText);
  co.SetVariable("luminaire.text",document.all.titel.innerText);
  co.SetVariable("ldata1.text",prod_sel.ldata1.value);
  co.SetVariable("ldata2.text",prod_sel.ldata2.value);
  co.SetVariable("ldata3.text",prod_sel.ldata3.value);
 }
}

function del(nr){
 var pa = GetCookie("project_akt");
 var cc=GetCookie(pa);
 var ccc=cc.split("#next=");

 cc="";
 var i;
 var zeile="";
   for (i=0; i < ccc.length-1; ++i){
    if(i!=nr) cc=cc+ccc[i]+"#next=";
   }
 SetCookie(pa,cc);
}

function save_and_addnewproduct(){
 saveandgo("../html/produkte.html"); 
}
function save_and_order(){
 saveandgo("../html/home.html");
}
function saveonly(){
 saveandgo("lum");
}
function saveandgo(targ) {
 //alert("targ="+targ);

 var flag="false";
 //seitenname bestimmen
 //alert(location.href);
 var zwi = location.href.lastIndexOf ("/"); 
 var zwi1 = location.href.indexOf (".html"); 
 var cp = location.href.substring(zwi+1,zwi1);
 //alert("cp="+cp+"===");
 var gesamt=cp+"#"+escape(document.prod_sel.comment.value)+"#0|"+escape(document.prod_sel.type.value)+"#";
 var nr="";
 var txt="";
 //alert(document.prod_sel.select[6].selectedIndex);
 var i;
//alert(document.prod_sel.select.length);
 for (i=0; i < document.prod_sel.select.length; ++i){
		if (document.prod_sel.select[i].value=="select") gesamt=gesamt+"select| "+"#";
		else {
		  nr=document.prod_sel.select[i].selectedIndex;
		  txt=document.prod_sel.select[i].options[nr].text;
		  if(txt==""||txt==" ") flag="true";
		  gesamt=gesamt+nr+"|"+txt+"#";
		}
 }
 //neu! kürzere Inhalte
 for (i=0; i < 9-document.prod_sel.select.length; ++i){
   gesamt=gesamt+"select| "+"#";;
 }



 if(flag=="true") {
	  alert("Your inputs are not complete.");
	  return false;
 }
 else {
	 //neu abfrage ob speichern
	 var Check=false;
	 if (targ=="lum") {
		if (document.todb.saved.value=="saved") Check=false;
		else Check=true;
	 }
 	 else {
		if (document.todb.saved.value=="saved") Check=false;
		else Check=confirm("Save changes?"); 
	 }
 
	 if(Check==false) {
		//location.href=targ; //wird weiter unten entschieden bei "Please log in and ... 
		//return false;
	 }
	 else document.todb.saved.value="saved";
//*******************************************************************************
	    var project_akt=GetCookie("project_akt");
		var project_data=GetCookie(project_akt);
		if (editnr==0||editnr==null||editnr=="null") {
		  project_data=project_data+gesamt+"#next=";
	    }
	    else {
	      //alert("vorher="+project_data);
		  cc=project_data.split("#next=");
		  project_data="";
		  for (i=0; i < cc.length; ++i){
		    if (i==editnr) project_data=project_data+gesamt+"#next=";
		    else {
		      if (cc[i]!="") project_data=project_data+cc[i]+"#next=";
		    }
		  }
	    }
	    //alert("nachher="+project_data);
	    SetCookie(project_akt,project_data);

	  //Zwischenspeichern, falls nich eingeloggt
	  if(GetCookie("user")==""||GetCookie("user")==null||GetCookie("user")=="null" || GetCookie("project_akt")==""||GetCookie("project_akt")==null||GetCookie("project_akt")=="null") SetCookie("temp_data",gesamt+"#next=");
	  //zum Login, falls nicht eingeloggt
	  //alert("hier");
	  if(GetCookie("user")==""||GetCookie("user")==null) {		//nicht eingeloggt
	  	alert("Please log in and select a project or create a new project.");
	   	location.href="../html/login.html";
	    return false;
	  }
	  else  {
	      //Zur Projektauswahl, falls kein Projekt gewählt		//kein Projekt ausgewählt
		  if(GetCookie("project_akt")==""||GetCookie("project_akt")==null){
	    	alert("Please select a project or create a new project");
	    	location.href="../html/myprojects.html";
	    	return false;
		  }
	  }
	  
	  if(Check==false) {		//zur Zielseite ohne speichern
		location.href=targ;
		return false;
	  }

	  //alert("darf nicht bei ohne login") 
	  //send to db
	  if(location.href.indexOf("http:")!=-1) {
	    document.todb.project.value=project_akt;
	    var Jetzt = new Date();
	    document.todb.datum.value=Jetzt;	//.toGMTString();
	    document.todb.content.value=project_data;
	    document.todb.targ.value=targ;
	    //alert(document.todb.content.value);
	    document.todb.submit();
	  }
	  else {
	    if (targ=="lum") alert("Your data has been saved.");
            else location.href=targ;
	  }
 }
}

function showdesc() {
//alert(document.cookie);
  //var zwi = location.href.lastIndexOf ("/"); 
  //var zwi1 = location.href.lastIndexOf (".htm"); 
  //var cp = location.href.substring(zwi+1,zwi1)+"_spec.html";
  //location.href=cp;
  location.href="#desc";
}
function nichts() {
}



function read_project_data(lum){
//alert("erad");
if (typeof(lum)=="undefined") pa=GetCookie("project_akt");
else {
  if (lum=="lum") pa=GetCookie("project_akt");
  else pa=lum;

}
//alert("lum="+lum);
 var project_data="";
//alert("###"+pa+"###");
 if(pa=="") project_data="######0|###########";
 else project_data=GetCookie(pa);
//alert(project_data);
 if(project_data!=null&&project_data!=""){
  var ccc=project_data.split("#");
  document.all.field11.innerText=pa;
  document.all.field12.innerText=ccc[0];
  document.all.field13.innerText=ccc[1];
  document.all.field14.innerText=ccc[2];
  document.all.field15.innerText=ccc[3];
  if(typeof(lum)=="undefined") {
    document.all.field16.innerText=ccc[4];
    document.all.field17.innerText=ccc[5];
    var temp=ccc[6].split("|");
    if (location.href.indexOf("epd.html")==-1) document.all.field18.innerText=temp[1];
    else document.prod_sel.field18.selectedIndex=temp[0];
    document.all.field19.innerText=ccc[7];
  }
 }
}

//function GetCookiex (name) {  
// if(name=="project_akt") temp=GetCookie("project_akt");
// else temp=GetCookie("project_data");
// return temp;
//}

//function SetCookiex (name, value) {  

//  if(name=="project_akt") window.opener.document.vars.project_akt.value=value;	//co.SetVariable("local.data.project_akt",value);
//  else {
//  window.opener.document.vars.project_data.value=value;
//  }
//}

function getCookieVal (offset) {  
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)    
   endstr = document.cookie.length;  
//alert("coval="+unescape(document.cookie.substring(offset, endstr)));
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
//alert(unescape(document.cookie));

if(name=="project_akt"||name=="user"||name=="email"||name=="var1"||name=="temp_data");
else name="project_data";

  var arg = name + "=";  
  var alen = arg.length;  
  var clen = document.cookie.length;  
  var i = 0;  
  while (i < clen) {    
    var j = i + alen;    
    if (document.cookie.substring(i, j) == arg)      
      return getCookieVal (j);    
    i = document.cookie.indexOf(" ", i) + 1;    
    if (i == 0) break;   
  }  
  return null;
}

function SetCookie (name, value) { 
//alert(unescape(document.cookie));

//Cookie Check
var cookieEnabled=(navigator.cookieEnabled)? true : false;
//if not IE4+ nor NS6+
if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
document.cookie="testcookie";
cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false;
}
if (cookieEnabled) ;//alert("enabled"); //if cookies are enabled on client's browser
else alert("This program doesn't work with cookie disabled.");


if(name=="project_akt"||name=="user"||name=="email"||name=="var1"||name=="temp_data");
else name="project_data";
 
  var argv = SetCookie.arguments;  
  var argc = SetCookie.arguments.length;  
  var Verfall = (argc > 2) ? argv[2] : 0;  //null
  Verfall = 1000*60*60*24*Verfall;
  var jetzt = new Date();
  var expires = ((Verfall==0) ? null : new Date(jetzt.getTime() + Verfall));
  //var path = (argc > 3) ? argv[3] : null;  
var path="/";
  var domain = (argc > 4) ? argv[4] : null; 
//var domain="http://loc-os.de/hess_neu/"; 
  var secure = (argc > 5) ? argv[5] : false;  
  document.cookie = name + "=" + escape (value) + 
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
  ((path == null) ? "" : ("; path=" + path)) +  
  ((domain == null) ? "" : ("; domain=" + domain)) +    
  ((secure == true) ? "; secure" : "");
}
