function getVar(name)
{
	get_string = document.location.search;         
	return_value = '';

	do { //This loop is made to catch all instances of any get variable.
		name_index = get_string.indexOf(name + '=');

		if(name_index != -1)
		{
			get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);

			end_of_value = get_string.indexOf('&');
			if(end_of_value != -1)                
				value = get_string.substr(0, end_of_value);                
			else                
				value = get_string;                

			if(return_value == '' || value == '')
				return_value += value;
			else
				return_value += ', ' + value;
		}
	} while(name_index != -1)

	//Restores all the blank spaces.
	space = return_value.indexOf('+');
	while(space != -1)
	{ 
		return_value = return_value.substr(0, space) + ' ' + 
			return_value.substr(space + 1, return_value.length);

		space = return_value.indexOf('+');
	}

	return(return_value);        
}

function showWindow(){
	var askME = readCookie("askME");

	if(askME == 'true'){
		var test = getVar('test');
		if(test == 1){
			askME = null;
		}
	}


	if(askME == null){
		createCookie("askME",true,365);
		Dialog.info('<div id="survey-popup">\n<div class="content">\n<h1>Servier Website User Survey</h1>\n<p class="divider"> We\'re looking for site visitors to help us improve the Servier website.</p>\n<p><strong>Will you help us out?</strong></p>\n<p>  You can participate by answering a few questions as you enter the site  (should take no more than 30 seconds), and a few more after you have  completed your visit.</p>\n<p class="buttons divider">\n  <input name="button" type="submit" class="survey-button" id="surveyButton" value="I\'ll Help" />\n  &nbsp;&nbsp;<input name="button2" type="submit" class="survey-button" id="surveyButton2" value="No Thanks" />\n  <br /><br />\n  This survey is being conducted by Organik, a market research company<br />\non behalf of Servier Laboratories Limited.<br />\n<a href="http://survey.askme.net/StaticPages/privacy/x6Q3QhEIr5eScH4-hw==" target="_blank">Privacy Statement</a><br />\n<br />\nPlease Note: Children under the age of 16 are not eligible to participate in this survey.<br />\n</p>\n</div>\n<div class="footer">\n  <p class="hide">Organik&trade; is a trusted survey partner of Servier UK</p>\n</div>\n</div>\n', {width:572, height:447} );
		Event.observe('surveyButton','click',showSurvey);
		Event.observe('surveyButton2','click',function(){Dialog.closeInfo();});
	}
}

function showSurvey(){
	var test = getVar('test');
	if(test == 1){
		window.open('http://survey.askme.net/Participants/testSurvey/165','','width=760,height=800,scrollbars=1');
	}else{
		window.open('http://survey.askme.net/Participants/startSurvey/165','','width=760,height=800,scrollbars=1');
	}
	Dialog.closeInfo();
}

Event.observe(window,'load',function() {showWindow();});

