// RUNTIME CODE BELOW! Cybonk Control 10/2/2002, 2004

function quicktriple_firstCookies(){  
// 3 objs in one cookie
	var tempchrs=""; 
	var prebaker= ""; 
	var keywords="";
	var matrix="";
	var userobj="";
	
	tempchrs = comma_string_to_amp_string('lastkeyworda','life','lastkeywordb','xor','lastkeywordc','art','lastkeywordd','Baker','combinatora','OR','combinatorb','OR','combinatorc','NOT');
	keywords = "c_keywords" + "=&" + escape(tempchrs) + "STOPC";
	
	tempchrs = comma_string_to_amp_string('r1','0','r2','0','r3','0','r4','0','r5','0','r6','0','r7','0','r8','0');
	matrix   = "&c_matrix" + "=&" + escape(tempchrs) + "STOPC";  

	tempchrs = comma_string_to_amp_string('lastalphaword','artstudios'); // ,'name','Guest' ,'email','' 
	userobj  = "&c_theUserObj" + "=&" + escape(tempchrs) + "STOPC"; 
	
	//rebaker=;
	setcookie ("mnc="+keywords+matrix+userobj);
	
	theKeywordObj = namedCookieToObj("c_keywords"); 
	theMatrixObj =  namedCookieToObj("c_matrix"); 
	theUserObj =    namedCookieToObj("c_theUserObj"); 
}


// 	----------+++
function setcookie(){ 
	var exDate = new Date;
	exDate.setMonth(exDate.getMonth()+ 9); // months
	document.cookie = arguments[0] +"; expires=" + exDate.toGMTString() + "; path=/";
}  
/*
cookie is nu zo: 

c_keywords="
&lastkeyworda=life&lastkeywordb=xor&lastkeywordc=art&lastkeywordd=Baker&combinatora=OR&combinatorb=OR&combinatorc=NOT
&STOPC
&c_matrix=&r1=0&r2=0&r3=0&r4=0&r5=0&r6=0&r7=0&r8=0
&STOPC
&c_theUserObj=&lastalphaword=artstudios&STOP
"

1st note: cookie-name is c_keywords ; niet goed
2nd note: &c_keywords= moet 1e val zijn zoals in beide andere?????
*/



// 	----------+++

function firstCookies(){  
	var argv=arguments;	//Deprecated ::::: var argv=firstCookies.arguments;
	
	var tempname=argv[0]; 
	var prebaker= ""; 
	if (tempname=="c_keywords"){ 
		prebaker= comma_string_to_amp_string('lastkeyworda','life','lastkeywordb','xor','lastkeywordc','art','lastkeywordd','true','combinatora','OR','combinatorb','OR','combinatorc','NOT');
  		prebaker = tempname + "=&" + escape(prebaker) + "STOPC";  
		setcookie (prebaker);
		theKeywordObj = namedCookieToObj("c_keywords"); 
	} else if (tempname=="c_matrix"){ 
		prebaker= comma_string_to_amp_string('r1','0','r2','0','r3','0','r4','0','r5','0','r6','0','r7','0','r8','0');
  		prebaker = tempname + "=&" + escape(prebaker) + "STOPC";  
		setcookie (prebaker); 
		theMatrixObj = namedCookieToObj("c_matrix"); 
	 } else if (tempname=="c_theUserObj"){	 	
		prebaker= comma_string_to_amp_string('lastalphaword','a'); // ,'name','Guest' ,'email','' 
  		prebaker = tempname + "=&" + escape(prebaker) + "STOPC";  
		setcookie (prebaker);
		theUserObj = namedCookieToObj(tempname); 
	} 
} 

function FRF_updateMemObject(){  
	// bv (theUserObj,'lastalphaword','abcdef' [,avar ,aval] )
	// ( object [,varstring1,valstring2] [,varstring3,valstring4] )
	var i,j=0; 
	var meobjname = new Array(); 
	meobjname=arguments[0]; //FRF_updateMemObject.
	var argv= new String();		
	argv= arguments; //FRF_updateMemObject.	 
	for(i=1;i<argv.length-1;i=i+2) { 
		var mevar=argv[i]; 
		var meval=argv[i+1]; 
		j=findPropIndexNr(meobjname,mevar);
		if(j!=false){meobjname[j][1]=meval;} //store new value if the prop exists
	}
	 //alert(meobjname[findPropIndexNr(meobjname,mevar)][1]);
}

function FRF_cookMemObject(){  
	// (theUserObj) 
	var meobjname = new Array(); 
	meobjname=arguments[0]; //FRF_cookMemObject.
	var argv= new String();		
	argv= arguments; //FRF_cookMemObject.	 
	setcookie( meobjname[1][1] + "=" + escape(c_Object_to_amp_string(meobjname)) + "STOPC");
}



// 	----------+++

function comma_string_to_amp_string() { 
	var argv=arguments;  //comma_string_to_amp_string.
  	var compstring = "";  
  	var i;  
	for(i=0;i<argv.length;i++) { 					
		compstring += argv[i] + '=' + argv[i+1] + '&';  	
		i++; 							
	} 
	return compstring;  //var1=val1&.....
}
// 	----------+++

function c_Object_to_amp_string() { 
	var argv=arguments; //c_Object_to_amp_string.
	var tempObj = new Array(); 
	tempObj=argv[0]; 
  	var compstring = "&"; 
	var i;
	for(i=2;i<tempObj.length;i++) {  
		//met 'quotes': compstring += tempObj[i][0] + "='" + tempObj[i][1] + "'&"; 
		compstring += tempObj[i][0] + "=" + tempObj[i][1] + "&"; 
	} 
	compstring = compstring.substring(0,compstring.length-1); // knip last &
	return compstring;  //&var1=val1&.....
}
// 	----------+++

