
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//'                                                                '
//'   source       :   userprocs.js                                 '
//'   Description  :   included in sse.inc. user procedures        '
//'                                                                '
//'                                                                '
//'   Cerium content manager (based on the Sellenger site engine) 									 '
//'	(c) 1997-2007 Jos Verhoeff, cerium             '
//'   For more information http://www.cerium.nl              '
//'                                                                '
//'                                                                '
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

function flvpopup(map,mname,width,height) 
{
	var intIndexOfMatch = mname.indexOf( " " );
	while (intIndexOfMatch != -1){
		mname = mname.replace( " ", "%20" )
		intIndexOfMatch = mname.indexOf( " " );
	}
	var win1=window.open('/cerium/popup_flvalbum.asp?map='+ map + '&mov='+mname+'.flv&width='+width+'&height='+height,'movie','width='+ eval(width+20) + ',height='+ eval(height+40) + ',menubar=no,scrollbars=no,toolbar=no,resizable=no')
	win1.focus();
}

function popup(src,width,height) 
{
	var win1=window.open(src,'pop','width='+ eval(width) + ',height='+ eval(height) + ',status=no,titlebar=no,menubar=no,scrollbars=no,toolbar=no,resizable=no')
	win1.focus();
}
function pageflippopup(map,width,height) 
{
	var win1=window.open('/cerium/usertemplates/CERIUM-pageflip.asp?map='+map+'&width='+ eval(width) + '&height='+ eval(height),'pop','width='+ eval(width) + ',height='+ eval(height) + ',status=no,titlebar=no,menubar=no,scrollbars=no,toolbar=no,resizable=no')
	win1.focus();
}
function fotoalbumpopup(map,width,height) 
{
	var win1=window.open('/cerium/usertemplates/CERIUM-fotoalbum.asp?map='+map+'&width='+ eval(width) + '&height='+ eval(height),'pop','width='+ eval(width) + ',height='+ eval(height) + ',status=no,titlebar=no,menubar=no,scrollbars=no,toolbar=no,resizable=no')
	win1.focus();
}
// these also exist in the vb component
function ssecreateCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function ssereadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return '';
}

function sseeraseCookie(name) {
	ssecreateCookie(name,"",-1);
}

function ssecookietest(bMsg) {
	var cookieVal = "Cerium Cookie test";
	ssecreateCookie("TestCookie",cookieVal)
	if (ssereadCookie("TestCookie") != cookieVal ) {
		if (bMsg) alert(msgNoCookies);
		return false;
	}
	sseeraseCookie("TestCookie");
	return true;
}

// onkeyup and onclick, erases initial input or puts it back
function doDefaultInputString(O,S)
{
	if (O) {
		if (O.value.toUpperCase() == S.toUpperCase()) {
			O.value = "";
			return false;
		}
		if (O.value.length == 0) {
			O.value = S;
			return false;
		}
	}
	return true;
}

// AJAX functionality in het CMS !!!
function gethttpxmlrequestobject() {
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;

}

/*
---------------------------------------------------------------------------

 * 	This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2, or (at your option)
 *      any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program (see the file COPYING); if not, write to the
 *      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *      Boston, MA  02111-1307, USA
 
This code is copyright 2003 by Matthew Eernisse (mde@state26.com)

Additional bugfixes by Mark Pruett (mark.pruett@comcast.net)

---------------------------------------------------------------------------	
*/ 

// The var docForm should be a reference to a <form>

function formData2QueryString(docForm) {

	var strSubmitContent = '';
	var formElem;
	var strLastElemName = '';
	
	for (i = 0; i < docForm.elements.length; i++) {
		
		formElem = docForm.elements[i];
		switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'select-one':
				strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				break;
				
			// Radio buttons
			case 'radio':
				if (formElem.checked) {
					strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				}
				break;
				
			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Continuing multiple, same-name checkboxes
					if (formElem.name == strLastElemName) {
						// Strip of end ampersand if there is one
						if (strSubmitContent.lastIndexOf('&') == strSubmitContent.length-1) {
							strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
						}
						// Append value as comma-delimited string
						strSubmitContent += ',' + escape(formElem.value);
					}
					else {
						strSubmitContent += formElem.name + '=' + escape(formElem.value);
					}
					strSubmitContent += '&';
					strLastElemName = formElem.name;
				}
				break;
				
		}
	}
	
	// Remove trailing separator
	strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
	return strSubmitContent;
}




function doxmlhttprequest(URL, TargetDiv) {
	var oTargetDiv, S
	var xmlhttp = gethttpxmlrequestobject();
	if (TargetDiv) {
		oTargetDiv = document.getElementById(TargetDiv);
	}
	if (!xmlhttp) {
		oTargetDiv.innerHTML = msgNoXMLobject;
		return false;
	}
	xmlhttp.open("GET", URL ,true);
	//alert(xmlhttp.responseText);
    xmlhttp.onreadystatechange=function() {
	   if (xmlhttp.readyState==4) {
			//alert(URL + ' ' + xmlhttp.status);
			if (xmlhttp.status != 200) {
				S = msgNoXMLexecute + URL + " (status=" + xmlhttp.status  + ")";
				if (xmlhttp.status >= 500) S = S +  " error message=" + xmlhttp.responseText;
			} else {
		    	S = xmlhttp.responseText;
			}
			if (oTargetDiv) oTargetDiv.innerHTML = S;
	   }
	}
	xmlhttp.send(null);
 	xmlHttp = null;
}





function doxmlhttppost(URL, formname, TargetDiv) {
	var oTargetDiv, S
	var xmlhttp = gethttpxmlrequestobject();
	if (TargetDiv) {
		oTargetDiv = document.getElementById(TargetDiv);
	}
	if (!xmlhttp) {
		oTargetDiv.innerHTML = msgNoXMLobject;
		return false;
	}
	var oForm = document.getElementById(formname);
	var parameters = formData2QueryString(oForm)

	xmlhttp.open("POST", URL, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", parameters.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
	   if (xmlhttp.readyState==4) {
			//alert(URL + ' ' + xmlhttp.status);
			if (xmlhttp.status != 200) {
				S = msgNoXMLexecute + URL + " (status=" + xmlhttp.status + ")";
			} else {
		    	S = xmlhttp.responseText;
			}
			if (oTargetDiv) oTargetDiv.innerHTML = S;
	   }
	}
	xmlhttp.send(parameters);
}

function isDivVisible(TargetDiv) {
	var oDiv = document.getElementById(TargetDiv)
	while (oDiv) {
		if (oDiv.style) {
			if (oDiv.style.display == "none") return false;
		}
		oDiv = oDiv.parentNode;
	}
	return true;
}


function repeatxmlhttprequest(URL, TargetDiv,interval) {
	// refreshes content if parent div is visible
	// if not request is put on the "stack"
	// interval > 500, always refres, < 500 only one time
	var bVisible = isDivVisible(TargetDiv);
	if (bVisible) doxmlhttprequest(URL, TargetDiv);
	if ((interval > 500) || (!bVisible)) {
		thisInterval = bVisible ? interval : 10;
		setTimeout('repeatxmlhttprequest(\'' + URL + '\',\'' + TargetDiv + '\',' + interval + ')',thisInterval );
	}
}

function ssenop() {
}