var divCalled = "";
function getHTTPObject(){
	var xhr = false;//set to false, so if it fails, do nothing
	if(window.XMLHttpRequest) {//detect to see if browser allows this method
		var xhr = new XMLHttpRequest();//set var the new request
	} else if(window.ActiveXObject) {//detect to see if browser allows this method
		try {
			var xhr = new ActiveXObject("Msxml2.XMLHTTP");//try this method first
		} catch(e) {//if it fails move onto the next
			try {
				var xhr = new ActiveXObject("Microsoft.XMLHTTP");//try this method next
			} catch(e) {//if that also fails return false.
				xhr = false;
			}
		}
	}
	return xhr;//return the value of xhr
}

function grabFile(file,div,e){
	var request = getHTTPObject();
	if(div) {
		divCalled = div;
		document.getElementById(divCalled).style.display = 'block';
		if(e){
			if(e.y) document.getElementById(divCalled).style.top = e.y;
			if(e.pageY) document.getElementById(divCalled).style.top = e.layerY;
		}
		request.onreadystatechange = function() {
			parseResponse(request);
		}
	}
	request.open("GET",file,true);
	request.send(null);
}

function parseResponse(request){
	if(request.readyState == 4){
		//if(request.status == 200 || request.status == 304){
			var results = document.getElementById(divCalled);
			results.innerHTML = request.responseText;
		//} else {
			//alert("Something Broke!");
		//}
	}
}

function closeDiv(){
	document.getElementById(divCalled).style.display='none';
}

