//* Write the Stylesheet that controls the Top Job Module*//

document.write(
'<style type="text/css">'+
'#title{ font-size:11px;padding-bottom:5px; font-family:Geneva,Arial,Helvetica,sans-serif; text-decoration:none;margin-left:20px; font-weight:bold; margin-right:20px}'+
'#description{ font-size:11px;font-family:Geneva,Arial,Helvetica,sans-serif; margin-left:30px; margin-right:20px;}'+
'#title a:link{color: #3366CC}'+
'#title a:visited{color: #3366CC}'+
'#title a:active{color: #003366}'+
'#title a:hover {color: #003366; text-decoration:underline;}'+
'#description a:link{color: #003366}'+
'#description a:visited{color: #003366}'+
'#description a:active{color: #003366:text-dedoration:none;}'+
'#cvphjobs{color:black; width:258px; border: solid 1px black; background-color:#ffffff; margin-bottom:20px; text-align:left;}'+
'#cvphjobs a{text-decoration:none;}'+
'</style>');
//*Writes a job block in the right rain to be populated by the Top Jobs.*//
document.write(
'<div id="cvphjobs">'+
'<img src="http://streaming.cnhi.zope.net/karl/Plattsburgh/_images/graphics/bullet-3366CC.gif" style="margin-left: 10px; margin-top:20px; border:none" />&nbsp;<span style="color: #030166;font-size: 10px;font-family: \'Gill Sans\', \'Gill Sans MT\', \'Verdana\', \'sans-serif\'; text-transform:uppercase;font-weight:bold;">CVPH Careers</span>'+
'<div id="jobList" style="margin-top:10px;"></div>'+
'<a href="http://www.cvph.org/Careers/JobOpenings/" target="_blank">'+
'<div style="text-align:center; padding:10px;"><span id="Opportunities" style="font-family: gill sans, tahoma, sans-serif; font-size:10px; color:#000; text-decoration:underline;"></span><br/><img src="http://images.cnhi.zope.net/cnhi/images_image_111130131" border="0"/></div>'+
'</a>'+
'<div id="lister"></div></div>');

//*Establish the variables that will be used*//
var param_wsId = "od6";
var param_ssKey = "o01392251594287302590.2502135237613211871";
var param_titleColumn = "title";
var param_departmentColumn = "department";
var param_descriptionColumn = "description";
var linkLoc = "http://www.pressrepublican.com/cvph";
var job="";
var p1;
var p2;
var p3;
var p4;
var p5;
document.write('<script type="text/javascript">function View_CVPH_Jobs(){window.open("http://www.pressrepublican.com/cvph");}</script>');

//*This is the function that creates the job list based on the Google Document*//
function loadJSON(json) 
	{	
	if (json.feed.entry){var l_length=json.feed.entry.length-1;}
		if (json.feed.entry)
		{
		switch(l_length+1)
			{
			case 1 : p1=0; break;

			case 2 :	p1 = Math.round(l_length*Math.random());
						do{p2 = Math.round(l_length*Math.random());}
						while (p2 ==p1); break;

			case 3 :	p1 = Math.round(l_length*Math.random());
						do{p2 = Math.round(l_length*Math.random());}
						while (p2 ==p1);
						do{p3 = Math.round(l_length*Math.random());}
						while (p1==p3 || p2 == p3);break;

			case 4 :	p1 = Math.round(l_length*Math.random());
						do{p2 = Math.round(l_length*Math.random());}
						while (p2 ==p1);
						do{p3 = Math.round(l_length*Math.random());}
						while (p1==p3 || p2 == p3);
						do{p4= Math.round(l_length*Math.random());}
						while (p1==p4 || p2 == p4 || p3 == p4);break;

			case 5 :	p1 = Math.round(l_length*Math.random());
						do{p2 = Math.round(l_length*Math.random());}
						while (p2 ==p1);
						do{p3 = Math.round(l_length*Math.random());}
						while (p1==p3 || p2 == p3);
						do{p4= Math.round(l_length*Math.random());}
						while (p1==p4 || p2 == p4 || p3 == p4);
						do{p5 = Math.round(l_length*Math.random());}
						while (p1==p5 || p2 == p5 || p3 == p5 || p4 == p5);break;

			default:
						p1 = Math.round(l_length*Math.random());
						do{p2 = Math.round(l_length*Math.random());}
						while (p2 ==p1);
						do{p3 = Math.round(l_length*Math.random());}
						while (p1==p3 || p2 == p3);
						do{p4= Math.round(l_length*Math.random());}
						while (p1==p4 || p2 == p4 || p3 == p4);
						do{p5 = Math.round(l_length*Math.random());}
						while (p1==p5 || p2 == p5 || p3 == p5 || p4 == p5);break;
			}

		for (var m = "0"; m < json.feed.entry.length; m++ ){
			var entry = json.feed.entry[m];
				if  (m == p1 || m == p2 || m == p3 || m == p4 || m == p5){
					
					var descriptionLength = entry["gsx$" + param_descriptionColumn].$t.length
					var descriptionText = entry["gsx$" + param_descriptionColumn].$t.substr(0,80)
						if (descriptionLength>85)
						{var descriptionMore= '...<br/><div style="text-align:right; margin-right:20px;font-size:80%">More</div>';
						}else{
						var descriptionMore= '';
						}
				job += '<div id="title"><a href="javascript: View_CVPH_Jobs()">'+ entry["gsx$" + param_titleColumn].$t +'</a></div>';
				if (entry["gsx$" + param_descriptionColumn].$t)
				{
				job += '<div id="description"><a href="javascript: View_CVPH_Jobs()"  class ="desc">Department:&nbsp;'+ entry["gsx$" + param_departmentColumn].$t +'</a></div>';
				job += '<div id="description"><a href="javascript: View_CVPH_Jobs()"   class ="desc">'+ descriptionText + descriptionMore +'</a></div><br/>';
				}else{
				job += '<div id="description"><a href="javascript: View_CVPH_Jobs()"  class ="desc">Department:&nbsp;'+ entry["gsx$" + param_departmentColumn].$t +'</a></div><br/>';
				}
				}
		}
		document.getElementById('jobList').innerHTML=job;
		if (((Math.round(json.feed.entry.length/10)-1)*10)>0)
		{
		document.getElementById("Opportunities").innerHTML='Browse Over&nbsp;'+((Math.round(json.feed.entry.length/10)-1)*10) +'&nbsp;Careers From:';
		}else{
		document.getElementById("Opportunities").innerHTML='Browse Careers From:';
		}
		}else{
			document.getElementById("Opportunities").innerHTML="Check Career Opportunities From";
		}
	}

//*Writes a script on the page to grab the Spreadsheet feed from Google in a JSON format.*//
  var script = document.createElement('script');
  script.setAttribute('src', 'http://spreadsheets.google.com/feeds/list'
                         + '/' + param_ssKey + '/' + param_wsId + '/public/values' +
                        '?alt=json-in-script&callback=loadJSON');
  script.setAttribute('id', 'jsonScript');
  script.setAttribute('type', 'text/javascript'); 
  document.documentElement.firstChild.appendChild(script);
