
var contentavil=true;

var scroll=true;
//find out if this is IE or other			
if (navigator.appName.match("Explorer")){
	var other = false;
}else{
	var other=true;
}

var pos=0;
//scroll speed mills sec
var time=500;
//secound speed for fast scroll
var time2=250;
//steps to high speed
var steps=3;
var step=1;

function validateSubForm()
{
	var flag=false;
	var obj=document.frmSub;
	if(obj.e.value=="")
	{
			alert("Please Enter Email Address");
			return false;
	}
	else
	{
		return true;
	}


}

function validate()
{

	var flag=false;
	var obj=document.qick;
	//alert(obj.propref.value);
	if(obj.propref.value=="")
	{
		
		if(obj.area.value=="")
		{
			alert("Please Select at least one Search Criteria or Enter Property Reference");
			return false;
		}
	}
	else
	{
		return true;
	}
}

function stopall(){
	scroll = false;
}

function startfwd() {
       
        scroll = true;
        step = 1;
        scrollfwd();
       
}

function scrollfwd(){
	if (scroll == true){
		pos++;
		if (pos < contentavil.length){
			
			if (other == false){
						
				document.getElementById("calender").innerHTML = contentavil[pos].firstChild.data;
			}else{
				document.getElementById("calender").innerHTML = contentavil[pos].firstChild.nextSibling.data;
			}
			
			if (step <= steps){
				timer = time;
			}else{
				timer = time2;
			}
			step++;
			
			var t = setTimeout("scrollfwd()",timer);
			
		}else{
			pos = contentavil.length - 1;
		}
	}
}

function startrwd() {
       
        scroll = true;
        step = 1;
        scrollrwd();
       
}

function scrollrwd(){
	if (scroll == true){
		pos--;
		if (other == false){
					
			document.getElementById("calender").innerHTML = contentavil[pos].firstChild.data;
		}else{
			document.getElementById("calender").innerHTML = contentavil[pos].firstChild.nextSibling.data;
		}
		if (pos > 0){
			
			if (step <= steps){
				timer = time;
			}else{
				timer = time2;
			}
			step++;
		
			var t = setTimeout("scrollrwd()",timer);
			
		}else{
			pos = 0;
		}
	}
}

function navigate(ref,month, img, strStart) {
        //see if the vaule is in the xml array and if not load in
        //next load in a new load of xml buffer if had to load from site buffer = 20 weeks
        var found = false;
        
        for(var i =0; i < contentavil.length; i++){
        	
        	if (contentavil[i].getAttribute("link").match(month)){
        		found = true;
        		if (navigator.appName.match("Explorer")){
        			//alert("IE is slow");
        			document.getElementById("calender").innerHTML = contentavil[i].firstChild.data;
        		}else{
        			document.getElementById("calender").innerHTML = contentavil[i].firstChild.nextSibling.data;
        		}
        	}
        	
        }
        
        if(found == false){
			var url = "/_availibility.php?propertyRef="+ref+"&next="+month+"&image="+img+"&stringStart="+strStart+"&ms="+ new Date().getTime();
			if(window.XMLHttpRequest) {
					req = new XMLHttpRequest();
			} else if(window.ActiveXObject) {
					req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			req.open("GET", url, true);
			req.onreadystatechange = callback;
			req.send(null);
			//need buffer load here for next start point
		}
}

function loadavil(ref) {
	
	var url = "/_availibilityXML.php?propertyRef="+ref+"&ms="+ new Date().getTime();
	if(window.XMLHttpRequest) {
			request = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
			request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	request.open("GET", url, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			initCalbox();
			var xmlDoc = request.responseXML;
			contentavil = xmlDoc.documentElement.getElementsByTagName("avail");
			//alert(contentavil[0].getAttribute("link"));
			
			if (other == false){
				document.getElementById("calender").innerHTML = contentavil[0].firstChild.data;
				pos = 0;
			}else{
				document.getElementById("calender").innerHTML = contentavil[0].firstChild.nextSibling.data;
				pos = 0;
				//alert(contentavil[0].getElementsByTagName("caltext")[0].firstChild.nextSibling.data);
			}
		}
	}
	
	request.send(null);
	
}


function navigateImg(img,ref, month, strStart ) {
        var url = "/_scrollingImage.php?image="+img+"&propertyRef="+ref+"&next="+month+"&stringStart="+strStart+"&ms="+ new Date().getTime();
        if(window.XMLHttpRequest) {
                req = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
                req = new ActiveXObject("Microsoft.XMLHTTP");
        }

        req.open("GET", url, true);
        req.onreadystatechange = callbackImg;
        req.send(null);
}

function callback() {
        if(req.readyState == 4) {
                if(req.status == 200) {
                        response = req.responseText;
								
                        document.getElementById("calender").innerHTML = response;
                } else {
                        alert("There was a problem retrieving the data:\n" + req.statusText);
                }
        }
}

function callbackImg() {
        if(req.readyState == 4) {
                if(req.status == 200) {
                        response = req.responseText;
								
                        document.getElementById("imageScroller2").innerHTML = response;
                } else {
                        alert("There was a problem retrieving the data:\n" + req.statusText);
                }
        }
}
	
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height){
  if(popUpWin){
	if(!popUpWin.closed){
	  popUpWin.focus;
	} else {
	  popUpWin=0;
	}
  }
  if(!popUpWin){
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  }
}

