function closeHelp() {
   w = window.open("about:blank","help", "width=626, height=404");
   w.close();
}

function openHelp2(ID) {
	myWindow = window.open("/pf_help/WebHelp/pf.htm#"+ID+".htm","help", "width=826, height=604,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
        myWindow.focus();
}

function openContact() {
    window.open('/servlet/doc?Structure=PF_Popup_Frameset_Kontakt&amp;pageid=FMON-5S6EYD&amp;frbot=PF_Bot_Luk&amp;iframe=no','kontakt','scrollbars=yes,width=362,height=303,status=no,toolbar=no,menubar=0,location=no'); 
}

function openChat() {
		 var htmlcPath = "http://online-kundeservice.unox.dk/solidus/htmlc/jsp/upfront.jsp?";
     // var htmlcPath = "http://194.255.7.7/solidus/htmlc/jsp/upfront.jsp?";
     // var htmlcPath = "/servlet/doc?PageID=FMON-5R9AGJ&amp;";
   var windowWidth = 428;
   var windowHeight = 420;
     var params = "location=no,status=no,toolbar=no,menubar=no,bars=no,resizable=no,width=" + windowWidth + ",height=" + windowHeight;
     var upfrontURL = htmlcPath + "tmstmp=" + jsGetTimeStamp();
     window.open( upfrontURL, "UpfrontHelper", params);
}

function jsGetTimeStamp(){
     var now = new Date();
     var timeStamp = ""+now.getYear()+now.getMonth()+now.getDay()+now.getHours()+now.getMinutes()+now.getSeconds()+jsGetRandom();
     return timeStamp;
}

function jsGetRandom(){
     var random = 1000 * Math.random();
     return Math.floor(random);
}

function setMenu(cat3, pageId){
	if(cat3 != "" && cat3 != "MinKonto") {
		if(document.getElementById('menu_'+cat3))
			document.getElementById('menu_'+cat3).className = "active nostyle";
		if(document.getElementById(pageId))
			document.getElementById(pageId).className="active nostyle";
	}
}

function numbersOnly(){
	if (window.event.keyCode < 48 || window.event.keyCode > 57) {
		window.event.keyCode = 0;
		return false;
	}
}
	
function checkEmail(strValue) {		
	var regexp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return regexp.test(strValue);
}
	
function isBetween(iLow, iUp, iVal) {
	if (iVal > iLow && iVal < iUp)
		return true;
	else
		return false;
}

function ffToInt(strValue) {
	var len = strValue.length;
	if (strValue.substr(0,1) == '0')
		return parseInt(strValue.substr(1,len-1));
	else
		return parseInt(strValue);
}

function checkCpr(strValue) {	
	var dd =  ffToInt(strValue.substr(0,2));
	var mm = ffToInt(strValue.substr(2,2));
	var aa =  ffToInt(strValue.substr(4,2));
	var isDate = isBetween(0,32,dd) && isBetween(0,13,mm) && isBetween(-1,100,aa);

	a = strValue.substr(0,1);
	b = strValue.substr(1,1);
	c = strValue.substr(2,1);
	d = strValue.substr(3,1);
	e = strValue.substr(4,1);
	ff = strValue.substr(5,1);
	g = strValue.substr(6,1);
	h = strValue.substr(7,1);
	i = strValue.substr(8,1);
	j = strValue.substr(9,1);

	// Do modulus calculation check
	test = a*4+b*3+c*2+d*7+e*6+ff*5+g*4+h*3+i*2+j*1;
	// rest should be 0 for a valid cpr
	rest = test % 11;

	if (isDate && rest==0)
		return(true);
	else 
		return(false);
}

function checkCvr(strValue) {	
	
	a = strValue.substr(0,1);
	b = strValue.substr(1,1);
	c = strValue.substr(2,1);
	d = strValue.substr(3,1);
	e = strValue.substr(4,1);
	ff = strValue.substr(5,1);
	g = strValue.substr(6,1);
	h = strValue.substr(7,1);	

	// Do modulus calculation check
	test = a*2+b*7+c*6+d*5+e*4+ff*3+g*2+h*1;
	// rest should be 0 for a valid cpr
	rest = test % 11;

	if (rest==0)
		return(true);
	else 
		return(false);
}

function setArea(area)
{
var largeExpDate = new Date();
largeExpDate.setTime(largeExpDate.getTime() + (31 * 24 * 3600 * 1000));
SetCookie('area', area, largeExpDate);
return true;
}

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = "/"; //(argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" +
expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? ("; domain=unox.dk") : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
