// JavaScript Document


/*
This made objects fade away when the window 
went beneath a certain width and reapperar when expanded

var ua=navigator.userAgent;
var version=get_IE_version();
var expanded=new Array();

function get_IE_version(){
	var offset=ua.indexOf("MSIE ");
	return parseFloat(ua.substring(offset+5, ua.indexOf(";", offset)));	
	}

var div_opacities=new Array();
var div_timers=new Array();

function fade_down_ff(d, endOp){
	var obj=document.getElementById
		if(!div_opacities[d]) div_opacities[d]=0;
		div_opacities[d]-=0.1;
		document.getElementById(d).style.opacity=div_opacities[d];
		if(div_opacities[d]<=endOp){
			clearInterval(div_timers[d])
		}
}

function fade_ff(d, startOp, endOp, inc){
		if(!div_opacities[d]) div_opacities[d]=startOp
		
		if(endOp>startOp){
				div_opacities[d]+=inc;
				if(div_opacities[d]>endOp){
					clearInterval(div_timers[d])
				}else{
					document.getElementById(d).style.opacity=div_opacities[d];
					}
		}else{
				div_opacities[d]-=inc;
				if(div_opacities[d]<(endOp-inc)){
					clearInterval(div_timers[d])
				}else{
					document.getElementById(d).style.opacity=div_opacities[d];
					}
		}
}

function init_fade(d, endOp, inc){
		var obj=document.getElementById(d)
		var style = document.defaultView.getComputedStyle(obj, '');	
		startOp=style.opacity
		//alert(style.opacity)
		div_timers[d]=setInterval("fade_ff('"+d+"', "+startOp+", "+endOp+", "+inc+")", 30);
	}

if(version>=0){	
//its just not worth my time to make this work in ie	 - please get a proper browser	
}else{
		window.onresize=function(){
				if(document.body.clientWidth<=955){
							init_fade('col3', 0, 0.1);
				}else{
					if(document.body.clientWidth>=990){
							init_fade('col3', 1, 0.1);
					}
					}
		}
}
*/

/**********************************************************\

	CALENDAR SCRIPTS
	Extra ajax object

\*********************************************************/

function createQCObject() { 
   var req; 
   if(window.XMLHttpRequest){ 
      // Firefox, Safari, Opera... 
      req = new XMLHttpRequest(); 
   } else if(window.ActiveXObject) { 
      // Internet Explorer 5+ 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
   } else { 
      alert('Problem creating the XMLHttpRequest object'); 
   } 
   return req; 
} 

// Make the XMLHttpRequest object 
var http = createQCObject(); 

function displayQCalendar(m,y, div, expanded) {
	var ran_no=(Math.round((Math.random()*9999))); 
	var expn=(expanded==true)? 'true' : 'false'
	http.open('get', ajaxPath+'?m='+m+'&y='+y+'&div='+div+'&expanded='+expn+'&ran='+ran_no);
   	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) { 
      		var response = http.responseText;
      		if(response) { 
			//alert('ajax responded')
				document.getElementById(div).innerHTML = http.responseText; 
      		} 
   		} 
	} 
   	http.send(null); 
}


var open_details=new Array();
var edit_on=false
function showhide_by_class(cls, containerid, switch_edit_on) {
	if(typeof(switch_edit_on)!='undefined') edit_on=switch_edit_on
		var container=(containerid)? document.getElementById(containerid) : document
		tags=container.getElementsByTagName('*')
		attr=(edit_on)? 'none' : 'inline'
		for (var i=0; i<tags.length; i++) {		
					if (tags[i].className==cls) tags[i].style.display=attr;
		}
		edit_on=!edit_on
} 

function hideall_by_class(cls, containerid) {
		var container=(containerid)? document.getElementById(containerid) : document
		tags=container.getElementsByTagName('*')
		for (var i=0; i<tags.length; i++) {		
					if (tags[i].className==cls) tags[i].style.display='none';
		}
} 
/**********************************************************\

	swap
makes one element (id) disappear while another appears

\*********************************************************/

