//Why not working?
$().ready(function(){
	//Disable SafariPrint.css on load so print.css will be only print style active when printing from file menu
	$('link[@rel*=style]').each(function(i){	
		if (this.getAttribute("href").match("SafariPrint.css")){
			this.disabled = true;
		}
	});
	 
	 if (jQuery.browser.safari){
		 $('#printOption').show();
	 }else{
		 $('#printOption').hide();
	 }
	 
	 
	 if (jQuery.browser.safari){
//Add a popup with 
var select1=ce('select','printLabLocations');
select1.setAttribute('id','printLabLocationSelect');
select1.onchange=function(){javascript:printLocation()};
 $('#printOption').append(select1);
  $('#printLabLocationSelect').append($('<option value="not_a_lab">Select a location to print for posting...</option>'));
  $('#printLabLocationSelect').append($('<option value="ALL">Print ALL locations</option>'));
	 $('.labLocation').each(function(i){
		//Place all the info about the location into variables
		var labName = $(".labName",this).text();
		var labNameAndPrint = "Print only "+labName;
		 $('#printLabLocationSelect').append($('<option value=\''+labName+'\'>'+labNameAndPrint+'</option>')); 
	
		});
	 }
	 
	
});

 function ce(tag,name){
    if (name && window.ActiveXObject){
      element = document.createElement('<'+tag+' name="'+name+'">');
    }else{
      element = document.createElement(tag);
      element.setAttribute('name',name);
    }
    return element;
  };

function printLocation() {
 //var lab_to_print = $("select[name='printLabLocations'] :selected").text();
 var lab_to_print_value = $("select[name='printLabLocations'] :selected").attr("value");
 //alert(lab_to_print+" "+lab_to_print_value);
 printLocations(lab_to_print_value);
}