function search(){
	var url_id = '';
	if(document.getElementById('search').elements['ids[]']){
		var id;
		var ids = document.getElementById('search').elements['ids[]'];
		for(id=0; id<ids.length; id++){
			if(ids[id].checked == true){
				if(ids[id].value != undefined){
					if(url_id) url_id += ','+ids[id].value;
					else url_id = ids[id].value;
				}
			}else document.getElementById('search').check_ids.checked = false;
		}
	}
	var url_loc = '';
	if(document.getElementById('search').elements['locs[]']){
		var loc;
		var locs = document.getElementById('search').elements['locs[]'];
		for(loc=0; loc<locs.length; loc++){
			if(locs[loc].checked == true){
				if(locs[loc].value != undefined){
					if(url_loc) url_loc += ','+locs[loc].value;
					else url_loc = locs[loc].value;
				}
			}else document.getElementById('search').check_locs.checked = false;
		}
	}
	if(document.getElementById('search').check_ids.checked == true) url_loc += '&section='+document.getElementById('search').check_ids.value;
	grabFile('/category.php?s='+document.getElementById('s').value+'&ids='+url_id+'&loc='+url_loc,'results');
}
function check_all_ids(){
	if(document.getElementById('search').elements['ids[]']){
		var id;
		var ids = document.getElementById('search').elements['ids[]'];;
		for(id=0; id<ids.length; id++){
			if(document.getElementById('search').check_ids.checked == true) ids[id].checked = true;
			else ids[id].checked = false;
		}
	}
	search();
}
function check_all_locs(no_search){
	if(document.getElementById('search').elements['locs[]']){
		var loc;
		var locs = document.getElementById('search').elements['locs[]'];
		for(loc=0; loc<locs.length; loc++){
			if(document.getElementById('search').check_locs.checked == true) locs[loc].checked = true;
			else locs[loc].checked = false;
		}
	}
	if(!no_search) search();
}
function link_ids(id){
	var ids = document.getElementById('search').elements['ids[]'];
	if(ids && ids[id]){
		if(ids[id].checked==true) ids[id].checked=false;
		else ids[id].checked=true;
		search();
	}else if(document.getElementById('search').check_ids){
		if(document.getElementById('search').check_ids.checked==true) document.getElementById('search').check_ids.checked=false;
		else document.getElementById('search').check_ids.checked=true;
		check_all_ids();
	}
}
function link_locs(loc,no_search){
	var locs = document.getElementById('search').elements['locs[]'];
	if(locs[loc]){
		if(locs[loc].checked==true) locs[loc].checked=false;
		else locs[loc].checked=true;
		if(!no_search) search();
	}else if(document.getElementById('search').check_locs){
		if(document.getElementById('search').check_locs.checked==true) document.getElementById('search').check_locs.checked=false;
		else document.getElementById('search').check_locs.checked=true;
		check_all_locs(no_search);
	}
}
/* Swazz Javascript Calendar v1.0 By Oliver Bryant http://calendar.swazz.org */
function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}
function checkClick(e) {
	e?evt=e:evt=event;
	CSE=evt.target?evt.target:evt.srcElement;
	if (getObj('fc'))
		if (!isChild(CSE,getObj('fc')))
			getObj('fc').style.display='none';
}
function isChild(s,d) {
	while(s) {
		if (s==d)
			return true;
		s=s.parentNode;
	}
	return false;
}
function Left(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
document.write('<table id="fc" style="position:absolute;border-collapse:collapse;background:#FFFFFF;border:1px solid #ABABAB;display:none" cellpadding=2>');
document.write('<tr><td style="cursor:pointer" onclick="csubm()">&lt;</td><td colspan=5 id="mns" align="center" style="font:bold 13px Arial"></td><td align="right" style="cursor:pointer" onclick="caddm()">&gt;</td></tr>');
document.write('<tr><td align=center style="background:#ABABAB;font:12px Arial">S</td><td align=center style="background:#ABABAB;font:12px Arial">M</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">W</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">F</td><td align=center style="background:#ABABAB;font:12px Arial">S</td></tr>');
for(var kk=1;kk<=6;kk++) {
	document.write('<tr>');
	for(var tt=1;tt<=7;tt++) {
		num=7 * (kk-1) - (-tt);
		document.write('<td id="v' + num + '" style="width:18px;height:18px">&nbsp;</td>');
	}
	document.write('</tr>');
}
document.write('</table>');
document.all?document.attachEvent('onclick',checkClick):document.addEventListener('click',checkClick,false);
var now = new Date;
var sccm=now.getMonth();
var sccy=now.getFullYear();
var ccm=now.getMonth();
var ccy=now.getFullYear();
var updobj;
function lcs(ielem) {
	updobj=ielem;
	getObj('fc').style.left=Left(ielem) + 'px';
	getObj('fc').style.top=Top(ielem)+ielem.offsetHeight+ 'px';
	getObj('fc').style.display='';
}

function evtTgt(e)
{
	var el;
	if(e.target)el=e.target;
	else if(e.srcElement)el=e.srcElement;
	if(el.nodeType==3)el=el.parentNode; // defeat Safari bug
	return el;
}
function EvtObj(e){if(!e)e=window.event;return e;}
function cs_over(e) {
	evtTgt(EvtObj(e)).style.background='#FFCC66';
}
function cs_out(e) {
	evtTgt(EvtObj(e)).style.background='#C4D3EA';
}
function cs_click(e) {
	updobjs=calvalarr[evtTgt(EvtObj(e)).id.substring(1,evtTgt(EvtObj(e)).id.length)].split("/");
	if(updobjs[1]<10) updobjs[1]="0"+updobjs[1];
	if(updobjs[0]<10) updobjs[0]="0"+updobjs[0];
	updobj.value=updobjs[1]+"/"+updobjs[0]+"/"+updobjs[2];
	getObj('fc').style.display='none';

}
var mn=new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
var mnn=new Array('31','28','31','30','31','30','31','31','30','31','30','31');
var mnl=new Array('31','29','31','30','31','30','31','31','30','31','30','31');
var calvalarr=new Array(42);
function f_cps(obj) {
	obj.style.background='#C4D3EA';
	obj.style.font='10px Arial';
	obj.style.color='#333333';
	obj.style.textAlign='center';
	obj.style.textDecoration='none';
	obj.style.border='1px solid #6487AE';
	obj.style.cursor='pointer';
}
function prepcalendar(hd,cm,cy) {
	now=new Date();
	sd=now.getDate();
	td=new Date();
	td.setDate(1);
	td.setFullYear(cy);
	td.setMonth(cm);
	cd=td.getDay();
	getObj('mns').innerHTML=mn[cm]+ ' ' + cy;
	marr=((cy%4)==0)?mnl:mnn;
	for(var d=1;d<=42;d++) {
		f_cps(getObj('v'+parseInt(d)));
		if ((d >= (cd -(-1))) && (d<=cd-(-marr[cm]))) {
			f_cps(getObj('v'+parseInt(d)));
			getObj('v'+parseInt(d)).onmouseover=cs_over;
			getObj('v'+parseInt(d)).onmouseout=cs_out;
			getObj('v'+parseInt(d)).onclick=cs_click;

			if(sd == (d-cd)) getObj('v'+parseInt(d)).style.color = 'red';
			getObj('v'+parseInt(d)).innerHTML=d-cd;
			calvalarr[d]=''+(d-cd)+'/'+(cm-(-1))+'/'+cy;
		}
		else {
			getObj('v'+d).innerHTML='&nbsp;';
			getObj('v'+parseInt(d)).onmouseover=null;
			getObj('v'+parseInt(d)).onmouseout=null;
			getObj('v'+parseInt(d)).style.cursor='default';
			}
	}
}
prepcalendar('',ccm,ccy);
function caddm() {
	marr=((ccy%4)==0)?mnl:mnn;
	ccm+=1;
	if (ccm>=12) {
		ccm=0;
		ccy++;
	}
	prepcalendar('',ccm,ccy);
}
function csubm() {
	marr=((ccy%4)==0)?mnl:mnn;
	ccm-=1;
	if (ccm<0) {
		ccm=11;
		ccy--;
	}
	prepcalendar('',ccm,ccy);
}

// SLIDESHOW
var slideshow2_fadingSpeed = 100;	// Speed of fading (Lower value = faster)
var slideshow2_stats = new Array();
var slideshow2_slideIndex = new Array();
var slideshow2_slideIndexNext = new Array();
var slideshow2_imageDivs = new Array();
var slideshow2_currentOpacity = new Array();
var slideshow2_imagesInGallery = new Array();
var Opera = navigator.userAgent.indexOf('Opera')>=0?true:false;
function createParentDivs(imageIndex,divId){
	var imgObj = document.getElementById(divId + '_' + imageIndex);	
	if(Opera)imgObj.style.position = 'static';
	if(!slideshow2_imageDivs[divId])slideshow2_imageDivs[divId] = new Array();
	slideshow2_imageDivs[divId][slideshow2_imageDivs[divId].length] =  imgObj;
	if(imgObj){
		if(0!=imageIndex) imgObj.parentNode.style.visibility = 'hidden';
		else imgObj.parentNode.style.visibility = 'visible';
		imageIndex++;
		createParentDivs(imageIndex,divId);		
	}
}

function showGallery(divId, dir){
	if(dir==1){
		if(slideshow2_slideIndex[divId]==-1)slideshow2_slideIndex[divId]=0; else slideshow2_slideIndex[divId] = slideshow2_slideIndexNext[divId];
		if(slideshow2_slideIndex[divId]==slideshow2_imageDivs[divId].length-1)slideshow2_slideIndex[divId]=0;
		slideshow2_slideIndexNext[divId] = slideshow2_slideIndex[divId]+1;
		if(slideshow2_slideIndexNext[divId]==slideshow2_imageDivs[divId].length-1)slideshow2_slideIndexNext[divId] = 0;
	}else{
		if(slideshow2_slideIndex[divId]==-1)slideshow2_slideIndex[divId]=1;
		if(slideshow2_slideIndex[divId]==slideshow2_imageDivs[divId].length-1)slideshow2_slideIndex[divId]=0; else slideshow2_slideIndex[divId] =slideshow2_slideIndexNext[divId];
		if(slideshow2_slideIndex[divId]<0)slideshow2_slideIndex[divId]=slideshow2_imageDivs[divId].length-2;
		slideshow2_slideIndexNext[divId] = slideshow2_slideIndex[divId]-1;
		if(slideshow2_slideIndexNext[divId]<0)slideshow2_slideIndexNext[divId] = slideshow2_imageDivs[divId].length-2;
	}
	slideshow2_currentOpacity[divId]=100;
	slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].parentNode.style.visibility = 'visible';
	if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].parentNode.style.display = 'inline';
	if(navigator.userAgent.indexOf('Opera')<0){
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].parentNode.style.visibility = 'visible';
	}
	if(document.all){	// IE rules
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.filter = 'alpha(opacity=100)';
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.filter = 'alpha(opacity=1)';
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.opacity = 0.99;
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.opacity = 0.01;
	}
	revealImage(divId);
}

