// Datachase Javascripts

function safeEmail(name,domain,display){
	emailAddress=(name +'@'+domain);
	if(display.length==0) display=emailAddress;
	document.write('<A href="mailto:' + emailAddress + '">' + display + '</a>');

}

function expandText(opp,line){
	toClose="comment_"+line;
	toOpen="expand_"+line;
	if(opp==1){
		document.getElementById(toClose).style.display="none";
		document.getElementById(toOpen).style.display="inline";
	}else{
		document.getElementById(toClose).style.display="inline";
		document.getElementById(toOpen).style.display="none";
	}
}

function saveData(type,page,section){
	// build url
	var myComment = document.getElementById('commentBox').value;	
	var myName  = document.getElementById('contributor').value;
	
	var query = "&comment=" + myComment + "&contributor=" + myName;
	
	var pageQuery='&p='+page;
	var sectionQuery='&s='+section
	ajaxCall='includes/ajaxService.php?m=list&t=1'+pageQuery+sectionQuery+query;	
	ajaxFunction(ajaxCall,'ajax_response_comments',2);

	document.getElementById('commentBox').value="";
	document.getElementById('contributor').value="";
}



function ajaxFunction(requestURL,targetControlId,controlType){
	var ajaxRequest;  
	//create appropriate ajax request ohject for browser
	try{
		ajaxRequest = new XMLHttpRequest();	// Opera 8.0+, Firefox, Safari
	} catch (e){		
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");		// Internet Explorer Browsers
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");	// older Internet Explorer Browsers
			} catch (e){				
				alert("Your browser doesn't support ajax");		// unsupported
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		
		if(ajaxRequest.readyState == 4){
			if(controlType==1)				// target has a value field
				document.getElementById(targetControlId).value = ajaxRequest.responseText;
			else if (controlType==2)			// target is text
				document.getElementById(targetControlId).innerHTML = ajaxRequest.responseText;
						
			//document.myForm.time.value = ajaxRequest.responseText;
		}
	}
	
	// get the data 
	ajaxRequest.open("GET", requestURL, true);
	ajaxRequest.send(null); 

}
