//function focusSearchBox() { document.searchform.w.focus(); }
//window.onload = focusSearchBox;
var nav4 = window.Event ? true : false;


/********************************************************************************************
These one letter functions are referenced by every sitelisting in the NZS.com directory.
MODIFYING THESE FUNCTIONS MAY STOP THE ENTIRE NZS.com DIRECTORY FROM OPERATING!!!
DO NOT MODIFY UNLESS YOU REALLY REALLY KNOW WHAT YOU ARE DOING!!!!!!
***********************************************************************/
function s(url,id) {
	if (id == void(0)) {
		self.status = url;
	} else {
		self.status = url + " (via /jump.php?siteid=" + id + ")";
	}
	return true;
}

function c() {
	self.status = "";
	return true; 
}

function j(id) {
	window.location = "/jump.php?siteid=" + id;
	return false;
}

function x(url) {
    window.location = url;
    return false;
}

function h(link, siteid, categoryid){
	categoryid = (typeof categoryid == "undefined") ? "" : categoryid;
	
	if(categoryid != ""){
		link.href = "/jump.php?siteid=" + siteid + "&categoryid=" + categoryid;
	} else{
		link.href = "/jump.php?siteid=" + siteid;
	}
    return true;
}


/*****************************************************************************************************
These functions:pronad and restricted_ads provide ads for the adult section of the site
breaking these can reduce revenue from that part of the site
****************************************************************************************************/

function pronad(line1,line2,line3,url,visible_url){ //Creates our ads to the same structure as the google ads
    this.line1=line1;
    this.line2=line2;
    this.line3=line3;
    this.url=url;
    this.visible_url=visible_url;
}

