/*
General functions that can be used on Passagen.se
*/

window.google_analytics_uacct = "UA-10282305-5";
var timeStamp = getTimeFormatted();

function getTimeFormatted() {
	var d = new Date();
	var h = d.getHours();
	var m = d.getMinutes();
	var s = d.getSeconds();
	var ms = d.getMilliseconds();
	return h.toString() + m.toString() + s.toString() + ms.toString();
}

/* ----- Get cookie functions ----- */

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

/* ----- Print ad functions ----- */

function new_printAddJS(width, height, tile, adress, clusterid, bhid, pos, kw) {

	var keyword = (kw!=undefined) ? kw : "null";
	var position = (pos!=undefined) ? pos : "null";
	
	var ac = getCookie("ac");

	var reg = /a=(.*):s=([M|F])/i;
	var ar = reg.exec(ac);
	var age ="0";
	var gender = "0";
	var status = "0";
	
	if (ar!=null) {
		age = ar[1];
		gender = ar[2];
		status = 1;
	}
	
	var clusterstr = "";
	if (clusterid != null && clusterid.length > 0) {
		clusterstr = "/"+clusterid;
	}
	adress += clusterstr;
	
	if (tile == 1) // To check if banner is a topbanner or not. The topbanner has a "dcopt=ist" value that the others dont have.
	{
		if (top.location==document.location){
			document.write('<img src="http://www.passagen.se/common/img/annons_45x5.gif" alt="Annons" style="display: block; margin-bottom: 1px;" />');
		}
	var src = "http://ad.se.doubleclick.net/adj/P5502.passagen.se/"+adress+"/;sz="+width+"x"+height+";gender="+gender+";age="+age+";status="+status+";tile="+tile+";dcopt=ist;ord=" + timeStamp + "?";
	}
	else if(tile == 2)
	{
	position = (position=='null') ? 'rightsky' : position;
	var src = "http://ad.se.doubleclick.net/adj/P5502.passagen.se/"+adress+"/;sz="+width+"x"+height+",160x600;gender="+gender+";age="+age+";status="+status+";tile="+tile+";kw="+keyword+";pos="+position+";ord=" + timeStamp + "?";		
	}
	else if(tile == 3)
	{
	var src = "http://ad.se.doubleclick.net/adj/P5502.passagen.se/"+adress+"/;sz="+width+"x"+height+",468x60,468x240,468x360;static=1;gender="+gender+";age="+age+";status="+status+";bhid="+bhid+";tile="+tile+";ord=" + timeStamp + "?";		
	}	
	document.write('<script type="text\/javascript" src=');
	document.write(src);
	document.write('><\/script>');
}

/* ----- Popup functions ----- */

function PopItUp (url,w,h) {
	var winstr='location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,width='+w+',height='+h;
	window.open(url,'fonster',winstr);
	void(0);
}

function PopNoScroll (url,w,h) {
	var winstr='location=no,menubar=no,scrollbars=no,status=no,toolbar=no,width='+w+',height='+h;
	window.open(url,'fonster',winstr);
	void(0);
}

function PopItUpRedirect (url,w,h,url2) {
	var winstr='location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,width='+w+',height='+h;
	document.location=url2;
	window.open(url,'fonster',winstr);
	void(0);
}

function PopNoScrollRedirect (url,w,h,url2) {
	var winstr='location=no,menubar=no,scrollbars=no,status=no,toolbar=no,width='+w+',height='+h;
	document.location=url2;
	window.open(url,'fonster',winstr);
	void(0);
}

function NewWin (url) {
	window.open(url,'fonster','location=yes,status=yes,menubar=yes,toolbar=yes,resizable=yes,scrollbars=yes');
	void(0);
}

function User () {
  document.write('<script src="http://www.passagen.se/ta/js/global/user.shtml?'+Math.random()+'" type="text/javascript"></script>');
}
