//preview script file


function openChromeWindow(url,w,h,t) {
	fullWin =
	window.open(url,"fullWin",'toolbar='+t+',location=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+w+',height='+h+'');


}




function sendemail(id) {
	mypath = "http://www.kenoshanews.com/scripts/edoris/edoris.dll?tem=sendemail&docid=" + id;

	fullWin =
	window.open(mypath,"fullWin","toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=500");
}



function printart(id) {
	mypath = "http://www.kenoshanews.com/scripts/edoris/edoris.dll?tem=printart&docid=" + id;

	fullWin =
	window.open(mypath,"fullWin","toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=600");
}


function arcprint2(id) {
	mypath = "http://www.kenoshanews.com/scripts/edoris/edoris.dll?tem=arcprint2&docid=" + id;

	fullWin =
	window.open(mypath,"fullWin","toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=600");
}


function arcprint(id) {
	mypath = "http://www.kenoshanews.com/scripts/edoris/edoris.dll?tem=arcprint&docid=" + id;

	fullWin =
	window.open(mypath,"fullWin","toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=600");
}



function reportabuse(topicid,postid) {
	mypath = "http://www.kenoshanews.com/scripts/edoris/edoris.dll?tem=reportabuse&topicid=" + topicid + "&postid=" + postid;

	fullWin =
	window.open(mypath,"fullWin","toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=600");
}


//Set .css file

function setcss(ccsfile,forumcss)
{
	dojo.io.cookie.setCookie('currentcss', ccsfile, 1000,'/eplanner/');
	dojo.io.cookie.setCookie('currentforumcss', forumcss, 1000,'/eplanner/');
	document.location.href = 	document.location.href;
}

//Get .css file
function getcss(defaultccsfile,defaultforumcss)
{
	var whichcss = dojo.io.cookie.getCookie('currentcss');
	var whichforumcss = dojo.io.cookie.getCookie('currentforumcss');

	if(whichcss == null)
		whichcss = defaultccsfile;
	else if (whichcss.length < 1)
		whichcss = defaultforumcss;
	if (defaultccsfile != "none")
		document.writeln('<style type="text/css" title="currentStyle" media="screen">@import "'+whichcss+'";</style>');
	if(whichforumcss == null)
		whichforumcss = defaultforumcss;
	else if (whichforumcss.length < 1)
		whichforumcss = defaultforumcss;
	if (defaultforumcss != "none")
		document.writeln('<link rel="stylesheet" type="text/css" href="'+whichforumcss+'">');
}


//search script

function HakuK(text)
{
	text.form.action = '/scripts/edoris/edoris.dll';
	text.form.method = 'post';
	text.form.submit();
	
	/*
	var text = document.getElementById(text_id);

	var hidden = document.createElement("input"); hidden.type = 'hidden';
	hidden.name = 'app'; hidden.value = 'server';
	text.form.appendChild(hidden);

	var hidden = document.createElement("input"); hidden.type = 'hidden';
	hidden.name = 'com'; hidden.value = 'search';
	text.form.appendChild(hidden);
	
	var hidden = document.createElement("input"); hidden.type = 'hidden';
	hidden.name = 'tem'; hidden.value = 'lsearch';
	text.form.appendChild(hidden);

	var hidden = document.createElement("input"); hidden.type = 'hidden';
	hidden.name = 'search_maxhits'; hidden.value = '5';
	text.form.appendChild(hidden);
	
	text.name = text_id;
	text.form.action = '/scripts/edoris/edoris.dll';
	text.form.method = 'post';
	text.form.submit();
*/
}

function HakuG(text_id)
{
	var text = document.getElementById(text_id);

	var hidden = document.createElement("input");
	hidden.type = 'hidden';
	hidden.name = 'hl'; hidden.value = 'fi';
	text.form.appendChild(hidden);

	text.name = 'q';
	text.form.action = 'http://www.google.com/search';
	text.form.method = 'get';
	text.form.submit();
}

function HakuNewG(text)
{
	var hidden = document.createElement("input");
	hidden.type = 'hidden';
	hidden.name = 'hl'; hidden.value = 'fi';
	text.form.appendChild(hidden);

	text.name = 'q';
	text.form.action = 'http://www.google.com/search';
	text.form.method = 'get';
	text.form.submit();
}

function HakuX(f)
{
	var text = f.search_articletext;
	
	if ( text.value != "" ) {
		if ( f.haku[0].checked )
			HakuK(text);
		else
			HakuNewG(text);
	}
}

function checkEnter(e, f)
{ 
	var characterCode;

	if( e && e.which ){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if( characterCode == 13 ){ //if generated character code is equal to ascii 13 (if enter key)
		text = f.search_articletext;
		/*
		f = document.getElementById(form_id);
		text = f.search_articletext;
		*/
		if ( text.value != "" ) {
			HakuX( f );
			return false;
		}
		else
			return false;
	}
	return true; 	
}

// simple browser check
var whichbrowser = navigator.userAgent.toLowerCase();
var isnetscape = false;
var isie = false;
var isie55up = false;
var isopera = false;
if (whichbrowser.indexOf("msie") != -1) {
  isie = true;
    fixi(1500);
   
  if (parseInt(navigator.appVersion) > 3 && whichbrowser.indexOf("msie 5.0") != 
	    -1 && whichbrowser.indexOf("msie 4") != -1)
  {
    isie55up = true;
  }
} 
else if (whichbrowser.indexOf('mozilla')!=-1) {
  isnetscape = true;
}
else if (whichbrowser.indexOf('opera')!=-1) {
  isie = true;
	isopera = true;
}

// Toggle an image's visibility
function toggleimage(imgcontainer,imgname,x,y) {
	oldimg = document.images["largeimageimg"].src;
	document.images["largeimageimg"].src = imgname;
	if (x != -1 && y != -1)
		setobjectonscreen(imgcontainer,x,y);
	if (oldimg.indexOf(imgname) < 0 && imgname.length > 0) { // New image
		showlayer(imgcontainer);
	}
	else {
		showhidelayer(imgcontainer);
	}
}

// Toggle a layers visibility
function showhidelayer(chosenlayer) {
  if (document.getElementById(chosenlayer).style.visibility == 'hidden') {
		document.getElementById(chosenlayer).style.visibility = 'visible';  
  }
  else {
		document.getElementById(chosenlayer).style.visibility = 'hidden';
  }
} 

// check if an object is visible on the screen, if not then reposition it
function setobjectonscreen(layername,xoffset,yoffset) {

  var layername;
	var layerstyle = document.getElementById(layername).style;
  var topposition;
  var leftposition;
  var screenwidth;
  var screenheight;
  var currentleft;
  var currenttop;

	if (typeof window.pageXOffset != 'undefined'){
		topposition = window.pageYOffset;
		leftposition = window.pageXOffset;
  }
  else {
		//topposition = window.document.body.scrollTop;
		//leftposition = window.document.body.scrollLeft;
		topposition = document.documentElement.scrollTop;
		leftposition = document.documentElement.scrollLeft;
  }

  if (isnetscape == true) {
    screenwidth = window.innerWidth;
    screenheight = window.innerHeight;
  }
  else {
    screenwidth = document.body.clientWidth;
		screenheight = document.body.clientHeight;
  }

  currentleft = parseInt(layerstyle.left);
  currenttop = parseInt(layerstyle.top);

	  topposition = topposition + yoffset;
	  leftposition = leftposition + xoffset;
	 
	  layerstyle.left = leftposition + 'px';
	  layerstyle.top= topposition + 'px';

	/*if (!currentleft || currentleft > (screenwidth-leftposition) || currentleft < leftposition || !currenttop || currenttop> (screenheight-topposition) || currenttop < topposition)
	{
	  topposition = topposition + yoffset;
	  leftposition = leftposition + xoffset;
	 
	  layerstyle.left = leftposition + 'px';
	  layerstyle.top= topposition + 'px';
	} */
}

// shows a layer
function showlayer(layer) {
	document.getElementById(layer).style.visibility = 'visible'; 
}

// hides a layer
function hidelayer(layer) {
	document.getElementById(layer).style.visibility = 'hidden';
}

//date script

 function dateFormat(aDate, displayPat){
    /********************************************************
    *   Valid Masks:
    *   !mmmm = Long month (eg. January)
    *   !mmm = Short month (eg. Jan)
    *   !mm = Numeric date (eg. 07)
    *   !m = Numeric date (eg. 7)
    *   !dddd = Long day (eg. Monday)
    *   !ddd = Short day (eg. Mon)
    *   !dd = Numeric day (eg. 07)
    *   !d = Numeric day (eg. 7)   
    *   !yyyy = Year (eg. 1999)
    *   !yy = Year (eg. 99)
   ********************************************************/

    intMonth = aDate.getMonth();
    intDate = aDate.getDate();
    intDay = aDate.getDay();
    intYear = aDate.getFullYear();

    var months_long =  new Array ('January','February','March','April',
       'May','June','July','August','September','October','November','December')
    var months_short = new Array('Jan','Feb','Mar','Apr','May','Jun',
       'Jul','Aug','Sep','Oct','Nov','Dec')
    var days_long = new Array('Sunday','Monday','Tuesday','Wednesday',
       'Thursday','Friday','Saturday')
    var days_short = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat')

    var mmmm = months_long[intMonth]
    var mmm = months_short[intMonth]
    var mm = intMonth < 9?'0'+ (1 + intMonth) + '':(1+intMonth)+'';
    var m = 1+intMonth+'';
    var dddd = days_long[intDay];
    var ddd = days_short[intDay];
    var dd = intDate<10?'0'+intDate+'':intDate+'';
    var d = intDate+'';
    var yyyy = intYear;

    century = 0;
    while((intYear-century)>=100)
        century = century + 100;

    var yy = intYear - century
    if(yy<10)
        yy = '0' + yy + '';

    displayDate = new String(displayPat);

    displayDate = displayDate.replace(/!mmmm/i,mmmm);
    displayDate = displayDate.replace(/!mmm/i,mmm);
    displayDate = displayDate.replace(/!mm/i,mm);
    displayDate = displayDate.replace(/!m/i,m);
    displayDate = displayDate.replace(/!dddd/i,dddd);
    displayDate = displayDate.replace(/!ddd/i,ddd);
    displayDate = displayDate.replace(/!dd/i,dd);
    displayDate = displayDate.replace(/!d/i,d);
    displayDate = displayDate.replace(/!yyyy/i,yyyy);
    displayDate = displayDate.replace(/!yy/i,yy);

    return displayDate;
}

//right image class

function isset ( test )
{
	return (typeof(test)!='undefined'&&test!=null);
}

function fixi(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);

} 

function ChooseClass(image,descr)
{
	if(!isset(descr))
		descr = true;
		

	var div = image.parentNode;
	
	var id = image.id.substring(5);
	

	// horizontal images, only for main & first images.
	if(( id == 1 || id == 'main' ) && image.width/image.height > 5/4)
	{
		image.style.width = '100%';
		if(descr)
			div.className = 'imgcontainer_h';
			// Handle also caption
	}
	else
	{
		if(id == 1 || id == 'main') // for the first image
			setTimeout(Scale(image,200,350),5000);
		else
			setTimeout(Scale(image,150,150),5000);

		if(descr)
		{
			div.className = 'imgcontainer_v'; // Handle also caption
			div.style.width = image.width+"px"; // Make sure the caption doesn't expand the div
		}
	}

}
function Scale(image,w,h)
{
	if( (image.width/image.height) > (w/h) )
		image.width = w;
	else
		image.height = h;
}
function TilausSetDate(input_id)
{
	var input = document.getElementById(input_id);
	var myDate=new Date();
	input.value = myDate.getDate() + "." + (1+myDate.getMonth()) + "." + myDate.getFullYear();
}

//linkkien päiväyksen muotoilu
function ShowDate(time)
{
	var out = new String();

	var d = new Date();
	var now = new Date();
	//d.setTime(time*1000);
	if(time.length > 0)
	{
		d.setFullYear(time.substr(0,4));
		d.setMonth(time.substr(4,2)-1);
		d.setDate(time.substr(6,2));
		d.setHours(time.substr(8,2));
		d.setMinutes(time.substr(10,2));
		d.setSeconds(time.substr(12,2));
		
		if(d.getDate() != now.getDate() || d.getMonth() != now.getMonth())
			out += d.getDate() + "." + (d.getMonth()+1) + ". ";
		
		// write time with leading zeros
		if(d.getHours() < 10)
			out += "0";
		out += d.getHours() + ":";
		if(d.getMinutes() < 10)
			out += "0";
		out += d.getMinutes();
			
		document.write(out);
	}
}

function ShowDateNew(time)
{
	if(time.length > 0)
	{
		var out = new String();
		var ampm = new String();
		var d = new Date();
	
		ampm = " a.m.";

		d.setFullYear(time.substr(0,4));
		d.setMonth(time.substr(4,2)-1);
		d.setDate(time.substr(6,2));
		d.setHours(time.substr(8,2));
		d.setMinutes(time.substr(10,2));
		d.setSeconds(time.substr(12,2));
		
		out = dateFormat(d, "!mmmm !d, !yyyy")+" | ";



		if(d.getHours() == 12){
			ampm = " p.m.";
	}

		if(d.getHours() > 12){
			d.setHours(d.getHours()-12);
			ampm = " p.m.";
		}	

	
		if(d.getHours() < 10)
			out += "";

		if (d.getHours() == 0){
			out += "12:";
		}	
		
		else{
		out += d.getHours() + ":";
		}

		if(d.getMinutes() < 10)
			out += "0";
		out += d.getMinutes();
		out += ampm;
		document.write(out);
	}
}

function ShowTimestamp(time)
{
	if(time.length > 0)
	{
		var out = new String();
		var ampm = new String();
		var d = new Date();
	
		ampm = " a.m.";

		d.setFullYear(time.substr(0,4));
		d.setMonth(time.substr(4,2)-1);
		d.setDate(time.substr(6,2));
		d.setHours(time.substr(8,2));
		d.setMinutes(time.substr(10,2));
		d.setSeconds(time.substr(12,2));
		
		out = dateFormat(d, "!mmmm !d, !yyyy")+", ";



		if(d.getHours() == 12){
			ampm = " p.m.";
	}

		if(d.getHours() > 12){
			d.setHours(d.getHours()-12);
			ampm = " p.m.";
		}	

	
		if(d.getHours() < 10)
			out += "";

		if (d.getHours() == 0){
			out += "12:";
		}	
		
		else{
		out += d.getHours() + ":";
		}

		if(d.getMinutes() < 10)
			out += "0";
		out += d.getMinutes();
		out += ampm;
		document.write(out);
	}
}

function ShowShortDate(time)
{
	if(time.length > 0)
	{
		var out = new String();
		var ampm = new String();
		var d = new Date();
	
		ampm = " a.m.";

		d.setFullYear(time.substr(0,4));
		d.setMonth(time.substr(4,2)-1);
		d.setDate(time.substr(6,2));
		d.setHours(time.substr(8,2));
		d.setMinutes(time.substr(10,2));
		d.setSeconds(time.substr(12,2));
		
		out = dateFormat(d, "!m/!d")+" ";



		if(d.getHours() == 12){
			ampm = " p.m.";
	}

		if(d.getHours() > 12){
			d.setHours(d.getHours()-12);
			ampm = " p.m.";
		}	

	
		if(d.getHours() < 10)
			out += "";

		if (d.getHours() == 0){
			out += "12:";
		}	
		
		else{
		out += d.getHours() + ":";
		}

		if(d.getMinutes() < 10)
			out += "0";
		out += d.getMinutes();
		out += ampm;
		document.write(out);
	}
}



function ShowTime(time)
{
	if(time.length > 0)
	{
		var out = new String();
		var ampm = new String();
		var d = new Date();
	
		ampm = " a.m.";

		d.setFullYear(time.substr(0,4));
		d.setMonth(time.substr(4,2)-1);
		d.setDate(time.substr(6,2));
		d.setHours(time.substr(8,2));
		d.setMinutes(time.substr(10,2));
		d.setSeconds(time.substr(12,2));
		
		out = "";



		if(d.getHours() == 12){
			ampm = " p.m.";
	}

		if(d.getHours() > 12){
			d.setHours(d.getHours()-12);
			ampm = " p.m.";
		}	

	
		if(d.getHours() < 10)
			out += "";

		if (d.getHours() == 0){
			out += "12:";
		}	
		
		else{
		out += d.getHours() + ":";
		}

		if(d.getMinutes() < 10)
			out += "0";
		out += d.getMinutes();
		out += ampm;
		document.write(out);
	}
}



function ShowDateShort(time)
{
	if(time.length > 0)
	{
		var out = new String();
		var ampm = new String();
		var d = new Date();
	
		ampm = " a.m.";

		d.setFullYear(time.substr(0,4));
		d.setMonth(time.substr(4,2)-1);
		d.setDate(time.substr(6,2));
		d.setHours(time.substr(8,2));
		d.setMinutes(time.substr(10,2));
		d.setSeconds(time.substr(12,2));
		
		out = dateFormat(d, "!m/!d/!yy");

		document.write(out);
	}
}


function ShowDateLabel(time)
{
	if(time.length > 0)
	{
		var out = new String();
		var d = new Date();
	

		d.setFullYear(time.substr(0,4));
		d.setMonth(time.substr(4,2)-1);
		d.setDate(time.substr(6,2));
		d.setHours(time.substr(8,2));
		d.setMinutes(time.substr(10,2));
		d.setSeconds(time.substr(12,2));
		
		out = dateFormat(d, "!dddd, !mmmm !d");

		document.write(out);
	}
}


function CShowImage(container, id, src, txt)
{

//alert(unescape(txt));
//onLoad="ChooseClass(this)"

	var container = document.getElementById(container);
//	container.innerHTML = '<img class="news_images" id="'+id+'" src="'+src+'" onLoad="ChooseClass(this)"/><br><span class="photocaption">'+txt+'</span>';
	container.innerHTML = '<table border="0" width="325"><tr><td width="200" margin="20"><img class="articlephoto" width="180" id="'+id+'" src="'+src+'" /></td><td width="120" valign="bottom"><span class="photocaption">'+txt+'</span></td></tr></table>';

}


function CShowImageComm(container, id, src, txt)
{

//alert(unescape(txt));
//onLoad="ChooseClass(this)"

	var container = document.getElementById(container);
//	container.innerHTML = '<img class="news_images" id="'+id+'" src="'+src+'" onLoad="ChooseClass(this)"/><br><span class="photocaption">'+txt+'</span>';
	container.innerHTML = '<table border="0" width="325"><tr><td width="200" margin="20"><img class="articlephoto" width="180" id="'+id+'" src="'+src+'" /></td><td width="120" valign="bottom"><span class="photocaption">'+txt+'</span></td></tr></table>';

}



function CShowImageArticle(container, id, src, txt)
{



	var container = document.getElementById(container);
//	container.innerHTML = '<img class="news_images" id="'+id+'" src="'+src+'" onLoad="ChooseClass(this)"/><br><span class="photocaption">'+txt+'</span>';
	container.innerHTML = '<table border="0" width="455"><tr><td margin="10"><img class="articlephoto" id="'+id+'" src="'+src+'"/></td><td valign="bottom"><span class="photocaption">'+txt+'</span></td></tr></table>';

}


function CShowCommImageArticle(container, id, src, txt)
{



	var container = document.getElementById(container);
//	container.innerHTML = '<img class="news_images" id="'+id+'" src="'+src+'" onLoad="ChooseClass(this)"/><br><span class="photocaption">'+txt+'</span>';
	container.innerHTML = '<table><tr><td width="200"><img class="articlephoto" id="'+id+'" src="'+src+'"/></td><td valign="bottom"><span class="photocaption">'+txt+'</span></td></tr></table>';

}



function CShowCartoon(container, id, src)
{

	var container = document.getElementById(container);
	container.innerHTML = '<img class="news_images" width ="450" id="'+id+'" src="'+src+'" />';
//onLoad="ChooseClass(this)"
}



function CShowVideo (container, file)
{
	var container = document.getElementById(container);
	container.className = 'imgcontainer_h';
	container.style.width = 'auto';
	container.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + 'width="470" height="411"' + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">' + '<param name="movie" value="flv_player.swf" /><param name="play" value="false" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="scale" value="scale" /><param name="salign" value="lt" /><param name="wmode" value="opaque" /><param name="bgcolor" value="#000000" /><param name="FlashVars" value="video1='+file+'"/>' + '<embed src="flv_player.swf" width="470" height="411" name="FLVPlayer_local" align="middle" play="true" loop="false" quality="high" scale="scale" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="video1='+file+'"/>' + '<\/object>';
}


// scripts for secondary navi bar====


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		subscriptions_over = newImage("../images/subscriptions-over.jpg");
		Jobs_over = newImage("../images/Jobs-over.jpg");
		cars_over = newImage("../images/cars-over.jpg");
		homes_over = newImage("../images/homes-over.jpg");
		classified_over = newImage("../images/classified-over.jpg");
		Menu_Guide_over = newImage("../images/Menu-Guide-over.jpg");
		community_over = newImage("../images/community-over.jpg");
		preloadFlag = true;
	}
}
