/*Set the directoty for the php files*/

/*DO NOT EDIT BELOW THIS LINE
PROPERTY OF skyfirestudio.com
YOU ARE NOT ALLOWED TO USE ANY PORTION OF THIS CODE
WITH OUT EXPLICIT CONSENT FROM skyfirestudio.com, we take payment in the form of beer, skis and or old star wars flicks before George Lucas Ruined them.*/


//once we click on the graph to show the list, and then we click show graph, we need
//to repopulate the list with the whole list based on the overall date ranges....
//if we keep the original data in an array we should be okay
//right now i addressed this by just making it refresh like in ie, Ill come back to this though
var orginalList = new Array();


function ChartClickOn(data) {

	if (document.getElementById('toggler') != null && document.getElementById('show_vertlist') != null && document.getElementById('show_vertgraph') != null) {

	var toggs = document.getElementById('toggler');
	
	var graph = document.getElementById('show_vertgraph');
	var vlist = document.getElementById('show_vertlist');
	
	
	var myswitch = toggs.innerHTML;
	
	if (myswitch == 'SHOW LIST') {
	
	
	//we need to now populate the list
	grabSpecificDateList(data);
	
	toggs.innerHTML = 'SHOW GRAPH';
	graph.style.display = 'none';
	vlist.style.display = 'block';
	
	//hide the date range and the stats
	if (document.getElementById('stb_stats') != null && document.getElementById('stb_dateexplain') != null) {
	document.getElementById('stb_stats').style.display = 'none';
	document.getElementById('stb_dateexplain').style.display = 'none';
	}
	
	
	//now we need to set the atribut to reload the page
		
		//if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 
		var where = location.href;
		toggs.setAttribute('href', where);
			
			//}
			
			
	} else {
		
		toggs.innerHTML = 'SHOW LIST';
		graph.style.display = 'block';
		vlist.style.display = 'none';
		
		
		
		
	}
	
	}
}




function toggleVertList() {

	if (document.getElementById('toggler') != null && document.getElementById('show_vertlist') != null && document.getElementById('show_vertgraph') != null) {

	var toggs = document.getElementById('toggler');
	
	var graph = document.getElementById('show_vertgraph');
	var vlist = document.getElementById('show_vertlist');
	toggs.onclick = function() {
	
	var myswitch = toggs.innerHTML;
	
	if (myswitch == 'SHOW LIST') {
	
	toggs.innerHTML = 'SHOW GRAPH';
	graph.style.display = 'none';
	vlist.style.display = 'block';
	//set the form value to list
	if (document.getElementById('showlistinput') != null) {
	
	document.getElementById('showlistinput').value = '1';
	
	}
	
	
	} else {
	
		toggs.innerHTML = 'SHOW LIST';
		graph.style.display = 'block';
		vlist.style.display = 'none';
		
		//set the form value to list
	if (document.getElementById('showlistinput') != null) {
	
	document.getElementById('showlistinput').value = '0';
	
	}
		
		
	}
	
	}
}

}

//how do i know what to query???
//by the url

var getVars = document.getElementById("stb_verttracker").src.toLowerCase().split('?');
var uris = getVars[1];

var divHolder = 'replaceme';

var file = 'http://www.skiingthebackcountry.com/viewmorevert.php?'+uris;


function initMore () {


if (document.getElementById('showmorebutton') != null) {


document.getElementById('showmorebutton').onclick = function() {

grabVertTracker();

}

}


}



//This is for grabbing specific date entries
function grabSpecificDateList(data) {

	var request = getHTTPObject();
  if (request) {
    request.onreadystatechange = function() {
      parseResponseDATE(request);
    };
    
    
    //replace more button with loading gif.
    
    //clear out the old stuff
    if (document.getElementById('vertlist') != null) {
    
    //we can this array up in the orginal click on function
    orginalList[0] = document.getElementById('vertlist').innerHTML;
    document.getElementById('vertlist').innerHTML = '';
    
    }
 

    
    
    request.open("GET", 'graphbox.php?id='+data, true);
    request.send(null);
    return true;
  } else {
    return false;
 
 
  }

}

function parseResponseDATE(request) {
  

  
	if (request.readyState == 4) {
    if (request.status == 200 || request.status == 304) {
      
     if (document.getElementById('vertlist') != null) {
      
     
      

      
      var details = document.getElementById('vertlist');
      details.innerHTML += request.responseText;
       
    	//initMore();
    	
     }
      
    }
  }
}

//end get specific date fnctions//////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////




function grabVertTracker() {

	var request = getHTTPObject();
  if (request) {
    request.onreadystatechange = function() {
      parseResponse(request);
    };
    
    
    //replace more button with loading gif.
    
    
    
  //get our start
  if (document.getElementById('morestuff') != null) {
 
 
 
  var hd = document.getElementById('morestuff');
  var rows = hd.getElementsByTagName('span');
  var startArray = rows[0].id.split('_');
  var startID = startArray[1];
  
  //replace more button with loading gif.
  document.getElementById('morestuff').innerHTML = '<img src="/site_images/loading2.gif" style="width:33px; height:32px" alt="Loading"/> Loading';
  
  
  
  }
    
    request.open("GET", file+'&start='+startID, true);
    request.send(null);
    return true;
  } else {
    return false;
 
 
  }

}

//This gets the vertracker and inserts it into the page
function parseResponse(request) {
  

  
	if (request.readyState == 4) {
    if (request.status == 200 || request.status == 304) {
      
     if (document.getElementById(divHolder) != null && document.getElementById('vertlist') != null && document.getElementById('morestuff') != null) {
      
     
      var d = document.getElementById('morestuff');
      d.parentNode.removeChild(d);

      
      var details = document.getElementById(divHolder);
       
       details.innerHTML += request.responseText;
       
    
     
       
      	
      	initMore();
     }
      
    }
  }
}


function getHTTPObject() {
  var xhr = false;
  if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xhr = false;
      }
    }
  }
  return xhr;
}





//this is our multiple onload fucntion
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


//iniate the display
addLoadEvent(initMore);
addLoadEvent(toggleVertList);

