function popup(url)
{
    var newwindow;
	newwindow=window.open(url,'name','height=200,width=600');
	if (window.focus) {newwindow.focus()}
}

function changeScreenSize(w,h) { window.resizeTo( w,h ) }


function refresh() { window.location.reload(); }

function removeDiv(parentDiv, divToRemove) {
  var pd = document.getElementById(parentDiv);
  var rd = document.getElementById(divToRemove);

  if (pd != null && rd != null){
  		pd.removeChild(rd);
  }
}

// get an object link this: 
// myObj = new getRepeatObject("myObj", funcToCall,intervalMins,countDownDivID);
// you can then call start() and stop() on this object
function getRepeatObject(globalVarName, funcToCall,intervalMins,countDownDivID){
	this.intervalSecs = intervalMins*60;
	this.secsLeft = this.intervalSecs;
	this.countDownDivID = countDownDivID;
	this.funcToCall=funcToCall;
	this.repeating=false;
	this.globalVarName=globalVarName;
	
	function start(){
		if(!this.repeating){
			this.recObj = setInterval(globalVarName+".update();",1000);
			this.repeating = true;
		}
	}
	
	function stop(){
		if(this.repeating){
			clearInterval(this.recObj);
			this.repeating = false;
			this.update();
		}
	}
	
	function update(){
		var html = "";
		if(this.repeating){
			if(this.secsLeft < 1){
				this.funcToCall();
				this.secsLeft = this.intervalSecs;
			}else{
				this.secsLeft = this.secsLeft-1;
			}
			if(this.secsLeft < 60){
				html = this.secsLeft+" seconds";
			}else{
				var mins = Math.floor(this.secsLeft/60);
				html = mins+" minutes";
			}
		}
		changeDiv(this.countDownDivID, html);
	}
	
	this.update = update;
 	this.start = start;
 	this.stop = stop;
}

// gets the value associated woth the cookie. 
// returns the empty string on no such cookie.
function getCookie(name){
	if (document.cookie.length>0){
  		cookBegin=document.cookie.indexOf(name + "=");
  		if (cookBegin!=-1){ 
			cookBegin=cookBegin + name.length+1;
			cookEnd=document.cookie.indexOf(";",cookBegin);
			if (cookEnd==-1){
				cookEnd=document.cookie.length;
			}
	    	return unescape(document.cookie.substring(cookBegin,cookEnd));
    	}
	}
	return "";
}


function setDisplayAll(className, display){
	var all = document.all ? document.all : document.getElementsByTagName('*');
	for (var i = 0; i < all.length; i++)
	if (all[i].className == className){
		var displayType = (all[i].tagName.toLowerCase()=='span')?'inline':'block';
		all[i].style.display=(display)? displayType:'none';
	}
}

// use if you know the qsVar to already be set in the qs
function setQsValue(qsVar, value, qs){
	var split = qs.indexOf(qsVar+'=') + qsVar.length +1;
	var begin = qs.substring(0,split); 
	var end = '';
	var endIndex = qs.indexOf('&',split);
	if(endIndex!=-1){
		end = qs.substring(endIndex);
	}
	var str = begin + value + end;
	return str;
}

function setShow(id){
	var theID = document.getElementById(id);
	if (theID != null) {
		theID.style.display = 'inline';
	}
}

function setHide(id){
	var theID = document.getElementById(id);
	if (theID != null) {
		theID.style.display = 'none';
	}
}

function setShowHideDiv(id){
	var theID = document.getElementById(id);
	if (theID != null) {
		if(theID.style.display == 'none'){
			theID.style.display = 'block';
		}else{
			theID.style.display = 'none';
		}
	}
}

function getShowHideLink(display, showHideDiv){
	return "<span class=jslink " +
		"onmouseover=\"javascript: this.className='jslink_hover';\" " +
		"onmouseout=\"javascript: this.className='jslink';\" " +
		"onclick=\"javascript: setShowHideDiv('"+showHideDiv+"');\"" +
		">"+display+"</span>";
}