function restricted_ads(){
    googleads = new Array();
    // Creates an array of our ads
    //googleads[0]=new pronad("Peaches & Cream Sex Toy Shop","Shop online for sex toys, lingerie and adult DVD's.","",'http://www.nzs.com/jump.php?siteid=41236','www.peachesandcream.biz');
    //googleads[2]=new pronad("Find Your Perfect Match","Meet Kiwi singles online for romance and fun!","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    //googleads[4]=new pronad("Looking For Passion?","Private, sexy personals for fun, flirtation and fantasy.","",'http://www.nzs.com/jump.php?siteid=82301','www.passion.com');
    //googleads[5]=new pronad("Swinging Singles and Couples","Looking to spice up your love life? Find Kiwi swingers online.","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    //googleads[9]=new pronad("Gay Adult Personals","Gay singles and swingers: hook up with hot men for free.","",'http://www.nzs.com/jump.php?siteid=90504','www.outpersonals.com');
    googleads[0]=new pronad("Adults Only Chat","Enjoy live webcam chat with sexy girls online 24/7.","",'http://www.nzs.com/jump.php?siteid=45894','www.cams.com');
    googleads[1]=new pronad("Auckland Singles Online Now!","Find NZ singles for romance, dating and fun.","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    googleads[2]=new pronad("Fetish and Bondage Personals","Find other Kiwis for BDSM play and fetish fun.","",'http://www.nzs.com/jump.php?siteid=90502','www.alt.com');
    googleads[3]=new pronad("Meet Gay Singles","Find sexy, single guys online for live chat.","",'http://www.nzs.com/jump.php?siteid=82305','www.gayfriendfinder.com');
    googleads[4]=new pronad("40+ and Looking For Love?","Meet NZ singles for dating, romance and relationships.","",'http://www.nzs.com/jump.php?siteid=90503','www.seniorfriendfinder.com');
    googleads[5]=new pronad("Free Adult Personals","Meet hot singles and couples looking for fun!","",'http://www.nzs.com/jump.php?siteid=90505','www.sexsearch.com');
	googleads[6]=new pronad("Who Are You Interested In Meeting?","For adult personals and sex search, find a hot date here!","",'http://www.nzs.com/jump.php?siteid=90505','www.sexsearch.com');
	googleads[7]=new pronad("Buy Sex Toys Online","Add some fun to your life with adult DVDs, sexy lingerie and naughty novelties.","",'http://www.nzs.com/jump.php?siteid=44662','www.wildsecrets.co.nz');
	googleads[8]=new pronad("Adult DVD Mega Store","A huge range of quality XXX adult DVDs at competitive prices.","",'http://www.nzs.com/jump.php?siteid=32711','www.uncutdvds.co.nz');
	googleads[9]=new pronad("Sexy Lingerie For All Women","Shop online for erotic lingerie, fantasy costumes, underwear and sleepwear.","",'http://www.nzs.com/jump.php?siteid=64377','www.fantasylingerie.co.nz');
    
    // this will shuffle the keys up by working thru idxs swapping with a random value
    for(i=0;i<googleads.length;i++){
        theRandidx=Math.floor(Math.random()*googleads.length);
        temp=googleads[i];
        googleads[i]=googleads[theRandidx];
        googleads[theRandidx]=temp;
    }
    
    return googleads; // Returns our ads to be displayed
}

function restricted_linkunit(){
    googleads= new Array();
    // Creates an array of our ads
    googleads[0]=new pronad("Sexy Toys","","",'http://www.nzs.com/jump.php?siteid=41236','www.peachesandcream.biz');
    googleads[1]=new pronad("Naughty Chat","","",'http://www.nzs.com/jump.php?siteid=45894','www.cams.com');
    googleads[2]=new pronad("Find a New Lover","","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    googleads[3]=new pronad("Single in Auckland?","","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    googleads[4]=new pronad("Like to Swing?","","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    googleads[5]=new pronad("Into Bondage?","","",'http://www.nzs.com/jump.php?siteid=90502','www.alt.com');
    googleads[6]=new pronad("Gay Singles","","",'http://www.nzs.com/jump.php?siteid=82305','www.gayfriendfinder.com');
    googleads[7]=new pronad("40+?","","",'http://www.nzs.com/jump.php?siteid=90503','www.seniorfriendfinder.com');
    googleads[8]=new pronad("Still Searching?","","",'http://www.nzs.com/jump.php?siteid=90505','www.sexsearch.com');
    googleads[9]=new pronad("Free Adult Personals","","",'http://www.nzs.com/jump.php?siteid=90505','www.sexsearch.com');
	googleads[10]=new pronad("Are you Wild?","","",'http://www.nzs.com/jump.php?siteid=44662','www.wildsecrets.co.nz');
	googleads[11]=new pronad("Hot DVDs","","",'http://www.nzs.com/jump.php?siteid=32711','www.uncutdvds.co.nz');
	googleads[12]=new pronad("Erotic Lingerie","","",'http://www.nzs.com/jump.php?siteid=64377','www.fantasylingerie.co.nz');
    
    // this will shuffle the keys up by working thru idxs swapping with a random value
    for(i=0;i<googleads.length;i++){
        theRandidx=Math.floor(Math.random()*googleads.length);
        temp=googleads[i];
        googleads[i]=googleads[theRandidx];
        googleads[theRandidx]=temp;
    }
    
    return googleads[0]; // Returns our ads to be displayed
}

function search_ads(google_ads){
	googleads= new Array();
	// Creates an array of our ads
	googleads[0]=new pronad("Auckland Flowers and Gifts","Shop online for flowers, gift baskets, wines, chocolates and more.","Prompt nationwide delivery.",'http://www.nzs.com/jump.php?siteid=79003','www.nzflower.co.nz ');
	googleads[1]=new pronad("SmileCity","New Zealand's #1 online rewards programme","with over 125,000 members.",'http://www.nzs.com/jump.php?siteid=79008','www.smilecity.co.nz ');
	googleads[2]=new pronad("Great NZ Survey","Be in to win $5,000 cash by taking part in","The Great New Zealand Survey.",'http://www.nzs.com/jump.php?siteid=79029','www.kiwisurveys.co.nz ');
	
	// this will shuffle the keys up by working thru idxs swapping with a random value
	for(i=0;i<googleads.length;i++){
		theRandidx=Math.floor(Math.random()*googleads.length);
		temp=googleads[i];
		googleads[i]=googleads[theRandidx];
		googleads[theRandidx]=temp;
	}
	
	return googleads; // Returns our ads to be displayed
}


/***************************************************************************************************
This function is the one that changes the little boxy icon thing on the weather page as you drag 
the mouse cursor around the nz map
*****************************************************************************************************/

function showWeather(region,icon,high,low,forecast,wind){
	document.getElementById("forecastregion").innerHTML=region + " Forecast";
	document.getElementById("forecast-icon").src=icon;
	document.getElementById("forecast-icon").alt=forecast;
	document.getElementById("high").innerHTML=high;
	document.getElementById("low").innerHTML=low;
	document.getElementById("wind").innerHTML=wind;
	document.getElementById("forecast-text").innerHTML=forecast;
}

/***************************************************************************************************
This function is for adding nzs.com as a bookmark
*****************************************************************************************************/

function addBookmark(title,url,referer) {
	var ua=navigator.userAgent.toLowerCase();
    var isKonq=(ua.indexOf('konqueror')!=-1);
    var isSafari=(ua.indexOf('webkit')!=-1);
    var isMac=(ua.indexOf('mac')!=-1);
    var buttonStr=isMac?'Command/Cmd':'CTRL';
	
	if(title == ""){ title = document.title; }
	
	if(isKonq) { alert('Press '+buttonStr+' + B to add NZS.com to your favorites'); }
	else if(isSafari) { alert('Press '+buttonStr+' + D to add NZS.com to your favorites'); }
	else if(!window.print || isSafari || isMac) { alert('Press '+buttonStr+' + D to add NZS.com to your favorites'); }
	else if(window.sidebar) { window.sidebar.addPanel(title, url,""); }
	else if(document.all && !window.opera) { window.external.AddFavorite(url, title); }
	else if(document.all && window.opera) { alert('Press '+buttonStr+' + D to add NZS.com to your favorites'); }
	else if(window.opera && window.print) { return true; }
	window.parent.location = "/bookmark/bookmark.php?referer=" + referer;
}

/***************************************************************************************************
This function is for bookmarking a page on nzs.com
*****************************************************************************************************/

function addPageBookmark(title,url) {
	if(window.sidebar) { window.sidebar.addPanel(title, url,""); }
	else if(document.all && !window.opera) { window.external.AddFavorite(url, title); }
	else if(document.all && window.opera) { alert("Press Ctrl+D to add NZS.com to your favorites"); }
	else if(window.opera && window.print) { return true; }
}

/***************************************************************************************************
This function shows or hide the specified div
*****************************************************************************************************/
function togglediv(targetId){
	target = document.getElementById(targetId);
	if(target.style.display == "none"){ target.style.display = "block"; }
	else{ target.style.display = "none"; }
}

function toggledivs(showid,hideid){
	show = document.getElementById(showid);
	hide = document.getElementById(hideid);
	
	hide.style.display = "none";
	show.style.display = "block";
}

function mouseoutdiv(targetId){
	target = document.getElementById(targetId);
	target.style.display = "none";
}

function mouseoverdiv(targetId){
	target = document.getElementById(targetId);
	target.style.display = "block";
}

function toggledirectorydetails(targetId){ /* Used to Show/Hide Directory Listings in the Site Profile Pages */
	target = document.getElementById(targetId);
	textsrc = document.getElementById("moredetails");
	buttonsrc = document.getElementById("btmoredetails");
	
	if (target.style.display == "none") {
		target.style.display = "block";
		textsrc.innerHTML = "Less Directory Details";
		buttonsrc.src = "/img/bt_minus.gif";
	} else {
		target.style.display = "none";
		textsrc.innerHTML = "More Directory Details";
		buttonsrc.src = "/img/bt_plus.gif";
	}
}

function togglelistingdetails(targetId){ /* Used to Show/Hide Directory Listings in the Site Profile Pages */
	target = document.getElementById(targetId);
	textsrc = document.getElementById("text-"+targetId);
	buttonsrc = document.getElementById("bt-"+targetId);
	
	if (target.style.display == "none") {
		target.style.display = "block";
		textsrc.innerHTML = "Hide Listing Details";
		buttonsrc.src = "/img/bt_minus.gif";
	} else {
		target.style.display = "none";
		textsrc.innerHTML = "Show Listing Details";
		buttonsrc.src = "/img/bt_plus.gif";
	}
}

function togglelinkdetails(targetId){ /* Used to Show/Hide Link Details in the Site Profile Pages */
	target = document.getElementById(targetId);
	textsrc = document.getElementById("text"+targetId);
	buttonsrc = document.getElementById("bt"+targetId);
	
	if (target.style.display == "none") {
		target.style.display = "block";
		textsrc.innerHTML = "Hide Link Details";
		buttonsrc.src = "/img/bt_minus.gif";
	} else {
		target.style.display = "none";
		textsrc.innerHTML = "Show Link Details";
		buttonsrc.src = "/img/bt_plus.gif";
	}
}

function togglesocial(){ /* Used to Show/Hide extra Social Bookmarks */
	socialicons = document.getElementById("socialiconsdiv");
	hidden = document.getElementById("hiddenicn");
	more = document.getElementById("moreicn");
	madeinnz = document.getElementById("madeinnzdiv");
	if(socialicons.style.display == "none") {
		more.style.display = "none";
		hidden.style.display = "block";
		socialicons.style.display = "block";
		madeinnz.style.display = "none";
	} else{
		socialicons.style.display = "none";
		hidden.style.display = "none";
		more.style.display = "block";
	}
}

function viewtable(targetId,numrows){ /* Used to Show/Hide table rows for the specified table */
	for(i=0; i<=numrows; i++){
		targetrow = document.getElementById(targetId + i);
		if(targetrow.style.display == "none"){
			if(document.all){ targetrow.style.display = "block"; }
			else{ targetrow.style.display = "table-row"; }
		} else if(i == numrows){
			targetrow.style.display = "none";
		}
	}
}

/***************************************************************************************************
This function launches a popup window
*****************************************************************************************************/
function popup(url, width, height){
	eval("page = window.open(url, null, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width="+(width+30)+",height="+(height+20)+",left=640,top=425');");
	if(window.focus){ page.focus() }
	return false;
}


/***************************************************************************************************
These functions resize the text on the page
***************************************************************************************************/

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


/***************************************************************************************************
This function emails the URL of the page
***************************************************************************************************/

function emailpage(){
	var pageurl = document.URL;
	var message = "Hi. Check out this page  "+ pageurl +".";
	document.getElementById('emailpage').href ="mailto:?subject=Check it out!&body="+ message;
}


/***************************************************************************************************
This function prints the current page
***************************************************************************************************/

function printpage(){
	if (window.print){
	    window.print();  
	} else{
	    var WebBrowser = '<object id="browserprint" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	    WebBrowser1.ExecWB(6,2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}


/***************************************************************************************************
This function creates a mailto link
***************************************************************************************************/

function insertmailto(email,domain,subject,body){
	var atsign = "@"
	var emailaddress = email + atsign + domain;
	var mailto_link = "mailto:"+emailaddress+"?subject="+subject+"&body="+body;
	
	win = window.open(mailto_link,"emailwindow"); 
	if(win && win.open && !win.closed){ win.close(); }
}