function showGalleryHelper(divId, dir, timeout){
	if(slideshow2_currentOpacity[divId]>0){
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].parentNode.style.visibility = 'hidden';	
		if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].parentNode.style.display = 'none';
	}
	showGallery(divId, dir);
	setTimeout("showGalleryHelper('"+divId+"',"+dir+","+timeout+")",timeout);
}

function revealImage(divId){
	slideshow2_currentOpacity[divId]-=20;
	if(document.all){
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.filter = 'alpha(opacity='+slideshow2_currentOpacity[divId]+')';
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity[divId])+')';
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.opacity = Math.max(0.01,slideshow2_currentOpacity[divId]/100);
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity[divId]/100)));
	}
	if(slideshow2_currentOpacity[divId]>0){
		setTimeout('revealImage("' + divId + '")',slideshow2_fadingSpeed);
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].parentNode.style.visibility = 'hidden';	
		if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].parentNode.style.display = 'none';
	}
}

function initImageGallery(divId,timeout){
	var slideshow2_galleryContainer = document.getElementById(divId);
	slideshow2_slideIndex[divId] = -1;
	slideshow2_slideIndexNext[divId] = 0;
	
	var galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');
	for(var no=0;no<galleryImgArray.length;no++){
		galleryImgArray[no].id = divId + '_' + no;
	}
	
	slideshow2_imagesInGallery[divId] = galleryImgArray.length;
	createParentDivs(0,divId);
	setTimeout("showGalleryHelper('"+divId+"',1,"+timeout+")",timeout);
}

