//VALIDATION
function validEmail(email) {
			var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
			return re.test(email); 
		}
		
//VALIDATION
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
		
//VALIDATION
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
		
//VALIDATION
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
		
//VALIDATION
function isFilled(elm) {
	//alert(elm.type);
	//Last Updated by Sol - 6/14/07
	switch(elm.type){
	case "text":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "password":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "textarea":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "select-one":
		var myindex=elm.selectedIndex;
		if (myindex==0){
		return false;}
		else {return true;}
		break;
	}
}

//VALIDATION
function validateform(formname){
	//last updated on 6/14/07
	//index of is mo betta
	var x = document.forms[formname];
	var allgood = true;
	for (var i=0;i<x.length;i++){
		if (x.elements[i].className.indexOf('required')>-1) {
		 	var thisformname = x.elements[i].name;
			var thisformid = x.elements[i].id;
			if (!isFilled(x.elements[i])) {
				document.getElementById(thisformid).style.background = "#f7f4a6";
				allgood = false;
				} else {
				  document.getElementById(thisformid).style.background = "#ffffff"; 
				}
			}
		}
		if (allgood) {
			return true;
			} else {
			return false;
			}
	}

function subform(formname){
	if(validateform(formname)){		
		document.forms[formname].submit();
	}
}
	
function reggala(formname,validateid){
	//VALIDATE REQUIRED
	if(validateform(formname)){				
	
		//EMAIL IS VALID?
		var email = document.getElementById("email").value;
		var gcemail = document.getElementById("gcemail").value;
		if(!validEmail(email) || !validEmail(gcemail)) {
			document.getElementById("email").style.background = "yellow"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
			} else {	
			submit.form()
			}
	}
}

function reggala09(formname,validateid){
	//VALIDATE REQUIRED
	if(validateform(formname)){				
	
		//EMAIL IS VALID?
		var email = document.getElementById("email").value;
		if(!validEmail(email)) {
			document.getElementById("email").style.background = "yellow"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
			} else {	
			document.galaform.submit();
			}
	}
}


//IMAGE ROLLOVER
//Last Update August 1, 2008
function rolloverInit(){
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].getAttribute('name') == "rollover") {			
			setupRollover(document.images[i]);
		}
	}
}

function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = rollOut;
	thisImage.overImage = new Image();
	thisImage.overImage.src = thisImage.src.replace('/off/','/on/')
	thisImage.onmouseover = rollOver;	
}

function rollOver() {
	this.src = this.overImage.src;
}

function rollOut() {
	this.src = this.outImage.src;
}

// END ROLLOVERS

function ajaxlogin(formname,validateid) {
	//VALIDATE REQUIRED
	if(validateform(formname)){				
		//AJAX POST
		new Ajax.Request('ajax/login.asp', {
		method: "post",
		parameters: Form.serialize(document.forms[formname]),
		onSuccess: function(transport,formname) { 	
			//LOG IN EXISTS?
			
			if (transport.responseText=='true'){			
					document.getElementById(validateid).innerHTML = '';
					document.forms.login.submit();
				} else {
					document.getElementById(validateid).innerHTML = '<span style="position:relative; top:7px;">Invalid Log In</span>';
					document.getElementById('forgot').style.color = "#ff780b";
					document.getElementById('forgot').innerHTML = 'forgot <br />password?'
					if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'appear');
					} else {
					Effect.Shake(validateid);
					}
				}
			}//-onSuccess
			}//-request arguments
			);// new ajax request		
	
	}
	else{
		document.getElementById(validateid).innerHTML = 'Please fill out all the<br /> fields in <span style="color:orange">orange</span>';
		if (document.getElementById(validateid).style.display == "none"){
		Effect.Appear(validateid,'blind');
		} else {
		Effect.Shake(validateid);
		}
		}
		
}

function spiderform(formname,validateid,successid,indicatorid,ajaxpage) {
	//VALIDATE REQUIRED
	if(validateform(formname,'yellow','#f9f7cb')){	
	
		//EMAIL IS VALID?
		var email = document.getElementById("email").value;
		if(!validEmail(email)){
			document.getElementById("email").style.background = "white"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'appear');
					} else {
					Effect.Shake(validateid);
					}
			} else {
			document.getElementById(validateid).style.display = "none";
			document.getElementById(indicatorid).style.display = "block";
			//alert('got here')
			//AJAX POST
			new Ajax.Request(ajaxpage, {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) {		
			document.getElementById(successid).innerHTML = transport.responseText;
			document.getElementById(indicatorid).style.display = "none";
				//alert(transport.responseText);			
				
				}//-onSuccess
			}//-request arguments
			);// new ajax request	
			
			//document.form.formname.submit();	
			}
	} else {
		document.getElementById(validateid).style.display = "block";
		document.getElementById(validateid).innerHTML = "PLEASE FILL IN REQUIRED FIELDS";
		Effect.Shake(validateid);
		}
}

