function urlEncode (string) {
  string = string.replace(/ /g, '+');
  return escape(string);
}

function openISurvey (url, ref) {
	var placeY;
	var placeX;
	if (ref) {
		url = url + "&ref=" + urlEncode(ref);
	}
	open(url,"ISurvey","width=600,height=600,resizable=yes,scrollbars=yes,status="+ (protocol == 'https' ? 'yes' : 'no') +"");
}

function cookie_status() {

	if(document.cookie){
		var cookie = document.cookie;

		if(cookie) { // if we have any cookies, ..
			cookies = cookie.split(';');
			var pattern = /survey\[([0-9]+)\]=([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):[0-9]{2}\|finished=(true|false)/;
			for(i=0;i<cookies.length;i++) { // .. check them one by one
				match=pattern.exec(cookies[i]); // using regex
				if (match) { // if it is a usable bit of cookie, ..
					this_cookie_finished = (match[7] == 'true');
					cookie_finished[match[1]] = this_cookie_finished;
				}
			}
		}
	}
}

function parseQueryString(str) {
	try {
		str=str?str:this.location.search;
		var query=str.charAt(0)=='?'?str.substring(1):str;
		var args=new Object();
		if(query){
			var fields=query.split('&');
			for(var f=0;f<fields.length;f++){
				if(fields[f] != '') {
					var field=fields[f].split('=');
					args[unescape(field[0].replace(/\+/g,' '))]=unescape(field[1].replace(/\+/g,' '));
				}
			}
		}
	}
	catch(doNothing) {
		// nothing
	}
	if (args)
		return args;
}

var args=parseQueryString();
var surveyIdExclude = '';
var refreshed = args['done']=='yes';
var finished = args['finished'] == 'true';

// Copyright (c) 1997-2010 - I-Survey