function printLocations(selected_location) {
if (selected_location != "not_a_lab") { 
	//Disable print.css temporarily 
	$('link[@rel*=style]').each(function(i){	

		if (this.getAttribute("href").match("print.css")){
			this.disabled = true;
		}
		if (this.getAttribute("href").match("SafariPrint.css")){
			this.disabled = false;
		}
	});
	 //Switch stylesheet to print style sheet to properly calculate heights
	 var div1=document.createElement('div');
		div1.setAttribute('id','printLocations');
		var semesterText = $("#printSemester").text();


		var table2=document.createElement('table');
		table2.setAttribute('width','1000');
		div1.appendChild(table2);
		var tbody1=document.createElement('tbody');
		table2.appendChild(tbody1);
		var tr1=document.createElement('tr');
		tbody1.appendChild(tr1);
		var td1=document.createElement('td');
		td1.setAttribute('id','printHeading1');
		tr1.appendChild(td1);
		var txt4=document.createTextNode('Computer Labs Locations and Hours');
		td1.appendChild(txt4);
		var tr2=document.createElement('tr');
		tbody1.appendChild(tr2);
		var td2=document.createElement('td');
		td2.setAttribute('id','printHeading2');
		tr2.appendChild(td2);
		var txt8=document.createTextNode(semesterText);

		td2.appendChild(txt8);

		
	 $('.labLocation').each(function(i){
		//Place all the info about the location into variables
		var labName = $(".labName",this).text();
		var labAddress = $(".labAddress",this).text();
		var labPhone = $(".labPhone",this).text();
		var labSunday = $(".labSunday",this).text();
		var labMThruTh = $(".labMondayThruThursday",this).text();
		var labFriday = $(".labFriday",this).text();
		var labSaturday = $(".labSaturday",this).text();
		var labImageURL = $("img",this).attr("src");
		var alternativeToHours = $(".alternativeToHours",this).text();
		var exceptionsTitle = $(".exceptionsTitle",this).text();

		if (labName == selected_location || selected_location == "ALL"){

		var table1=document.createElement('table');
		table1.setAttribute('width','1000');
		table1.setAttribute('border','0');
		table1.setAttribute('id','printLocationsTable');
		div1.appendChild(table1);
		var tbody1=document.createElement('tbody');
		table1.appendChild(tbody1);
		var tr1=document.createElement('tr');
		tbody1.appendChild(tr1);
		var td1=document.createElement('td');
		td1.setAttribute('width','72%');
		tr1.appendChild(td1);
		var table2=document.createElement('table');
		table2.setAttribute('width','80%');
		table2.setAttribute('border','0');
		td1.appendChild(table2);
		var tbody2=document.createElement('tbody');
		table2.appendChild(tbody2);
		var tr2=document.createElement('tr');
		tbody2.appendChild(tr2);
		var td2=document.createElement('td');
		td2.setAttribute('width','23%');
		tr2.appendChild(td2);
		var img1=document.createElement('img');
		img1.setAttribute('src',labImageURL);
		img1.setAttribute('width','75');
		img1.setAttribute('height','64');
		img1.setAttribute('border','1');
		td2.appendChild(img1);
		var td3=document.createElement('td');
		td3.setAttribute('width','77%');
		tr2.appendChild(td3);
		var div2=document.createElement('div');
		div2.className='printLabName';
		td3.appendChild(div2);
		var txt8=document.createTextNode(labName);
		div2.appendChild(txt8);
		var div3=document.createElement('div');
		div3.className='printLabAddress';
		td3.appendChild(div3);
		var txt10=document.createTextNode(labAddress);
		div3.appendChild(txt10);
		var div4=document.createElement('div');
		div4.className='printLabPhone';
		td3.appendChild(div4);
		var txt12=document.createTextNode(labPhone);
		div4.appendChild(txt12);
		var td4=document.createElement('td');
		td4.setAttribute('width','28%');
		td4.setAttribute('rowspan','2');
		tr1.appendChild(td4);
		var div5=document.createElement('div');
		div5.className='printHolidaysHeading';
		td4.appendChild(div5);
		//Test if there is no holidays, if none listed don't print anything for holiday info.
		if ($(".labHoliday",this).text() != ""){
		var txt16=document.createTextNode('Holidays');
		//If exceptionsTitle class is defined use the header text from webpage.
		if (exceptionsTitle != ""){txt16=document.createTextNode(exceptionsTitle);}
		div5.appendChild(txt16);
		var div6=document.createElement('div');
		div6.className='printHolidaysHours';
		td4.appendChild(div6);
		
		$(".labHoliday",this).each(function(i){
			var labHoliday = $(this).text();
			//alert("lh:"+labHoliday);
			var txt18=document.createTextNode(labHoliday);
			div6.appendChild(txt18);
			var br1=document.createElement('br');
			div6.appendChild(br1);
		});
		}
		
		var tr3=document.createElement('tr');
		tbody1.appendChild(tr3);
		var td5=document.createElement('td');
		td5.setAttribute('height','43');
		tr3.appendChild(td5);
		//If no hours then print alternative to hours info instead
		if (alternativeToHours != ""){
			var table3=document.createElement('table');
			table3.setAttribute('width','98%');
			table3.setAttribute('border','0');
			td5.appendChild(table3);
			var tbody3=document.createElement('tbody');
			table3.appendChild(tbody3);
			var tr4=document.createElement('tr');
			tbody3.appendChild(tr4);
			var td6=document.createElement('td');
			tr4.appendChild(td6);
			var div7=document.createElement('div');
			div7.className='printAlternativeToHours';
			td6.appendChild(div7);
			var txt29=document.createTextNode(alternativeToHours);
			div7.appendChild(txt29);
		}else{
		var table3=document.createElement('table');
		table3.setAttribute('width','98%');
		table3.setAttribute('border','0');
		td5.appendChild(table3);
		var tbody3=document.createElement('tbody');
		table3.appendChild(tbody3);
		var tr4=document.createElement('tr');
		tbody3.appendChild(tr4);
		var td6=document.createElement('td');
		td6.setAttribute('width','25%');
		tr4.appendChild(td6);
		var div7=document.createElement('div');
		div7.className='printDaysOfWeekHeading';
		td6.appendChild(div7);
		var txt29=document.createTextNode('Sunday');
		div7.appendChild(txt29);
		var td7=document.createElement('td');
		td7.setAttribute('width','25%');
		tr4.appendChild(td7);
		var div8=document.createElement('div');
		div8.className='printDaysOfWeekHeading';
		td7.appendChild(div8);
		var txt31=document.createTextNode('Monday-Thursday');
		div8.appendChild(txt31);
		var td8=document.createElement('td');
		td8.setAttribute('width','25%');
		tr4.appendChild(td8);
		var div9=document.createElement('div');
		div9.className='printDaysOfWeekHeading';
		td8.appendChild(div9);
		var txt33=document.createTextNode('Friday');
		div9.appendChild(txt33);
		var td9=document.createElement('td');
		td9.setAttribute('width','25%');
		tr4.appendChild(td9);
		var div10=document.createElement('div');
		div10.className='printDaysOfWeekHeading';
		td9.appendChild(div10);
		var txt35=document.createTextNode('Saturday');
		div10.appendChild(txt35);
		var tr5=document.createElement('tr');
		tbody3.appendChild(tr5);
		var td10=document.createElement('td');
		td10.setAttribute('height','17');
		tr5.appendChild(td10);
		var div11=document.createElement('div');
		div11.className='printDaysOfWeekHours';
		td10.appendChild(div11);
		var txt39=document.createTextNode(labSunday);
		div11.appendChild(txt39);
		var td11=document.createElement('td');
		tr5.appendChild(td11);
		var div12=document.createElement('div');
		div12.className='printDaysOfWeekHours';
		td11.appendChild(div12);
		var txt41=document.createTextNode(labMThruTh);
		div12.appendChild(txt41);
		var td12=document.createElement('td');
		tr5.appendChild(td12);
		var div13=document.createElement('div');
		div13.className='printDaysOfWeekHours';
		td12.appendChild(div13);
		var txt43=document.createTextNode(labFriday);
		div13.appendChild(txt43);
		var td13=document.createElement('td');
		tr5.appendChild(td13);
		var div14=document.createElement('div');
		div14.className='printDaysOfWeekHours';
		td13.appendChild(div14);
		var txt45=document.createTextNode(labSaturday);
		div14.appendChild(txt45);
		}//labs match
		}
	 });
	 
	 $('#printHeader').append(div1);
	  window.print();
	  $("#printLocations").hide();
	  //Remove div1 so that next time function is called past information will not persist
	  $(div1).remove();
	  

	//ReEnable print.css  
	$('link[@rel*=style]').each(function(i){	
		if (this.getAttribute("href").match("print.css")){
			this.disabled = false;
		}
		if (this.getAttribute("href").match("SafariPrint.css")){
			this.disabled = true;
		}
	});

}//end of not_a_lab test
}