function ordersupplies(formname,validateid,ajaxpage){
	//VALIDATE REQUIRED
	if(validateform(formname)){				
	
		//EMAIL IS VALID?
		var email = document.getElementById("email").value;
		if(!validEmail(email)){
			document.getElementById("email").style.background = "yellow"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
			} else {	
			//AJAX POST
			new Ajax.Request(ajaxpage, {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) { 
			document.getElementById('submitform').innerHTML = '';
			document.getElementById(validateid).innerHTML = transport.responseText;	
			Effect.Appear(validateid,'blind');
			
			}//-onSuccess
			}//-request arguments
			);// new ajax request	
			}
	}
}

function addressother(thename) {
	//alert (thename)
	if (thename == 'My future contact info will be') {
	  document.getElementById('futureaddress').style.display = 'block';
	} else {
	  document.getElementById('futureaddress').style.display = 'none';
	} 
}



function assets(){
	var x=document.getElementsByTagName("div");
	for (var i=0;i<x.length;i++)
  	{
	if (x[i].id.indexOf("assetbox")>-1){
		//alert('a');
		var element = document.getElementById(x[i].id);
		element.style.cssFloat = 'left !important';
		element.style.width = '150px';
		element.style.height = '200px';
		element.style.borderRight = '1px #cccccc solid';
		element.style.borderBottom = '1px #cccccc solid';
		element.style.margin = '4px';
		element.style.background = '#ffffff';
		element.onmouseover = assetrollover;
		element.onmouseout  = assetrollout;
		element.onclick = assetclickme;
	}
  	}
}

function assetclickme(){
	var theid = this.id.replace('assetbox','');
	var linkid = 'link' + theid
	var thelink = document.getElementById(linkid).href;
	window.location.href = thelink;
}

function assetrollover(){
	this.style.border = '2px #cccccc solid';
	this.style.backgroundColor='#F9F9F9';
	this.style.cursor = 'pointer';
	this.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=40);-moz-opacity:.4;';
}

function assetrollout(){
	this.style.borderRight = '1px #cccccc solid';
	this.style.borderBottom = '1px #cccccc solid';
	this.style.borderTop = '0px #cccccc solid';
	this.style.borderLeft = '0px #cccccc solid';
	this.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100);-moz-opacity:1;';
	this.style.backgroundColor='white';
}

function adddiv1(thename,vmatch,longid,reqfield1,classname) {
	if (thename == vmatch) {
	Effect.Appear(longid,'blind');
	document.getElementById(reqfield1).className = classname;
	} else {
	document.getElementById(longid).style.display = 'none';
	document.getElementById(reqfield1).className = ''; } 
} 

function aspddivs(thename,vmatch,longid1,longid2) {
	if (thename == vmatch) {
	document.getElementById(longid2).style.display = 'none';
	Effect.Appear(longid1,'blind');
	document.getElementById('FellowshipProgram').className = 'formborder required';
	document.getElementById('CompletionDate').className = 'formborder required';
	document.getElementById('DermatopathologyPosition').className = 'formborder required';
	document.getElementById('GeographicLocationDesired').className = 'formborder required';
	document.getElementById('q2').className = 'formborder required';
	document.getElementById('q4').className = 'formborder';
	document.getElementById('CurrentResidency').className = 'formborder';
	document.getElementById('Program').className = 'formborder';
	
	} else {
	document.getElementById(longid1).style.display = 'none';
	Effect.Appear(longid2,'blind');
	document.getElementById('FellowshipProgram').className = 'formborder';
	document.getElementById('CompletionDate').className = 'formborder';
	document.getElementById('DermatopathologyPosition').className = 'formborder';
	document.getElementById('GeographicLocationDesired').className = 'formborder';
	document.getElementById('q2').className = 'formborder';
	document.getElementById('q4').className = 'formborder required';
	document.getElementById('CurrentResidency').className = 'formborder required';
	document.getElementById('Program').className = 'formborder required';
	 } 
} 

function spiderwindow(url, width, height){
    mywindow = window.open(url, 'windowname','location=0,status=0,scrollbars=0,width=' + width +',height=' + height);
    mywindow.focus(); 
 } 


window.onload = masterloader;

function masterloader(){
	rolloverInit();
	assets();
}