// #################### AD VARIABLES #################### //

restricted_ads = false;

// #################### END AD VARIABLES #################### //


// #################### NZS AD FUNCTIONS #################### //


// Create NZS ads to google ad structure
function create_ad(line1,line2,line3,url,visible_url){
    this.line1 = line1;
    this.line2 = line2;
    this.line3 = line3;
    this.url = url;
    this.visible_url = visible_url;
}


// NZS equivalent google ads
function get_nzs_ads(){
	var nzs_ads= new Array();
	// Creates an array of our ads
	nzs_ads[0] = new create_ad("Get DVDs Delivered to Your Mailbox","Start a 14-Day Free Trial with Fatso Online DVD Rental.","Get DVDs Delivered to Your Mailbox!",'http://www.nzs.com/jump.php?siteid=41824','www.fatso.co.nz');
	nzs_ads[1] = new create_ad("The Great New Zealand 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');
	nzs_ads[2] = new create_ad("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');
	nzs_ads[3] = new create_ad("Valued Opinions","Did you know you could get rewarded for simply giving your opinions?","",'http://www.nzs.com/jump.php?siteid=84288','www.valuedopinions.co.nz');
	nzs_ads[4] = new create_ad("Real Free Samples","Your source for the best free samples.","Get the best product samples that New Zealand companies want to send.",'http://www.nzs.com/jump.php?siteid=95163','www.realfreesamples.co.nz');
	nzs_ads[5] = new create_ad("SnapFish - 20 FREE prints!","Snapfish, HP's leading online photo service would like to offer you 20 FREE prints of your favourite photos.","",'http://www.nzs.com/jump.php?siteid=96654','www.snapfish.co.nz');
	
	// This will shuffle the keys up by working through the indexs swapping with a random value
	for(i=0; i<nzs_ads.length; i++){
		random_index = Math.floor(Math.random()*nzs_ads.length);
		temp_ad = nzs_ads[i];
		nzs_ads[i] = nzs_ads[random_index];
		nzs_ads[random_index] = temp_ad;
	}
	
	return nzs_ads; // Returns our ads to be displayed
}


function get_nzs_adult_ads(){
    var nzs_adult_ads= new Array();
    // Creates an array of our adult ads
    nzs_adult_ads[0] = new create_ad("Adults Only Chat","Enjoy live webcam chat with sexy girls online 24/7.","",'http://www.nzs.com/jump.php?siteid=45894','www.cams.com');
    nzs_adult_ads[1] = new create_ad("Auckland Singles Online Now!","Find NZ singles for romance, dating and fun.","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    nzs_adult_ads[2] = new create_ad("Fetish and Bondage Personals","Find other Kiwis for BDSM play and fetish fun.","",'http://www.nzs.com/jump.php?siteid=90502','www.alt.com');
    nzs_adult_ads[3] = new create_ad("Meet Gay Singles","Find sexy, single guys online for live chat.","",'http://www.nzs.com/jump.php?siteid=82305','www.gayfriendfinder.com');
    nzs_adult_ads[4] = new create_ad("40+ and Looking For Love?","Meet NZ singles for dating, romance and relationships.","",'http://www.nzs.com/jump.php?siteid=90503','www.seniorfriendfinder.com');
    nzs_adult_ads[5] = new create_ad("Free Adult Personals","Meet hot singles and couples looking for fun!","",'http://www.nzs.com/jump.php?siteid=90505','www.sexsearch.com');
	nzs_adult_ads[6] = new create_ad("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');
	nzs_adult_ads[7] = new create_ad("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');
	nzs_adult_ads[8] = new create_ad("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');
	nzs_adult_ads[9] = new create_ad("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 through the indexs swapping with a random value
    for(i=0; i<nzs_adult_ads.length; i++){
        random_index = Math.floor(Math.random()*nzs_adult_ads.length);
        temp_ad = nzs_adult_ads[i];
        nzs_adult_ads[i] = nzs_adult_ads[random_index];
        nzs_adult_ads[random_index] = temp_ad;
    }
    
    return nzs_adult_ads; // Returns our ads to be displayed
}


function get_nzs_adult_linkunit(){
    nzs_adult_linkunit = new Array();
    // Creates an array of our adult link unit ads
    nzs_adult_linkunit[0] = new create_ad("Sexy Toys","","",'http://www.nzs.com/jump.php?siteid=41236','www.peachesandcream.biz');
    nzs_adult_linkunit[1] = new create_ad("Naughty Chat","","",'http://www.nzs.com/jump.php?siteid=45894','www.cams.com');
    nzs_adult_linkunit[2] = new create_ad("Find a New Lover","","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    nzs_adult_linkunit[3] = new create_ad("Single in Auckland?","","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    nzs_adult_linkunit[4] = new create_ad("Like to Swing?","","",'http://www.nzs.com/jump.php?siteid=90501','www.adultfriendfinder.com');
    nzs_adult_linkunit[5] = new create_ad("Into Bondage?","","",'http://www.nzs.com/jump.php?siteid=90502','www.alt.com');
    nzs_adult_linkunit[6] = new create_ad("Gay Singles","","",'http://www.nzs.com/jump.php?siteid=82305','www.gayfriendfinder.com');
    nzs_adult_linkunit[7] = new create_ad("40+?","","",'http://www.nzs.com/jump.php?siteid=90503','www.seniorfriendfinder.com');
    nzs_adult_linkunit[8] = new create_ad("Still Searching?","","",'http://www.nzs.com/jump.php?siteid=90505','www.sexsearch.com');
    nzs_adult_linkunit[9] = new create_ad("Free Adult Personals","","",'http://www.nzs.com/jump.php?siteid=90505','www.sexsearch.com');
	nzs_adult_linkunit[10] = new create_ad("Are you Wild?","","",'http://www.nzs.com/jump.php?siteid=44662','www.wildsecrets.co.nz');
	nzs_adult_linkunit[11] = new create_ad("Hot DVDs","","",'http://www.nzs.com/jump.php?siteid=32711','www.uncutdvds.co.nz');
	nzs_adult_linkunit[12] = new create_ad("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<nzs_adult_linkunit.length; i++){
        random_index = Math.floor(Math.random()*nzs_adult_linkunit.length);
        temp_ad = nzs_adult_linkunit[i];
        nzs_adult_linkunit[i] = nzs_adult_linkunit[random_index];
        nzs_adult_linkunit[random_index] = temp_ad;
    }
    
    return nzs_adult_linkunit[0]; // Returns our ads to be displayed
}


// Converts the array into an object so that we can test if a value is in the array
function getquerystring(param){
	param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  	var regexS = "[\\?&]"+param+"=([^&#]*)";
  	var regex = new RegExp(regexS);
  	var results = regex.exec(window.location.href);
  	if(results == null){
	    return "";
  	} else{
    	return results[1];
  	}
}


// #################### END NZS AD FUNCTIONS #################### //


// #################### GOOGLE AD FUNCTIONS #################### //


//Google Ads for Content Javascript
function google_ad_request_done(google_ads){
	display_ads = new Array(); // Array to hold adverts to be displayed on the page
	
	var google_ad_count = 0; // Count so that the same google ad is not displayed twice
	google_feedback_url = google_info.feedback_url; // Google feedback URL
	
	display_nzs_ads = false;
	
	for(var i=0; i<nzs_adverts.length; i++){ // Iterate through the ad positions
		var ad_name = nzs_adverts[i][0]; // Ad postion name
		display_ads[ad_name] = new Array(); // Ad array for postion
		
		for(var j=0; j<nzs_adverts[i][1]; j++){ // Iterate through the specified # of ads for this postion
			if(google_ads[google_ad_count] != undefined){ // If there is a google ad available then add the data to the postion array
				display_ads[ad_name].push(google_ads[google_ad_count]);
				google_ad_count++; // Increment the google ad count so this ad is not displayed again
			}
		}
		
		// If there were no google ads then we need to use the nzs ads for this postion
		if(display_ads[ad_name].length == 0){
			if(!restricted_ads){
				var nzs_ads = get_nzs_ads(); // Get the nzs ads
			} else{
				var nzs_ads = get_nzs_adult_ads(); // Get the nzs adult ads
			}
			
			for(var j=0; j<nzs_adverts[i][1]; j++){ // Iterate through the specified # of ads for this postion
				if(nzs_ads[j] != undefined){ // If there is an nzs ad available the add the data to the postion array
					display_ads[ad_name].push(nzs_ads[j]);
				}
			}
			
			var display_nzs_ads = "nzs"+ad_name;
			
			display_ads[display_nzs_ads] = new Array();
			display_ads[display_nzs_ads].push("nzs");
		}
	}
}


//Google Ads for Search Javascript
function google_afs_request_done(google_ads) {
	total_google_ads = google_ads.length;
	display_ads = new Array(); // Array to hold adverts to be displayed on the page
	
	var google_ad_count = 0; // Count so that the same google ad is not displayed twice
	google_feedback_url = "http://services.google.com/feedback/online_hws_feedback"; // Google feedback URL
	
	display_nzs_ads = false;
	
	for(var i=0; i<nzs_adverts.length; i++){ // Iterate through the ad positions
		var ad_name = nzs_adverts[i][0]; // Ad postion name
		display_ads[ad_name] = new Array(); // Ad array for postion
		
		for(var j=0; j<nzs_adverts[i][1]; j++){ // Iterate through the specified # of ads for this postion
			if(google_ads[google_ad_count] != undefined){ // If there is a google ad available the add the data to the postion array
				display_ads[ad_name].push(google_ads[google_ad_count]);
				google_ad_count++; // Increment the google ad count so this ad is not displayed again
			}
		}
		
		// If there were no google ads then we need to use the nzs ads for this postion
		if(display_ads[ad_name].length == 0){
			if(!restricted_ads){
				var nzs_ads = get_nzs_ads(); // Get the nzs ads
			} else{
				var nzs_ads = get_nzs_adult_ads(); // Get the nzs adult ads
			}
			
			for(var j=0; j<nzs_adverts[i][1]; j++){ // Iterate through the specified # of ads for this postion
				if(nzs_ads[j] != undefined){ // If there is an nzs ad available the add the data to the postion array
					display_ads[ad_name].push(nzs_ads[j]);
				}
			}
			
			var display_nzs_ads = "nzs"+ad_name;
			
			display_ads[display_nzs_ads] = new Array();
			display_ads[display_nzs_ads].push("nzs");
		}
	}
}


// #################### END GOOGLE AD FUNCTIONS #################### //