// constant variable to define the PCMS code to call.PRIMERALINEA
var contID = '';
var affiliateID = 1856;
var hits = 3;
var country = 'es';
var debug = 0;

//Randomize CID's
function RandomContentID() {
var Contentlist = new Array('girls','cine','musica','clubbing','mundoPL','CanalleoPL','PeliculasPL');
						triger = Math.ceil(Contentlist.length*Math.random())-1;
						return Contentlist[triger]
}

var hostIpAddress = '';

var referralUrl = window.location.href;

// this function call a refresh of the 2 contentCodes and call the display on both boxes to be refreshed
function changeBoxesContent() {

  contID = RandomContentID();

   var headID = document.getElementsByTagName("head")[0]; 
   var newScript1 = document.createElement('script');
   newScript1.type = 'text/javascript';
   newScript1.src = 'http://search.' + country + '.miva.com/search/content/implementations/Results.asp?hits=' + hits + '&contentidentifier=' + contID + '&affiliateid=' + affiliateID +'&host=' + hostIpAddress + '&referralUrl=' + referralUrl + '&resulttype=objectFeed';
   headID.appendChild(newScript1);
   return true;
}



// this function defines the display of the box
function mivaFeed (feed) {

    var	htmlString = '';
	htmlString += '<div class="Maddheader">ENLACES PATROCINADOS</div>' + '\n';
	htmlString += '<table class="Maddbox"><tr>' + '\n';

	    for (x=0; x < feed.hits; x++) {

			htmlString += '<td>'
			htmlString += '<div class="Maddcontainer"><a class="Maddtitle" href="' + feed.links[x].redir + '" onmouseover="self.status=\''+ feed.links[x].url +'\'" onmouseout="self.status=\'\';return true" target="_blank">' + '\n';
				htmlString +=  feed.links[x].title + '\n';
		    htmlString += '</a><br/>' + '\n';
			htmlString += '<a class="Madddesc" href="' + feed.links[x].redir + '" onmouseover="self.status=\''+ feed.links[x].url +'\'" onmouseout="self.status=\'\';return true" target="_blank">' + '\n';
				htmlString +=  feed.links[x].description.substring(0,100) + '...' + '\n';
		    htmlString += '</a><br/>' + '\n';
			htmlString += '<a class="Maddurl" href="' + feed.links[x].redir + '" onmouseover="self.status=\''+ feed.links[x].url +'\'" onmouseout="self.status=\'\';return true" target="_blank">' + '\n';
				htmlString +=  feed.links[x].url.substring(7,30) + '\n';
		    htmlString += '</a><br/></div>' + '\n';
		  htmlString += '</td>'
 	   }
	htmlString += '</tr></table>' + '\n';
// assign html code to the relevant box
    document.getElementById('mivaBox1').innerHTML=htmlString;

    //alert ('mivaFeed executed');    

}



// <!-- this is the MIVA box html code -->

//<!-- debugg -->
if (debug == 1){
document.write('hits = ' + hits + '<br/>');
document.write('contID = ' + contID + '<br/>');
document.write('affiliateID = ' + affiliateID + '<br/>');
document.write('referralUrl = ' + referralUrl + '<br/>');
document.write('hostIpAddress = ' + hostIpAddress + '<br/>');
}
// <!-- change here the css -->
document.write('<link rel="stylesheet" type="text/css" href="http://www.primeralinea.es/css/primeralinea/miva.css"/>');

document.write('<div name="mivaBox1" id="mivaBox1"></div>');



// first command to display the default codes
changeBoxesContent();