function swap(id1, id2){
var args=swap.arguments
for(n=0;n<args.length;n++){
			if(version>4){
					style=document.getElementById(args[n]).currentStyle
			}else{
					var element = document.getElementById(args[n]);
					var style = document.defaultView.getComputedStyle(element, '');			
					}
			document.getElementById(args[n]).style.display=(style.display=="none")? "block" : "none";		
			}	
}
/**********************************************************\

swap_this_img
very simple image swap

\*********************************************************/

path='assets/image/bigbuttons/';
function swap_this_img(obj, new_img){
obj.src=path+new_img
}

/**********************************************************\

	ajax_reply: sends GET variables survey and reply to script reply_add.php which should respond with a thank you
on no response outputs unsure message

\*********************************************************/

function ajax_reply(survey, reply){
		  var xmlHttp;
		  try{
					// Firefox, Opera 8.0+, Safari
					xmlHttp=new XMLHttpRequest();
			}
		  catch (e){
			// Internet Explorer
			try{
					  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  }
			catch (e){
			  try{
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
			  catch (e){
						alert("Your browser does not support AJAX!");
						return false;
				}
			  }
			}// catches closing
	
/*For reasons I couldn't fathom here, using GET caused the data to be submitted twice - tried return false and looked around a bit, using POST solved the problem. Thanks to Open JS*/
	
			var url = "reply_add_post.php";
			var params = "survey="+survey+"&reply="+reply;
			xmlHttp.open("POST", url, true);
			
			//Send the proper header information along with the request
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			
			xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
				if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
					document.getElementById('survey').innerHTML='<p>'+xmlHttp.responseText+'</p>';
				}
			}
			xmlHttp.send(params);
	
  } // end ajaxReply
 
/**********************************************************\

	 Specific to survey add and edit
	 Sets a hidden field called current trigger to 1 or 0 to indicate whether this should be the current survey or not
	 Changes the style of the calling object to indicate current status

\*********************************************************/
 
currentstatus=false

function make_current_survey(obj){
		currentstatus=!currentstatus
		if(currentstatus){
				obj.style.backgroundColor="#FF5200";
				obj.style.color="white";
				obj.style.fontWeight="bold";
				obj.style.borderColor="black";
				document.getElementById('current_trigger').value="1";
		}else{
				obj.style.backgroundColor="white";
				obj.style.color="black";
				obj.style.fontWeight="normal";
				obj.style.borderColor="#FCDAC2";
				document.getElementById('current_trigger').value="0";
		}
		obj.blur()
}

/**********************************************************\

	SHOW HIDDEN
	
	adapt so more link doesn'ty show on divs that don't expand or link somewhere else?

\*********************************************************/

var div_showing=new Array();

function onload_actions(){
/*		var num_hidden_divs= 1
		for(var n=1;n<=num_hidden_divs;n++){
				if(obj=document.getElementById('hidden_'+n)){
						obj.style.display="none"
				}
		}*/
		hideall_by_class('hidden', 'content')
}

function show_hidden_div(div_num){
		if(typeof(div_showing[div_num])=="undefined") div_showing[div_num]=false
		document.getElementById('hidden_'+div_num).style.display=(div_showing[div_num])? "none" : "block"
		document.getElementById('continue_'+div_num).innerHTML=(div_showing[div_num])? "More about this >>" : "Put this away"
		div_showing[div_num]=!div_showing[div_num]
}

var admin_open=false
function show_admin_panel(){	
	document.getElementById('admin-panel').style.display=(admin_open)? 'none' : 'block';
	admin_open=!admin_open
	}
	
function change_text_rule(styleSheetIndex, cssRuleIndex,value){
	if(version>=4){// version is picked up from x-fadeslides so watch deployment
			document.styleSheets[styleSheetIndex].rules[cssRuleIndex].style.fontSize=value;
		}else{
			document.styleSheets[styleSheetIndex].cssRules[cssRuleIndex].style.fontSize=value;
		}
}	


