function openWin(url, width, height) {
	var win;
	var windowName;
	var params;
	windowName  = "buttons";
	params = "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=1,";
	params += "menubar=0,";
	params += "scrollbars=1,";
	params += "resizable=0,";
	params += "top=50,";
	params += "left=50,";
	params += "width="+width+",";
	params += "height="+height;
	win = window.open(url, windowName, params);
}

function openWin2(url, width, height) {
	var win;
	var windowName;
	var params;
	windowName  = "buttons";
	params = "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=0,";
	params += "menubar=0,";
	params += "scrollbars=1,";
	params += "resizable=1,";
	params += "top=50,";
	params += "left=50,";
	params += "width="+width+",";
	params += "height="+height;
	win = window.open(url, windowName, params);
}

function popSend(url, width, height, reqVars) {
	var win;
	var windowName;
	var params;
	windowName  = "buttons";
	params = "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=1,";
	params += "menubar=0,";
	params += "scrollbars=1,";
	params += "resizable=0,";
	params += "top=50,";
	params += "left=50,";
	params += "width="+width+",";
	params += "height="+height;
	win = window.open(url+"?"+reqVars, windowName, params);
}

window.onload = function() {
	setContainerHeight();
}

function setContainerHeight() {
	// if window is bigger than div#container, set #container to height of window so bg image extends to bottom
	var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	if (document.getElementById('container')) {
		if (windowHeight > document.getElementById('container').offsetHeight) {
		  document.getElementById('container').style.height = windowHeight + 'px';
		}
	}
}



function validate_requestform()
{
	if (document.form.name.value == "")
	{
		alert ("Please fill in the 'Your Name'.");
		document.form.name.focus();
		return false;
	}
	if (document.form.email.value == "")
	{
		alert ("Please fill in the 'Email Address'.");
		document.form.email.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.form.email.value)){
		alert ("Please your 'Email Address' is in an incorrect format.");
		document.form.email.focus();
		return false;
	}

	document.form.submit();
	return true;
}



function validate_loginform()
{
	if (document.formlogin.name.value == "")
	{
		alert ("Please fill in the 'User Name'.");
		document.formlogin.name.focus();
		return false;
	}
	if (document.formlogin.password.value == "")
	{
		alert ("Please fill in the 'Password'.");
		document.formlogin.password.focus();
		return false;
	}

	document.formlogin.submit();
	return true;
}


function validate_loginauth()
{
	if (document.formtrial.username.value == "")
	{
		alert ("Please fill in the 'Username'.");
		document.formtrial.username.focus();
		return false;
	}
	if (document.formtrial.password.value == "")
	{
		alert ("Please fill in the 'Password'.");
		document.formtrial.password.focus();
		return false;
	}

	document.formtrial.submit();
	return true;
}