function cookieEnabled(){
	if (isWindows() && (isIE() || isFirefox())){
		var name= 'octotestcookie';
		var value = 'hurra';
		setSetupCookie(name, value); 

		var start = document.cookie.indexOf( name + "=" + value);
		return (start > -1);
	}	
	return false;
}

function getCookieInstallerStandard(variant, lang, custom){
	getCookieInstaller(variant,lang,custom,"-afterinstall:dialog");
}

function setSetupCookie(name,value){
	var nu = new Date();
	nu.setTime(nu.getTime() + (1000*60*60*24));		// Your accept is valid for 24 hours
	document.cookie = name+'='+value+'; path=/; expires='+ nu.toGMTString() +'; domain=octoshape.com;'
}

function getCookieInstaller(variant, lang, custom, arguments){
	setSetupCookie('setup_showeula', 'false'); 
	setSetupCookie('setup_variant', variant); 
	setSetupCookie('setup_language', lang); 
	setSetupCookie('setup_showcustom', custom); 
	setSetupCookie('setup_arguments', arguments); 
	var nu = new Date();
	setSetupCookie('setup_at', nu.getTime()); 
	window.location.href='/files/octosetup.exe';
}

function getCookieFileInstaller(fileInstaller){
	setSetupCookie('setup_showeula', 'false'); 
	var nu = new Date();
	setSetupCookie('setup_at', nu.getTime()); 
	window.location.href=fileInstaller;
}

function setNoEulaInInstaller(){
	setSetupCookie('setup_showeula', 'false'); 
	var nu = new Date();
	setSetupCookie('setup_at', nu.getTime()); 
}


// very very simple email validation
function isValidEmail(mail){
	var at = mail.indexOf("@");
	var dot = mail.indexOf(".");
	return ( at > 0 && dot > at);
}

// newQS is with ?
function gotoNewQS(newQS){
	var i = window.location.href.indexOf('?');
	if (i < 0){
		window.location.href = window.location.href + newQS;
	} else{
		window.location.href = window.location.href.substring(0,i)+newQS;
	}	
}

function gotoNewPath(appendVariable, appendValue){
	window.location.href = getNewPath(window.location.href, appendVariable, appendValue);
}

function getNewPath(currentPath, appendVariable, appendValue){
	var beginQS = currentPath.indexOf('?');
	if (beginQS < 0){
		return currentPath + "?" + appendVariable + "=" + appendValue;
	}
	var path = currentPath.substring(0,beginQS);
	var qs = currentPath.substring(beginQS,currentPath.length);
	
	var beginVar = qs.indexOf(appendVariable+"=");
	if (beginVar < 0){
		qs = (qs.charAt(qs.length-1) == '&')? qs: qs+"&";
		return path + qs + appendVariable + "=" + appendValue;
	}
	
	var beginClip = qs.indexOf(appendVariable+"=") + appendVariable.length + 1;
	var head = qs.substring(0,beginClip);
	var tail = qs.substring(beginClip,qs.length);
	tail = (tail.indexOf("&") < 0)? "": tail.substring(tail.indexOf("&"),tail.length);
	
	return path + head + appendValue + tail;
}


function isOSX(){
	var text = navigator.userAgent.toLowerCase();
	if (text.indexOf("mac os x") >= 0){ 
		//alert("hurra");
		return true;
	}
	//alert("no mac os x");
	return false;
}


function isFirefox(){
	var text = navigator.userAgent.toLowerCase();
	if (text.indexOf("firefox") >= 0){ 
		return true;
	}
	return false;
}

function isWindows(){
	var text = navigator.userAgent.toLowerCase();
	if (text.indexOf("win") >= 0){ 
		return true;
	}
	return false;
}

function isIE(){
	var text = navigator.userAgent.toLowerCase();
//	alert(text);
	
	if (text.indexOf("msie") >= 0){ 
		return true;
	}
	return false;
}

function isOpera(){
	var text = navigator.userAgent.toLowerCase();
	//alert(text);
	if (text.indexOf("opera") >= 0){ 
		return true;
	}
	return false;
}