//RATINGS
function rate(choice){
	document.comment.rating.value = choice;
	fill(choice);
}
function out(){
	fill(document.comment.rating.value);
}
function fill(choice){
	switch(choice){
case '1': document.getElementById('star-2').src = 'images/star-n.png'; document.getElementById('star-3').src = 'images/star-n.png'; document.getElementById('star-4').src = 'images/star-n.png'; document.getElementById('star-5').src = 'images/star-n.png'; break;
case '2': document.getElementById('star-2').src = 'images/star-y.png'; document.getElementById('star-3').src = 'images/star-n.png'; document.getElementById('star-4').src = 'images/star-n.png'; document.getElementById('star-5').src = 'images/star-n.png'; break;
case '3': document.getElementById('star-2').src = 'images/star-y.png'; document.getElementById('star-3').src = 'images/star-y.png'; document.getElementById('star-4').src = 'images/star-n.png'; document.getElementById('star-5').src = 'images/star-n.png'; break;
case '4': document.getElementById('star-2').src = 'images/star-y.png'; document.getElementById('star-3').src = 'images/star-y.png'; document.getElementById('star-4').src = 'images/star-y.png'; document.getElementById('star-5').src = 'images/star-n.png'; break;
case '5': default: document.getElementById('star-2').src = 'images/star-y.png'; document.getElementById('star-3').src = 'images/star-y.png'; document.getElementById('star-4').src = 'images/star-y.png'; document.getElementById('star-5').src = 'images/star-y.png';
	}
}