function validate_feedback()
{
	// Radios buttons
	var found_searched = false;
	var found_rank_ease_use = false;
	var found_description_enough = false;
	var found_rate_materials_useful = false;
	var found_rate_materials_effective = false;
	var found_rate_important_central = false;
	var found_would_join = false;
	var found_purpose_easy_understand = false;
	var found_format_eligibility_criteria = false;
	var found_format = false;
	var found_rate_attractive = false;
	var found_rate_clear_navigation = false;
	var found_would_recommend = false;
	var found_would_use = false;

	for (var i=0; i<document.formfeedback.searched.length; i++)  {
		if (document.formfeedback.searched[i].checked)
		{
			found_searched = true;
		}
	}
	if (found_searched == false)
	{
		alert ('Please answer "Have you searched on-line for a clinical trial in the past?"');
		document.formfeedback.searched[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.rank_ease_use.length; i++)  {
		if (document.formfeedback.rank_ease_use[i].checked)
		{
			found_rank_ease_use = true;
		}
	}
	if (found_rank_ease_use == false)
	{
		alert ('Please answer "1) Rank the overall ease of use for searching for a clinical trial and location"');
		document.formfeedback.rank_ease_use[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.description_enough.length; i++)  {
		if (document.formfeedback.description_enough[i].checked)
		{
			found_description_enough = true;
		}
	}
	if (found_description_enough == false)
	{
		alert ('Please answer "3) Was the initial study description under “Search Results” informative enough for you to want to proceed?"');
		document.formfeedback.description_enough[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.rate_materials_useful.length; i++)  {
		if (document.formfeedback.rate_materials_useful[i].checked)
		{
			found_rate_materials_useful = true;
		}
	}
	if (found_rate_materials_useful == false)
	{
		alert ('Please answer "4) Rate how useful these materials are in better understanding the specifics of that clinical trial"');
		document.formfeedback.rate_materials_useful[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.rate_materials_effective.length; i++)  {
		if (document.formfeedback.rate_materials_effective[i].checked)
		{
			found_rate_materials_effective = true;
		}
	}
	if (found_rate_materials_effective == false)
	{
		alert ('Please answer "5) Rate how effective these materials would be for you in choosing to participate in that given clinical trial"');
		document.formfeedback.rate_materials_effective[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.rate_important_central.length; i++)  {
		if (document.formfeedback.rate_important_central[i].checked)
		{
			found_rate_important_central = true;
		}
	}
	if (found_rate_important_central == false)
	{
		alert ('Please answer "6) Rate how important you think having this additional information in one central place would be for you to make an informed decision about participating in that clinical trial"');
		document.formfeedback.rate_important_central[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.would_join.length; i++)  {
		if (document.formfeedback.would_join[i].checked)
		{
			found_would_join = true;
		}
	}
	if (found_would_join == false)
	{
		alert ('Please answer "7) Based on the overall feel of this site would you join the database to receive e-mail alerts for your specific area of interest?"');
		document.formfeedback.would_join[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.purpose_easy_understand.length; i++)  {
		if (document.formfeedback.purpose_easy_understand[i].checked)
		{
			found_purpose_easy_understand = true;
		}
	}
	if (found_purpose_easy_understand == false)
	{
		alert ('Please answer "8) Is the description under “Purpose” informative and easy to understand?"');
		document.formfeedback.purpose_easy_understand[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.format_eligibility_criteria.length; i++)  {
		if (document.formfeedback.format_eligibility_criteria[i].checked)
		{
			found_format_eligibility_criteria = true;
		}
	}
	if (found_format_eligibility_criteria == false)
	{
		alert ('Please answer "9) Is the format for the “Eligibility Criteria” clear and easy to understand?"');
		document.formfeedback.format_eligibility_criteria[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.format.length; i++)  {
		if (document.formfeedback.format[i].checked)
		{
			found_format = true;
		}
	}
	if (found_format == false)
	{
		alert ('Please answer "10) Which method would you prefer for answering medical questions to determine if you qualify for a trial?"');
		document.formfeedback.format[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.rate_attractive.length; i++)  {
		if (document.formfeedback.rate_attractive[i].checked)
		{
			found_rate_attractive = true;
		}
	}
	if (found_rate_attractive == false)
	{
		alert ('Please answer "11) Please rate how attractive and user friendly you find the overall layout and color scheme of Clinical-TrialFinder.com to be."');
		document.formfeedback.rate_attractive[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.rate_clear_navigation.length; i++)  {
		if (document.formfeedback.rate_clear_navigation[i].checked)
		{
			found_rate_clear_navigation = true;
		}
	}
	if (found_rate_clear_navigation == false)
	{
		alert ('Please answer "12) How clear is the over-all navigation of Clinical-TrialFinder.com"');
		document.formfeedback.rate_clear_navigation[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.would_recommend.length; i++)  {
		if (document.formfeedback.would_recommend[i].checked)
		{
			found_would_recommend = true;
		}
	}
	if (found_would_recommend == false)
	{
		alert ('Please answer "14) Would you recommend Clinical-trialfinder.com to a friend or colleague?"');
		document.formfeedback.would_recommend[0].focus();
		return false;
	}
	for (var i=0; i<document.formfeedback.would_use.length; i++)  {
		if (document.formfeedback.would_use[i].checked)
		{
			found_would_use = true;
		}
	}
	if (found_would_use == false)
	{
		alert ('Please answer "15) If you were searching for a clinical trial would you use ClinialTrialFinder.com"');
		document.formfeedback.would_use[0].focus();
		return false;
	}
	if (document.formfeedback.email.value != "")
	{
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.formfeedback.email.value)){
			alert ("'Email Address' is in an incorrect format.");
			document.formfeedback.email.focus();
			return false;
		}
		if (document.formfeedback.confirmemail.value == "")
		{
			alert ("Please fill in the 'Confirm Email'.");
			document.formfeedback.confirmemail.focus();
			return false;
		}
		if (document.formfeedback.email.value != document.formfeedback.confirmemail.value)
		{
			alert ("'Email Address' and 'Confirm Email' do not match.");
			document.formfeedback.confirmemail.focus();
			return false;
		}
	}

	document.formfeedback.submit();
	return true;
}


function validate_stfform()
{
	if (document.formstf.your_name.value == "")
	{
		alert ("Please fill in 'Your Name'.");
		document.formstf.your_name.focus();
		return false;
	}
	if (document.formstf.your_email.value == "")
	{
		alert ("Please fill in 'Your Email'.");
		document.formstf.your_email.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.formstf.your_email.value)){
		alert ("'Your Email' is in an incorrect format.");
		document.formstf.your_email.focus();
		return false;
	}
	if (document.formstf.friends_name.value == "")
	{
		alert ("Please fill in 'Friends Name'.");
		document.formstf.friends_name.focus();
		return false;
	}
	if (document.formstf.friends_email.value == "")
	{
		alert ("Please fill in 'Friends Email'.");
		document.formstf.friends_email.focus();
		return false;
	}
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.formstf.friends_email.value)){
		alert ("'Friends Email' is in an incorrect format.");
		document.formstf.friends_email.focus();
		return false;
	}
	if (document.formstf.message.value == "")
	{
		alert ("Please fill in 'Message'.");
		document.formstf.message.focus();
		return false;
	}

	document.formstf.submit();
	return true;
}



function toggleLayer(whichLayer,mode){

	if (document.getElementById){
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
	}
	else if (document.all){
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
	}
	else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
	}

	if(mode=='close'){style2.display = "none";}
	else if(mode=='open'){style2.display = "block";}
	else{style2.display = style2.display=="block"?"none":"block";}
}



function toggleLayerSwitch(whichLayer,hideLayer,mode){

	if (document.getElementById){
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
	}
	else if (document.all){
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
	}
	else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
	}

	if(mode=='close'){style2.display = "none";}
	else if(mode=='open'){style2.display = "block";}
	else{style2.display = style2.display=="block"?"none":"block";}

	if (document.getElementById){
		// this is the way the standards work
		var style3 = document.getElementById(hideLayer).style;
	}
	else if (document.all){
		// this is the way old msie versions work
		var style3 = document.all[hideLayer].style;
	}
	else if (document.layers){
		// this is the way nn4 works
		var style3 = document.layers[hideLayer].style;
	}

	if(mode=='open'){style3.display = "none";}
	else if(mode=='close'){style3.display = "block";}
	else{style3.display = style3.display=="none"?"block":"none";}
}


function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function checkAll(theForm, element, field) {
	//alert (theForm.checkall.checked);
    for (i = 0, n = theForm.elements.length; i < n; i++)
        if (theForm.elements[i].name.indexOf(field) != -1)
            //theForm.elements[i].checked = true;
			//eval("theForm.elements[" + i + "].checked = theForm.checkall.checked");
			eval("theForm.elements[" + i + "].checked = element.checked");
}

/*----------------Functions for Stylesheet Switcher--------------------*/
/*function setActiveStyleSheet(title, reset) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (reset == 1) {
	  createCookie("wstyle", title, 365);
  }
}

function setStyle() {
	var style = readCookie("wstyle");
	if (style != null) {
		setActiveStyleSheet(style, 0);
	}
}*/



//generic popup function
function popup(u, w, h, n, scroll, loc, resize, tool, menu){
	newwindow = window.open(u, n,'height='+h+',width='+w+',scrollbars='+scroll+',location='+loc+',resizable='+resize+',toolbar='+tool+',menubar='+menu+'');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}


var diseaseId='';
var locationId='';

function getAvailableLocations(disease)
{
	diseaseId=disease;
	var gURL = 'getavailablelocations.php?disease='+diseaseId;
	//create the Cross-browser XMLHttpRequest object
	if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
		xmlhttp=new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			//xmlhttp.overrideMimeType('text/xml');
		}
		xmlhttp.onreadystatechange=loadLocations;
		xmlhttp.open("GET", gURL, true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		//xmlhttp.setRequestHeader("Content-length", parameters.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(null);
	} else if (window.ActiveXObject) { //IE
		xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		if (xmlhttp) {
			xmlhttp.onreadystatechange=loadLocations;
			xmlhttp.open('GET', gURL, false);
			xmlhttp.send();
		}
	}
	// order is not ready if we just changed item style
	//document.getElementById('buttons').style.display='none';
	if (locationId!='') {
		// we could have changed the location after selecting a disiase - reset the locations
		getAvailableColors('');
	}
}

// function to handle asynchronus call
function loadLocations() {
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			document.getElementById('dropdowns').innerHTML=xmlhttp.responseText;
			if (xmlhttp.responseText.indexOf('disabled')<=0) {
				if (document.getElementById('state')) {
					document.getElementById('state').focus();
				}
			}
		}
	}
}



function getAvailableTrials(locationID, trialID, action, layer) {
	sizeId=locationID;
	if (locationID=='') {
		var gURL = 'getavailabletrials.php';
	}else{
		var gURL = 'getavailabletrials.php?disease='+trialID+'&location='+locationID;
	}	
	//create the Cross-browser XMLHttpRequest object
	if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
		xmlhttp=new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}
		xmlhttp.onreadystatechange=loadTrials;
		xmlhttp.open("GET", gURL, true);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) { //IE
		xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		if (xmlhttp) {
			xmlhttp.onreadystatechange=loadTrials;
			xmlhttp.open('GET', gURL, false);
			xmlhttp.send();
		}
	}
	// order is not ready if we just changed size...
	//document.getElementById('buttons').style.display='none';
	//Effect.toggle('search', 'slide', {duration: .5});
	//location.href = location.href + '#search';
	Effect.SlideDown('search', { duration:0.5 });
	//toggleLayer(layer, action);
}

// function to handle asynchronus call
function loadTrials() {
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			document.getElementById('results').innerHTML=xmlhttp.responseText;
		}
	}
}

function selectedColor(pColor) {
	document.getElementById('buttons').style.display='inline';
}


function search(disease, mode, whichLayer, hideLayer)
{
	if (document.getElementById){
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
	}
	else if (document.all){
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
	}
	else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
	}

	if(mode=='close'){style2.display = "none";}
	else if(mode=='open'){style2.display = "block";}
	else{style2.display = style2.display=="block"?"none":"block";}

	if (document.getElementById){
		// this is the way the standards work
		var style3 = document.getElementById(hideLayer).style;
	}
	else if (document.all){
		// this is the way old msie versions work
		var style3 = document.all[hideLayer].style;
	}
	else if (document.layers){
		// this is the way nn4 works
		var style3 = document.layers[hideLayer].style;
	}

	if(mode=='open'){style3.display = "none";}
	else if(mode=='close'){style3.display = "block";}
	else{style3.display = style3.display=="none"?"block":"none";}
}


/* Round Corners */
window.onload=function(){
//	$('case1').makeRounded('top right', {borderColor: '#777', radius: 20});
//	$('example1').makeRounded({radius: 30});

}