// Short Break JavaScript

function loadsbavil(ref) {
	
	var url = "/_sbAvailibilityXML.php?propertyRef="+ref+"&ms="+ new Date().getTime();
	if(window.XMLHttpRequest) {
			request = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
			request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	request.open("GET", url, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			initCalbox();
			var xmlDoc = request.responseXML;
			contentavil = xmlDoc.documentElement.getElementsByTagName("avail");
			//alert(contentavil[0].getAttribute("link"));
			
			if (other == false){
				document.getElementById("sbcalender").innerHTML = contentavil[0].firstChild.data;
				pos = 0;
			}else{
				document.getElementById("sbcalender").innerHTML = contentavil[0].firstChild.nextSibling.data;
				pos = 0;
				//alert(contentavil[0].getElementsByTagName("caltext")[0].firstChild.nextSibling.data);
			}
		}
	}
	
	request.send(null);
	
}

function amountOfDays(amount){
				document.getElementById('days').value=amount; // this does not work when re-selecting dates. inline provides a temp soltution. caching amount?
				return;
			}
			
function selectDays(fromDate){
	
	
	// check to see if any dates have been previously selected
	if (document.getElementById('store').value != ''){
		
		//de select them
		deSelectDays(document.getElementById('store').value);

	}
	
	// the amount of days has the user chosen to break for
	amountOfDays = document.getElementById('days').value;
	
	// generate the highest date that needs selecting 
	toDate = fromDate + (amountOfDays - 1);
	
	// change the icons to selected for the days required
	for(i=fromDate;i<=toDate;i++){
		
		document.getElementById(i).style.backgroundImage = 'url(../../images/icon_selected.gif)';
			
	}
	
	storeDays(fromDate, toDate);
	
	return;
}

// store currently selected days so they can be de selected if and when a new bunch is chosen
function storeDays(fromDate, toDate){
		
		var storedDays = new Array();
		var arrayString = '';
		var arrayStart = 0;
		
		// cycle through days that need storing (from id to rd)
		for(i=fromDate;i<=toDate;i++){
			
			// create string for storing in hidden input use a comma as a delim (leave a comma off the last one)
			if (toDate == i){
				
				arrayString += i;
				
			}else{
				
				arrayString += i;
				arrayString += ',';
				
			}
			
			//storedDays[arrayStart] = i;
			
			arrayStart++;
			
		}
		
		// store string in a html var
		document.getElementById('store').value = arrayString;
		
	}

// De-Select previous date choices
function deSelectDays(storedDays){
	
		var temp = new Array();
		
		// divide out the dates
		temp = storedDays.split(',');
		
		// change each icon from selected back to available
		for(i=0;i<temp.length;i++){
			
			document.getElementById(temp[i]).style.backgroundImage = 'url(../images/icon_available.gif)';
			
		}
	
}

// Deal with month changeovers