function findPropIndexNr(){  // bv=findPropIndexNr(c_theUserObj,"email")  => 2
	var argv=arguments; //findPropIndexNr.
	var tempObjc = new Array(); 
	tempObjc=argv[0]; 
	var temppropname=argv[1]; 
	var toad;  
	for (toad=0; toad<tempObjc.length; toad++){
		if(tempObjc[toad][0]==temppropname){
			return toad; 			// => 2
			break;
		}
	}
	return false; 
}

// 	----------+++
 
function deleteCookie(theName,thePath){ 
	document.cookie = theName + "=; expires=Thu, 01-Jan-01 01:01:01 GMT" +  "; path=" + thePath;
}
 
// 	----------+++ OTHER FUNK
function replaceAforBinC(oldS,newS,fullS) { // repl. oldS with newS in fullS   
	for (var i=0; i<fullS.length; i++) {
		if (fullS.substring(i,i+oldS.length) == oldS){
			fullS =fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
		}   
	}   
	return fullS; 
}

















// 	NIET GEBRUIKTE FUNC MET NEW CODE: 
// 	bv=findPropValue(c_theUserObj,"email"); => returns "you@test.com" of false
// 	zie in /sys/ " cookiez-NOT.js "
// 	----------+++

 
// 	----------+++

function namedCookieToObj() { 						// wordt runtime gebruikt zie onderaan
	var argv=arguments; //namedCookieToObj.
	var tempname=argv[0];   
	var tempstring=read_named_cookie_trim(tempname); 		//call internal func
	if(tempstring != false) {
		tempstring = "&c_name=" + tempname + tempstring;  	
		var tempObj = new Array();
		tempObj = amp_string_to_object(tempstring); 	
		return tempObj;	 					
	} else { 
		return false; 
	}
}


function read_named_cookie_trim() {
	var argv=arguments; //read_named_cookie_trim.
	var tempername=argv[0];  
	if (document.cookie == "") {  				
		return false; 					
	} else { 						
		var firstChar, lastChar, tempChar;
		var theBigCookie = document.cookie;				
		firstChar = theBigCookie.indexOf(tempername);	
		//alert(firstChar);
		if(firstChar == -1)  {  					
			return false; 						
		} else {
			var tempString = new String("");
			firstChar += tempername.length + 1; 	
			
			lastChar = theBigCookie.indexOf("STOPC", firstChar); 
			if(lastChar == -1) { 					
				lastChar = theBigCookie.length;
			}
			tempString = unescape(theBigCookie.substring(firstChar, lastChar)); 
			tempChar  = tempString.charAt(tempString.length-1); 	
			if(tempChar == "&") { 	
				tempString = tempString.substring(0,tempString.length-1); 
			}
			return tempString; 
		}
    }
}



// 	----------+++

function amp_string_to_object() {  
	var argv=arguments; //amp_string_to_object.
	var tempInstring=argv[0]; 	//alert("amp_string_to_object argv[0]: " + argv[0]);

	var separated_values = tempInstring.split("&"); 
	var property_value = ""; 
	var tempObj = new Array(); 
	var i = 0;
	var j = 0;
	for (i = 0; i < separated_values.length; i++) {
		property_value = separated_values[i];
		var broken_info = property_value.split("=");
		var the_property = broken_info[0];
		var the_value = broken_info[1];
		tempObj[j] = new Array(2);
		tempObj[j][0]=the_property; 
		tempObj[j][1]=the_value;  
		j++;
	}
	return tempObj; 
}
// 	----------+++







/*

// RUNTIME:  ===========================
var theUserObj = new Array(); 
theUserObj = namedCookieToObj("c_theUserObj"); // returns false if not found
if (!theUserObj){ firstCookies("c_theUserObj"); }
//
var theMatrixObj = new Array(); 
theMatrixObj = namedCookieToObj("c_matrix"); 
if (!theMatrixObj){ firstCookies("c_matrix"); }
//
var theKeywordObj = new Array();
theKeywordObj = namedCookieToObj("c_keywords"); 
if (!theKeywordObj){ firstCookies("c_keywords"); }
// 

*/




// this RUNTIME: while testing newcookie-funcs, JS/Flash ===========================
var theUserObj = new Array(); 
var theMatrixObj = new Array(); 
var theKeywordObj = new Array(); 

//if (document.cookie == "") {  				
		quicktriple_firstCookies(); 
		//alert(document.cookie);
//} else { 	
/*
		var firstChar, lastChar, tempChar;
		var theBigCookie = document.cookie;				
		firstChar = theBigCookie.indexOf(tempername);	
		alert("sddsd"+theBigCookie);
		if(firstChar == -1)  {  					
			return false; 						
		} else {
			var tempString = new String("");
			firstChar += tempername.length + 1; 	
			
			lastChar = theBigCookie.indexOf("STOPC", firstChar); 
			if(lastChar == -1) { 					
				lastChar = theBigCookie.length;
			}
			tempString = unescape(theBigCookie.substring(firstChar, lastChar)); 
			tempChar  = tempString.charAt(tempString.length-1); 	
			if(tempChar == "&") { 	
				tempString = tempString.substring(0,tempString.length-1); 
			}
			return tempString; 
		}
}
*/



// ========================================================



// standard test
// var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; 	// MSIE
var isNSold = ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) <= 4)) ? true : false;  //ns4
// var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; 	// windows
//

