function isEmpty(val) {
	if (val == "") {
		return false;
	} else {
		return true;
	}
}

errors = new Array();

colorCount = 0;
function fadeBorder(state) {
	colors = new Array("#fbdddd", "#f7a6a6", "#fc6969", "#fc3434", "#ff0000");
	
	for (i=0;i<errors.length;i++) {
		if (document.getElementById(errors[i])) {
			document.getElementById(errors[i]).style.borderStyle = "solid";
			document.getElementById(errors[i]).style.borderWidth = "1px";
			document.getElementById(errors[i]).style.borderColor = colors[colorCount];
		}
	}
	if (colorCount == 4) {
		window.clearInterval(intval);
		document.getElementById('errMsg').innerHTML = "Please Fill In The Highlighted Fields";
		Effect.BlindDown('errMsg', { duration: 0.3});
		
	}
	colorCount++;
}

function doubleCheck(myForm, type) {
  for (i=0; i < myForm.elements.length; i++) {

	field = myForm.elements[i];

						
						if (field.name == "email")  {
							var status="";
							status = isEmpty(field.value);
							//alert('status is ' + status);
							if (status == false)
								{
								alert('Please Enter Your Email');
								field.focus();
								return false;
								break;
							} else if (field.value.indexOf("@") == -1 || field.value.indexOf(".") == -1) {
								alert('Please Enter A Valid Email');
								field.focus();
								return false;
								break;
							}
						}
			
	}
	
	var check2 = new Array("state22", "preflocation2", "name2", "phone2" ,"email2", "contact_name1", "organisation1", "state11", "telephone1", "email1");
	var check = new Array("state2", "preflocation2", "name2", "phone2" ,"email2", "contact_name1", "organisation1", "state1", "telephone1", "email1");

	for (i=0;i < check.length;i++) {
		if ($(check2[i])) {
			if ($(check2[i]).value == "") {
				errors[errors.length++] = check[i];
			}
		}
	}
	
	if (errors.length != 0) {
		intval = window.setInterval("fadeBorder()", 50);
		return false;
	}
	
	return true;
}
function addStudy(state) {
	
	var case1 = document.getElementById('all');
	var case2 = document.getElementById('selected');

	if (state == 'add') {
		for (i=0; i<= case1.options.length;i++) {
			if (case1.options[i].selected) {
				var op = case1.options[i];
				var newop =document.createElement("option");
				newop.text = op.text;
				newop.value = op.value;
			
				try {
					case2.add(newop, null);
				} catch(ex) {
					case2.add(newop);
				}
				case1.removeChild(op);
				
				
				
			}
		}
	} else if (state == 'remove') {
		for (i=0; i<= case2.options.length;i++) {
			if (case2.options[i].selected) {
				var op = case2.options[i];
				var newop = document.createElement("option");
				newop.text = op.text;
				newop.value = op.value;
			
				try {
					case1.add(newop, null);
				} catch(ex) {
					case1.add(newop);
				}
				case2.removeChild(op);
			}
		}
	}
}
function checkAll() {
	for (i=0; i<document.getElementById('case2').options.length;i++) {
		document.getElementById('case2').options[i].selected = true;
	}
}

function pressHover(dom, state) {

	if (state == 'over') {
		document.getElementById(dom).style.backgroundColor = "#b0b8c2";
	} else {
		document.getElementById(dom).style.backgroundColor = "";
	}
	
}

function changeCase(state, dom) {
	
	if (state == 'over') {
		dom.className = "case_list2";
	} else {
		dom.className = "case_list";
	}
}
function changeSearch(dom, rel) {
	
	if (dom.value == rel) {
		dom.value = "";
	} else if (dom.value == "") {
		dom.value = rel;
	}
}