//DOS BOOK

function mybook(thebox,dosid,name,specialtytest){
    if (thebox.checked == true){
        //alert('add');
        addtobook(dosid,name,specialtytest);
    } else {
        removefrombook(dosid);
        //alert('remove');
    }
}

//ADDALL
function addall(){
    //AJAX REQUEST
	    new Ajax.Request('addall.aspx?refresh='+ new Date().getTime(), {
	    method: "get",
	    onComplete: function(transport) { 
	        alert('All Tests have been Added.  Click on My Book to view them.')
		    //document.getElementById('message'+dosid).innerHTML = '<b>ADDED!</b>';
		    //document.getElementById('message2'+dosid).innerHTML = '<b>ADDED!</b>';
		    //document.getElementById('dosrow'+dosid).style.backgroundColor='#F9F9F9';
		    //document.getElementById("searchindicator").style.display='none';
		    }//-onSuccess
	      }//-request arguments
	    );// new ajax request	
	}

//REMOVE ALL
function removeall(){
    //AJAX REQUEST
	    new Ajax.Request('removeall.aspx?refresh='+ new Date().getTime(), {
	    method: "get",
	    onComplete: function(transport) { 
	        alert('All Tests have been Removed');
	        //refreshdos('refreshdos','mybook=1');
	        document.location.reload();
		    }//-onSuccess
	      }//-request arguments
	    );// new ajax request	
	}
	
//ADD TO BOOK
function addtobook(dosid,name,specialtytest){
    //AJAX REQUEST
	    new Ajax.Request('addtobook.aspx?refresh='+ new Date().getTime() + '&' + 'id=' + dosid + '&name=' + name + '&st=' + specialtytest, {
	    method: "get",
	    onComplete: function(transport) { 
		    document.getElementById('bookcount').innerHTML = '(' + transport.responseText + ')';
	      
	        if (transport.responseText > 0){
	            document.getElementById('printit').style.display = 'block';
	            document.getElementById('mbl').className = 'mybookon';
	            document.getElementById('mbl').href="buildbook.aspx?Loading...";
	            document.getElementById('mbl').setAttribute("target", "_blank");
	        }else {
	            document.getElementById('printit').style.display = 'none';
	            document.getElementById('mbl').className = 'mybookoff';
	            document.getElementById('mbl').href="#";
	            document.getElementById('mbl').removeAttribute("target");
	        }
		    //document.getElementById('message'+dosid).innerHTML = '<b>ADDED!</b>';
		    //document.getElementById('messagetwo'+dosid).innerHTML = '<b>ADDED!</b>';
		    //document.getElementById('dosrow'+dosid).style.backgroundColor='#F9F9F9';
		   
		    //document.getElementById("searchindicator").style.display='none';
		    }//-onSuccess
	      }//-request arguments
	    );// new ajax request	
	}
	 
//REMOVE FROM BOOK
function removefrombook(dosid){
    //AJAX REQUEST
	    new Ajax.Request('removefrombook.aspx?refresh='+ new Date().getTime() + '&' + 'id=' + dosid, {
	    method: "get",
	    onComplete: function(transport) { 
	         document.getElementById('bookcount').innerHTML = '(' + transport.responseText + ')';
	         if (transport.responseText > 0){
	            document.getElementById('printit').style.display = 'block';
	            document.getElementById('mbl').className = 'mybookon';
	             document.getElementById('mbl').href="buildbook.aspx?Loading...";
	             document.getElementById('mbl').setAttribute("target", "_blank");
	         }else {
	            document.getElementById('printit').style.display = 'none';
	            document.getElementById('mbl').className = 'mybookoff';
	            document.getElementById('mbl').href="#";
	            document.getElementById('mbl').removeAttribute("target");
	         }
	        //refreshdos('refreshdos','mybook=1');
	       // document.location.reload();
	       
	        //document.getElementById('message'+dosid).innerHTML = 'REMOVED!';
		    //document.getElementById('dosrow'+dosid).innerHTML = '';
		    //document.getElementById("searchindicator").style.display='none';
		    }//-onSuccess
	      }//-request arguments
	    );// new ajax request	
	}	    

//DOS ROLLOVER
function productrollover(){
	var x=document.getElementsByTagName("div");
	for (var i=0;i<x.length;i++)
  	{
	if (x[i].id.indexOf("dosrow")>-1){
		var element = document.getElementById(x[i].id);
		//element.style.background = 'white';
		//ROLL
		element.onmouseover = function(){
		    var messageid = this.id.replace('dosrow','');
		    document.getElementById("add"+messageid).style.display='block';
		    document.getElementById("messagetwo"+messageid).style.display='none';
		    this.style.backgroundColor='#e8ecd7';
		    //this.style.borderTop = '1px solid #000000';
	        //this.style.cursor = 'pointer';
		};
		//OUT
		element.onmouseout  = function(){
		    var messageid = this.id.replace('dosrow','');
		    document.getElementById("messagetwo"+messageid).style.display='block';
		    document.getElementById("add"+messageid).style.display='none';
		    if (document.getElementById("messagetwo"+messageid).innerHTML != '<b>ADDED!</b>'){
		    this.style.backgroundColor='#f3f7ea';
		    }

		};
		
		//element.onclick = clickme;
		
//		element.onclick = function(){
//		    var messageid = this.id.replace('dosrow','');
//	        var linkid = 'link' + messageid
//	        var thelink = document.getElementById(linkid).href;
//	        window.location.href = thelink;
//		};
	}
  	}
}

