/* comment added extra characters to make sure it ftp's to all servers */
function extractCookies(){
	var cookies = new Object();
	var name, value;
	var beginning, middle, end;
	for(name in cookies){
		cookies = new Object();
		break;
	}
	beginning = 0; 
	while (beginning < document.cookie.length){
		middle = document.cookie.indexOf('=', beginning);
		end = document.cookie.indexOf(';', beginning);
		if (end == -1){ 
			end = document.cookie.length;
		}
		if ((middle > end) || (middle == -1)){
			name = document.cookie.substring(beginning, end);
			value ="";
		}
		else{
			name = document.cookie.substring(beginning, middle);
			value = document.cookie.substring(middle + 1, end);
		}
		cookies[name] = unescape(value);	
		beginning = end + 2;
	}	
	return cookies;
}
function surveyLaunch(){
	var popupPath = 'http://www.bbc.co.uk/survey/insitenov2004/newsround/newsroundinsitesurvey.htm';
	var upperLimit = 5;
	var surveyRoot = '/';
	var surveyExpiry = 14;
	var popupWidth = 635;
	var popupHeight = 547;
	var today = new Date();
	var day = today.getDate() + surveyExpiry;
	today.setDate(day);
	var dateString = today.toGMTString();
	var rand = Math.round(Math.random() * (upperLimit - 1)) + 1;
	var popupString = 'height=' + popupHeight + ',width=' + popupWidth + ',resizable=yes,scrollbars=yes';
	var cookies;
	cookies = extractCookies();	
	if ((document.cookie)&& !cookies["BBCSurvey"] && cookies["BBC-UID"]){
		cookieString = 'BBCSurvey=true; expires=' + dateString + '; path=' + surveyRoot + ';' ;
		document.cookie = cookieString;			
		if (rand == 1){				
			window.open(popupPath, 'survey', popupString);
		}
	}
}
