// JavaScript Document

function check(){
alert ("Hello");
return false;
}


//Checks to make sure the user entered all required fields
//returns FALSE if a required field is not filled
function validate_register(theForm){
	if(!isValid_email(theForm.email.value)){
		//alert ("Please enter a valid e-mail address!");
		return false;
	}else if(theForm.pass1.value == null || theForm.pass1.value == "" || theForm.pass1.value != theForm.pass2.value){
		alert ("Please enter matching passwords!");
		return false;
	}else if(theForm.f_name.value == null || theForm.f_name.value == ""){
		alert ("Please enter your first name!");
		return false;
	}else if(theForm.l_name.value == null || theForm.l_name.value == ""){
		alert ("Please enter your last name!");
		return false;
	}else if(theForm.phone.value == null || theForm.phone.value == ""){
		alert ("Please enter your phone number!");
		return false;
	}else if(theForm.address1.value == null || theForm.address1.value == ""){
		alert ("Please enter your street address!");
		return false;
	}else if(theForm.city.value == null || theForm.city.value == ""){
		alert ("Please enter a city!");
		return false;
	}else if(theForm.state.value == null || theForm.state.value == ""){
		alert ("Please enter a state!");
		return false;
	}else if(theForm.zip.value == null || theForm.zip.value == ""){
		alert ("Please enter your zipcode");
		return false;
	}
	
	//everything is valid!
	return true;
	
	
}


//Checks the email address for correct characters
function isValid_email(email){
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	var returnval=emailfilter.test(email)
	
		if (returnval==false){
			alert ("Please a valid e-mail address!");
			return false;
		}
		else
			return true;
}


function validate_login(theForm){
	if(!isValid_email(theForm.email.value)){
		//alert ("Please a valid e-mail address!");
		return false;
	}else if(theForm.password.value == null || theForm.password.value == ""){
		alert ("Please enter your password!");
		return false;
	}
	
	//everthing is valid
	return true;
}


function validate_forgot_pass(theForm){
	if(!isValid_email(theForm.email.value)){
		//alert ("Please your valid e-mail address!");
		return false;
	}else{	
	//everthing is valid
	return true;
	}
}


function validate_contact(theForm){
	if(theForm.name.value == null || theForm.name.value == ""){
		alert ("Please enter your name");
		return false;
	}else if(!isValid_email(theForm.email.value)){
		//alert ("Please a valid e-mail address!");
		return false;
	}else if(theForm.message.value == null || theForm.message.value == ""){
		alert ("Please enter a message!");
		return false;
	}
	
	//everthing is valid
	return true;
}




function validate_askQuestion(theForm){
	if(theForm.name.value == null || theForm.name.value == ""){
		alert ("Please enter your name");
		return false;
	}else if(!isValid_email(theForm.email.value)){
		//alert ("Please a valid e-mail address!");
		return false;
	}else if(theForm.question.value == null || theForm.question.value == ""){
		alert ("Please enter a question!");
		return false;
	}else{	
	//everthing is valid
	return true;
	}
}



function validate_changePassword(theForm){
	if(theForm.old_pass.value == null || theForm.old_pass.value == ""){
		alert ("Please your current password!");
		return false;
	}else if(theForm.new_pass1.value == null || theForm.new_pass1.value == "" || theForm.new_pass2.value != theForm.new_pass2.value){
		alert ("Please enter new matching passwords!");
		return false;
	}
}
	
	
function validate_changeContactInfo(theForm){
	if(theForm.f_name.value == null || theForm.f_name.value == ""){
		alert ("Please enter your first name!");
		return false;
	}else if(theForm.l_name.value == null || theForm.l_name.value == ""){
		alert ("Please enter your last name!");
		return false;
	}else if(theForm.phone.value == null || theForm.phone.value == ""){
		alert ("Please enter your phone number!");
		return false;
	}else if(theForm.address1.value == null || theForm.address1.value == ""){
		alert ("Please enter your street address!");
		return false;
	}else if(theForm.city.value == null || theForm.city.value == ""){
		alert ("Please enter a city!");
		return false;
	}else if(theForm.state.value == null || theForm.state.value == ""){
		alert ("Please enter a state!");
		return false;
	}else if(theForm.zip.value == null || theForm.zip.value == ""){
		alert ("Please enter your zipcode");
		return false;
	}
	
	//everthing is valid!
	return true;
}


function validate_licenseRegistration(theForm){
	if(theForm.num1.value.length != 4){
		alert ("The registration number should have 12 characters!");
		return false;
	}else if(theForm.num2.value.length != 4){
		alert ("The registration number should have 12 characters!");
		return false;
	}else if(theForm.num3.value.length != 4){
		alert ("The registration number should have 12 characters!");
		return false;
	}
	
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}



function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("FirstName", "LastName");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("First Name", "Last Name");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}


function print_view(contentId){
	printDiv = document.getElementById(contentId);
	popup = window.open('', 'popup');
	popup.document.open();
	popup.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>');
	popup.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');
	popup.document.write("<head><link href='includes/style.css' rel='stylesheet' type='text/css' /></head><body><div style='padding:10px;'>");
	popup.document.write(printDiv.innerHTML);
	popup.document.write("</div></body></html>");
	popup.document.close();	
}





function CreateBookmarkLink(title, url) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite(url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }
 
 
 
 
 function hideDiv(divID){
	document.getElementById(divID).style.display = 'none'; 
 }
 	
 function showDiv(divID){	 
	document.getElementById(divID).style.display = 'block'; 
 }
 
 
 
 
/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function overlayDiv(curobj, divID, opt_position){
	if (document.getElementById){
		var subobj=document.getElementById(divID);
		subobj.style.display=(subobj.style.display!="block")? "block" : "none";
		subobj.style.zIndex = 0;
		
		var xpos = (document.body.clientWidth/2) - (subobj.offsetWidth/2);
		var ypos = ((iecompattest().clientHeight/2 + iecompattest().scrollTop)) - (subobj.offsetHeight/2);
		
		subobj.style.left=xpos+"px";
		subobj.style.top=ypos+"px";
		return false;
	}else{
		return true;
	}
}


function overlayclose(subobj){
	theDiv = document.getElementById(subobj)
	theDiv.style.display="none";
}







/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
* http://dynamicdrive.com/dynamicindex4/image3.htm
***********************************************/

var dragobject={
	z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
	initialize:function(){
		document.onmousedown=this.drag;
		document.onmouseup=function(){this.dragapproved=0;}
	},
	
	
	drag:function(e){
		var evtobj=window.event? window.event : e;
		this.targetobj=window.event? event.srcElement : e.target;
		tClass = this.targetobj.className;
		if (tClass=="drag" || tClass == "overlayDiv"){
			this.dragapproved=1;
			if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0;}
			if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0;}
			this.offsetx=parseInt(this.targetobj.style.left);
			this.offsety=parseInt(this.targetobj.style.top);
			this.x=evtobj.clientX;
			this.y=evtobj.clientY;
			if (evtobj.preventDefault)
				evtobj.preventDefault();
			document.onmousemove=dragobject.moveit;
		}
	},

	moveit:function(e){
		var evtobj=window.event? window.event : e;
		if (this.dragapproved==1){
			this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px";
			this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px";
			return false;
		}
	}
}

dragobject.initialize()