function toggledivs(divtoshow,divtohide){
	if (document.getElementById(divtoshow).style.display == 'none'){
	document.getElementById(divtohide).style.display = 'none';
	document.getElementById(divtoshow).style.display = 'block';
	//Effect.toggle(divtoshow,'appear');
	} else {
	document.getElementById(divtohide).style.display = 'block';
	document.getElementById(divtoshow).style.display = 'none';
	}
}

function changepass(formname,theid,color1,color2) {
//VALIDATE REQUIRED
	if(validateform(formname,color1,color2)){
			//AJAX POST
			new Ajax.Request('sc_changepassword.aspx', {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onSuccess: function(transport,formname) { 
				if (transport.responseText=='true'){	
					document.getElementById(theid).innerHTML = "Your password has been changed."
					//Effect.Appear(theid,'blind');
					//var t = setTimeout("Effect.toggle('" + validateid + "');",2000);
				} else {
					document.getElementById(theid).innerHTML = transport.responseText;
					if (document.getElementById(theid).style.display == "none"){
					Effect.Appear(theid,'blind');
					} else {
					Effect.Shake(theid);
					}
				}
				}
				}
				);// new ajax request
			} else {
				document.getElementById(theid).innerHTML = 'Invalid Entry';
				if (document.getElementById(theid).style.display == "none"){
					Effect.Appear(theid,'blind');
					} else {
					Effect.Shake(theid);
			}
		
	}
}

//EMAIL PASSWORD
function emailpassworda(formname,theid,color1,color2) {
	//VALIDATE REQUIRED
	if(validateform(formname,color1,color2)){
		//AJAX POST
		new Ajax.Request('sc_emailpassword.aspx', {
		method: "post",
		parameters: Form.serialize(document.forms[formname]),
		onSuccess: function(transport,formname) { 
			if (transport.responseText=='true'){	
				document.getElementById(theid).innerHTML = 'Please check your email to continue.';
				//Effect.Appear(theid,'blind');
				//var t = setTimeout("Effect.toggle('" + theid + "');",4000);
			} else {
				document.getElementById(theid).innerHTML = transport.responseText;
				if (document.getElementById(theid).style.display == "none"){
				Effect.Appear(theid,'blind');
				} else {
				Effect.Shake(theid);
				}
			}
			}
			}
			);// new ajax request
		} else {
			document.getElementById(theid).innerHTML = 'Invalid Entry';
			document.getElementById("passwordemail").style.background = "yellow"; 
			if (document.getElementById(theid).style.display == "none"){
				Effect.Appear(theid,'blind');
				} else {
				Effect.Shake(theid);
		}
		
	}
}


//VALIDATION
function validateform(formname,color1,color2){
	//last updated on 9/27/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 = color1;
				allgood = false;
				} else {
				  document.getElementById(thisformid).style.background = color2; 
				}
			}
		}
		if (allgood) {
			return true;
			} else {
			return false;
			}
	}


//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;
	}
}


// row rollover scripts for test menu
function rowrollover(){
	var x=document.getElementsByTagName("div");
	for (var i=0;i<x.length;i++)
  	{
	if (x[i].id.indexOf("dosrow")>-1){
		var element = document.getElementById(x[i].id);
		element.onmouseover = rollover;
		element.onmouseout  = rollout;
		element.onclick = clickme;
	}
  	}
}

function clickme(){
	var messageid = this.id.replace('dosrow','');
	var linkid = 'link' + messageid
	var thelink = document.getElementById(linkid).href;
	window.location.href = thelink;
}

function rollover(){
	this.style.backgroundColor='#e8ecd7';
	this.style.cursor = 'pointer';
}

function rollout(){
	this.style.backgroundColor='#f3f7ea';
}


//IMAGE ROLLOVER
function rolloverInit(){
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].getAttribute('name') == "rollover") {			
			setupRollover(document.images[i]);
		}
	}
}

//IMAGE ROLLOVER
//Last Update August 1, 2008
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;	
}

//IMAGE ROLLOVER
function rollOver() {
	this.src = this.overImage.src;
}

//IMAGE ROLLOVER
function rollOut() {
	this.src = this.outImage.src;
}

window.onload = masterloader;

function masterloader(){
	//rowrollover();
	rolloverInit();
	//productrollover();
}