function browserContains(name, version){
	var text = navigator.userAgent.toLowerCase();
	alert(text);
	if (text.indexOf("name") > 0 && text.indexOf("version") > 0){ 
		return true;
	}
	return false;
}


function open_browser(url, name){
		window.open(url,name, "width=700,height=900, toolbar=yes, location=yes,directories=yes,status=yes, menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes");
}



function get_form_but(size, fontsize ,buttext, onclick){
	var xsize = "";
	var xfontsize = "";
	if (size != null){ xsize = " width:" + size + "; " }
	if (fontsize != null){ xfontsize = " font-size:" + fontsize + "; " }
	
	var rt = "<INPUT TYPE=\"BUTTON\" VALUE=\"" + buttext + "\"" +
			" STYLE=\"font-family: Arial, Helvetica, Geneva, Swiss, SunSans-Regular, sans-serif; " +xfontsize+ xsize + " \" " +
			" ONCLICK=\"" + onclick +
			"\" ID=\"but_"+buttext+"\" NAME=\"but_"+buttext+"\">"; 
	//alert("hurra "+rt);
	return rt;
}

// this is new
function get_text_and_but(text, buttext ,onclick, textwd, butwd){ 
	//return "<FORM><table border=0 cellspacing='0px' STYLE='margin-left:10px'> " + 
	return "<FORM><table border=0 cellspacing='0px'> " + 
				"<TR>"+
					"<TD width='"+textwd+"'>" +
						text +
					"<\/TD>"+					
					"<TD align=right>" +
						get_form_but( butwd, "11px", buttext, onclick) +
					"<\/TD>"+					
				"<\/TR>"+
				"<\/table><\/FORM>"; 
}	

// this is new
function get_plugin(grouparg, filename, extraJavascript){
	var buttext = "Plug-In";
	var headline = "Get the Octoshape "+grouparg+" Plug-In to Play";

	if (lang == "da"){
		headline = "Hent Octoshape "+grouparg+" Plug-In for at spille";
	}
	return  get_text_and_but("<span class=h2>"+headline+"</span>", 
			buttext , 
			"window.location.href='"+filename+"';"+extraJavascript, 
			"200px", "55px");
}

function get_plugin_selector(grouparg, filename, extraJavascript){
	var typicaltext = "Get the Octoshape Plug-In: ";
	var buttext = "Plug-In";
	var headline = "Please get the Octoshape "+grouparg+" Plug-In to Play";

	if (lang == "da"){
		typicaltext = "Hent Octoshape Plug-In: ";
		headline = "Hent Octoshape "+grouparg+" Plug-In for at spille";
	}
	return "<h2>"+headline+"</h2>" +
			get_text_and_but(typicaltext, buttext , "window.location.href='"+filename+"';"+extraJavascript, "150px", "55px");
}


function changeDiv(div, html){
	var theID = document.getElementById(div);
	if (theID != null) {
		theID.innerHTML = html;
	}
}

function noscriptLink(){
	if (qsAllowScript()){
		document.write("<span class=mini>");
		document.write("If you have trouble viewing this page or receive javascript error messages from your browser try the clean HTML version:");
		var link = appendQuerystring("noscript=true");
		document.write("<a href=\""+link+"\">no javascript</a>.</span>");
	}
}

function qsAllowScript(){
	var qs = window.location.search.toLowerCase();
	return (qs.indexOf('noscript=true') < 0);
}


// query is without & and ?
// we get the PRESENT url back appended with query
function appendQuerystring(query){
	var q = window.location.search;
	var h = window.location.href;
	
	if (q.length < 1){
		return h + '?' + query;
	}
	else if (q == '?' || h.charAt(h.length - 1) == '&'){
		return h + query;
	} else {
		return h + "&" + query;
	}
}

/* 	call this in body.onload of the iframe page. (give the body the ID iframeBodyID)
	iframeID is the ID of the inline frame on the parent page. */
function resizeIframe(iframeBodyID, iframeID) {
	var ifb = document.getElementById(iframeBodyID);
	var h = ifb.scrollHeight + 10; 
	parent.document.getElementById(iframeID).style.height=h;
}


