function init() {
    var sendEmailLink = document.getElementById("send-email");
	if(sendEmailLink) {
	    sendEmailLink.setAttribute("href", "#");
	}

}

function emailWindow(targetLocation) {
	emailFriend = window.open(targetLocation,'emailWin', 'width=500,height=480,scrollbars=no');	
	return(false);
}


var url ="#";
if((typeof(v) != "undefined")) {
    if(v != null) {
        a=new Array(22);aln=22;
    }
}

function getSelectValue(formNm,selectNm) {
	for (q=0; q<document.forms[formNm][selectNm].length; q++) {
		if (document.forms[formNm][selectNm][q].selected) {
window.open(document.forms[formNm][selectNm][q].value,'region','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=230,height=205');
			return;
			}
		}
	alert("nothing found")
	}


function getFormNum (formName) {
        var formNum =-1;
        for (i=0;i<document.forms.length;i++){
                tempForm = document.forms[i];
                if (formName == tempForm) {
                        formNum = i;
                        correctForm = tempForm;
                        break;
                }
        }
        return formNum;
}



function relate(formName,elementNum,j) {
if(v){
k=1;
aln2=a.length;
var formNum = getFormNum(formName); 
// var formNum added, explicit var pass
if (formNum>=0) {
        formNum++; 
		// reference next form, assume it follows in HTML
        with (document.forms[formNum].elements[elementNum]) {
                for (var i=options.length-1;i>0;i--) options[i]=null;
                for (var i=1;i<aln2;i++) options[i-1]=a[i];
                options[0].selected=true;
        }
}
} else {
jmp(formName,elementNum);
}
}


function printStoryPage() {
	 if (document.getElementById("print-logo")){
         document.getElementById("print-logo").setAttribute("src", "/images/print/print-logo.jpg");
	     window.print();
	 }
}


/* For radio buttons on forms */

function selectedValue(nodeList) {
	for (var i=0; i<nodeList.length; i++) {
		if (nodeList[i].checked) {
		    return nodeList[i].value;
		}
	}
	
	return null;
}


/* popups
------------------- */

function sizedPopUp(url, width, height, bars, isResizable) {
    var setResizable = "yes";
    if(isResizable != null) {
	    if(isResizable === "no");
	    setResizable = "no";
	}
	window.open(url, '',
	'width=' + width + ',height=' + height + ' ,scrollbars=' + bars + 
	    ',status=yes,toolbar=no,menubar=no,location=no,resizable='+setResizable);
}

function popUp(type,winURL) {
	var wndReference = null;
    suffixedType = type+"";
	switch (type) {
	case "poll":
		wndReference = window.open(winURL,suffixedType,"height=352, width=442");
		break;
	case "gallery":
		wndReference = window.open(winURL,suffixedType,"height=700, width=750");
		break;
	case "gallery2":
		wndReference = window.open(winURL,suffixedType,"height=750, width=750");
		break;
	case "gallery3":
		wndReference = window.open(winURL,suffixedType,"height=630, width=625");
		break;
	case "cartoongallery":
		wndReference = window.open(winURL,suffixedType,"height=600, width=750");
		break;
	case "weather":
		wndReference = window.open(winURL, suffixedType, 'width=236,height=350');
		break;
	case "stateweather":
		wndReference = window.open(winURL, suffixedType, 'width=945,height=640,scrollbars=yes');
		break;
	case "currentweather":
		wndReference = window.open(winURL, suffixedType, 'width=1024,height=650,scrollbars=yes');
		break;
	case "subscribe":
		wndReference = window.open(winURL, suffixedType, 'width=765,height=610,scrollbars=yes');
		break;
	case "stopstart":
		wndReference = window.open(winURL, suffixedType, 'width=785,scrollbars=yes');
		break;
	case "showbuzz":
		wndReference = window.open(winURL, suffixedType, 'width=710,height=610,scrollbars=yes');
		break;
	case "addresschange":
		wndReference = window.open(winURL, suffixedType, 'width=500,scrollbars=yes');
		break;
	case "video":
		wndReference = window.open(winURL, suffixedType, 'toolbar=no,location=no,scrolling=auto,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=760,height=660');
		break;
	case "email":
		wndReference = window.open(winURL, suffixedType, 'width=585,height=700,resizable=yes,scrollbars=yes');
		break;
	case "sendLetter":
		wndReference = window.open(winURL, suffixedType, 'width=450,height=820,resizable=yes,scrollbars=yes');
		break;
	case "event":
		wndReference = window.open(winURL, suffixedType, 'width=510,height=700,resizable=yes,scrollbars=no');
		break;
	case "pguide":
		wndReference = window.open(winURL, suffixedType, 'width=442,height=500,resizable=no,scrollbars=yes');
		break;
	case "nipoll":
	    wndReference = window.open(winURL, type, 'width=550, height=500,resizable=yes,scrollbars=yes');
		break;
	case "footy":
		wndReference = window.open(winURL, suffixedType, 'width=800,height=600,resizable=yes,scrollbars=yes');
		break;
	case "interactive":
		wndReference = window.open(winURL, suffixedType, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=700,height=420');
		break;
	default:
		wndReference = window.open(winURL);
	}
	
	if ((wndReference !== null) && (wndReference !== "")) {
		wndReference.focus();
	}
}


 function pollValidate(pollForm) {
	var option = selectedValue(pollForm.option);
	var addr = pollForm.getAttribute("action") + "?option="+option;
	if(validate(pollForm)) {
		popUp("poll", addr);		
	}	
	return false;
}

/* font size change 
------------------- */

var curFontSize = 1; 	
var fontModifier = 0.1; 

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
	    endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)  {
		date.setTime (date.getTime() - skew);
	}
}

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,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

function fontSize(act) {
    if (document.getElementById) {
        storyBody = document.getElementById("article-wrapper");
		storyComments = document.getElementById("story-comments");

        if (act === 1) {
            curFontSize += fontModifier;
            curFontSize = Math.min(curFontSize, 1.4);
        } else if (act === 0) {
            curFontSize -= fontModifier;
            curFontSize = Math.max(curFontSize, 1);
        }

        storyBody.style.fontSize = curFontSize + "em";
		
		if(storyComments !== null) {
		    for (v = 0; v < storyComments.getElementsByTagName("blockquote").length; v++) {
		       storyComments.getElementsByTagName("blockquote")[v].style.fontSize = curFontSize + "em";
		    }
		}
    }
	
	// set cookie with font size
	var expdate = new Date();
	FixCookieDate (expdate);
	expdate.setTime (expdate.getTime() + (672*60*60*1000)); // 4 weeks
	SetCookie("userfontc",curFontSize,expdate);		
	return(false);
}
