QuePort = window.QuePort || {};

AUI().use(
	'node',
	function(A) {
		QuePort.Theme = {

			init: function() {
				var instance = this;
				instance.handleDate();
				instance.AUI = A;
			},
			checkValue: function(val, obj) {
				if (obj.value == val) {
					obj.value = "";
				}
			},
			checkOutValue: function(val, obj) {
				if (obj.value.match(/^\s*$/)) {
					obj.value = val;
				}
			},
			handleDate: function() {
				var curDate = new Date();
				var curDay = curDate.getDate() < 10 ?  "0" + curDate.getDate() : curDate.getDate();
				var curMonth = curDate.getMonth() < 9 ?  "0" + (curDate.getMonth() + 1) : curDate.getMonth() + 1;
				var curFullDate = curDay + "." + curMonth + "." + curDate.getFullYear();
				var curMinutes = curDate.getMinutes() < 10 ? "0" + curDate.getMinutes() : curDate.getMinutes();
				var curTime = curDate.getHours() + ":" + curMinutes;
				A.one("#date").set("innerHTML", "<span>" + curFullDate + "  " + curTime + " Uhr</span>");
			}			
		}
	}
);




/*  AD STUFF  */

var oms_site;
var oms_zone = "nationalnews";
var btcode;
var oms_gallery = "0";
window.isGallery = false;

var qp_docid;
var qp_ressort;

var showSuperbanner = true;
var showSkyscraper = true;
var sz_superBanner = "728x90;tile=1;";
var sz_skyScraper = "120x600;tile=2;";

var adlWallPaperLeft = 815;
var adlink_randomnumber;

var sbframe;
var sscframe;

var ivw_code;
var ivw_code_prefix;
var ivw_code_suffix;


function initAdStuff(oms_site_ConfigParam) {
	/* set oms_site */
    if (typeof(oms_site_ConfigParam)!="undefined" && oms_site_ConfigParam != "") {
        oms_site = oms_site_ConfigParam;
    } else {
        var oms_siteSplit = window.location.hostname.split(".");
        if (oms_siteSplit.length > 2) {
            oms_site = "oms." + oms_siteSplit[oms_siteSplit.length - 2] + "." + oms_siteSplit[oms_siteSplit.length - 1];
        } else {
            oms_site = "oms." + oms_siteSplit[0] + "." + oms_siteSplit[1];
        }
    }
    
    if (typeof(adlink_randomnumber) == "undefined") {
        adlink_randomnumber=Math.floor(Math.random()*10000000000)
    }
	
	if(typeof(WLRCMD)=="undefined"){var WLRCMD="";}
	
	window.isIE6 = false;
	if (Liferay.Browser.isIe()) {
		if (Liferay.Browser.getMajorVersion() == "6") {
			window.isIE6 = true;
		}
	}
}

function checkDetailDocumentValues() {
	/* 
	 * Die Variablen qpomszone, qpdocid, qpgallery, 
	 * werden durch ein Detail-Portlet via Html-Header-Bridge gesetzt 
	 * und sind dementsprechend nur auf einer Detailseite verfuegbar.
	 */ 
	if(typeof(qpomszone)!="undefined"){oms_zone=qpomszone;}
	if(typeof(qpdocid)!="undefined"){qp_docid=qpdocid;}else{qp_docid=""}
	if(typeof(qpgallery)!="undefined"){oms_gallery=qpgallery;if (oms_gallery == "1") {window.isGallery = true;}}
	if(typeof(qpbtcode)!="undefined"){btcode=qpbtcode;}
	if(typeof(qpivwcode)!="undefined"){ivw_code_suffix=qpivwcode;}
	if(typeof(qpressort)!="undefined"){qp_ressort=qpressort;}else{qp_ressort=""}
}

function addBanner(ad, path, frame) {
    if (ad == "Superbanner") {
		document.write('<scr'+'ipt type="text/javascript" src="http://ad.de.doubleclick.net/adj/' + oms_site + '/' + oms_zone + ';oms=' + oms_zone + ';nielsen=7;dcopt=ist;' + WLRCMD + 'sz=' + sz_superBanner + ';ord='+adlink_randomnumber + '?"><\/scr'+'ipt>');
    } 
	if (ad == "Skyscraper") {
    	document.write('<scr'+'ipt type="text/javascript" src="http://ad.de.doubleclick.net/adj/' + oms_site + '/' + oms_zone + ';oms=' + oms_zone + ';nielsen=7;' + WLRCMD + 'sz=' + sz_skyScraper + ';ord='+adlink_randomnumber + '?"><\/scr'+'ipt>');
    }
	if (frame) {
		sscframe = document.createElement("iframe");
		sscframe.src = path + "/oms.jsp?oms_site=" + oms_site + "&oms_zone=" + oms_zone + "&WLRCMD=" + WLRCMD + "&sz_sb=" + sz_superBanner + "&sz_ss=" + sz_skyScraper + "&adlink_randomnumber=" + adlink_randomnumber + "&adlWallPaperLeft=" + adlWallPaperLeft;
		sscframe.width = "100%";
		sscframe.height = 10000;

		sscframe.border = "0";
		sscframe.frameborder = "0";
		sscframe.scrolling = "no";
		document.getElementById("iFrameHolder").appendChild(sscframe);
		tile = 3;
	}
	//ssc.appendChild(sscframe);
}

function checkAdlWallpaper() {
	if(typeof(adlWallPaper)!="undefined" && adlWallPaper == 3){
		QuePort.Theme.AUI.one("#oms_skyscraper").addClass("top");
		QuePort.Theme.AUI.one("#oms_superbanner").addClass("wallpaper");
		QuePort.Theme.AUI.one("body").css("background-color", adlbgcolor);
	}
}

function refreshOMSFrame() {
	if (!isIE6 && isGallery && typeof(sscframe)!="undefined") {
		sscframe.src = sscframe.src;
	}
}

function refreshIVW() {
	if (typeof(IVW) != "undefined" && IVW != null && document.getElementById("szmimages") != "undefined" && document.getElementById("szmimages") != null) {
		document.getElementById("szmimages").src = IVW + "?r=" + escape(document.referrer) + "&d=" + (Math.random()*100000);
	}
}
