function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

var _toAddrs;
var _cc;
var _bcc;
var _subject;
var _body;
var _replyTo;

function openEmailWindow(toAddrs, cc, bcc, subject, body, replyTo)
{
	var win = window.open('email.aspx','Email','height=700,width=740,resizable=yes,scrollbars=yes,status=0');
		
	//need to delay until the doc is loaded
	//while(win.document.forms[0] == null)
	//{		
	//}	
	
	//self.setTimeout('fillEmailWindow()', 5000);
	
    //var date = new Date();
    //var curDate = null;
    //do { curDate = new Date(); }
	//while(curDate-date < 5000);
	
	//var frm = win.document.Form1;
	
	win.toAddrs = toAddrs;
	win.cc = cc;
	win.bcc = bcc;
	win.subject = subject;
	win.body = body;
	win.replyTo = replyTo;
}

function fillEmailWindow()
{
	alert("blah");
}

function check_range(o_chk, i_start, i_end, b_check)
{
	if( o_chk.length == undefined )
	{
		o_chk.checked = b_check;
	}
	else
	{
		for( var i = i_start; i <= i_end; i++ )
		{
			if( i > -1 && i <= o_chk.length - 1 )
			{
				o_chk[i].checked = b_check;
			}
		}
	}
}

function validate_feature_form(frm)
{
	return true;
}

function validate_view_doc_form(frm)
{
	//alert("Hello World!");
	var b_found = false;
	if( frm.doc_id.length == undefined )
	{
		if( frm.doc_id.checked )
			b_found = true;
	}
	else
	{
		for( var i = 0; i < frm.doc_id.length; i++ )
		{
			if( frm.doc_id[i].checked )
				b_found = true;
		}
	}
	
	if( !b_found )
	{
		alert("You must choose at least one document from the list to proceed");
		return false;
	}

	return true;
}

function validate_view_doc_realtor_form(frm)
{

	var b_found = false;
	
	if( frm.quick_pick_doc_type.value == "" )
	{
		alert("You cannot proceed as there are no documents in the Standard Set.\r\n\r\nTo find other documents, Click on View All Documents");
		
		return false;
	}
	
	/*
	if( frm.quick_pick_doc_type.length == undefined )
	{
		if( frm.quick_pick_doc_type.checked )
			b_found = true;
	}
	else
	{
		for( var i = 0; i < frm.quick_pick_doc_type.length; i++ )
		{
			if ( frm.quick_pick_doc_type[i].checked ) 
				b_found = true;
		}
	}
	
	//alert(frm.quick_pick_doc_type.checked);
	
	if( !b_found )
	{
		alert("You must choose document from at least one type to proceed");
		return false;
	}
	*/
	return true;
}

function validate_realtor_resend(frm)
{
	var radioObj;
	
	radioObj = document.getElementById("rdoAgents0");
	
	if(radioObj)
	{
		if (radioObj.checked)
		{
			alert("You did not select a REALTOR\u00AE to send an email to.");
			return false;
		}
	}
	else
	{
		return false;
	}
	
	/*var sel;
	
	var i = 0;
	do{
		elem = document.getElementById("email_" + i);
		sel = document.getElementById("sel_" + i);
		if(elem != null && elem.value != "" && sel != null && sel.checked == true)
		{
			if( !is_email_valid(elem.value) )
			{
				elem.focus();
				alert("The email address provided, " + elem.value + ", does not appear to be valid.\n\nPlease check it and try again.");
				return false;
			}
		}
		i++;
	}while(elem != null)
	
	if( !is_email_valid(frm.client_email.value) )
	{
		frm.client_email.focus();
		alert("The email address provided does not appear to be valid.\n\nPlease check it and try again.");
		return false;
	}*/
	
	return true;
}

function validate_client_confirm(frm)
{	
	if( !frm.accept_terms.checked )
	{
		alert("You must agree to the Terms and Disclaimer to view these documents.\r\n\r\nPlease check the checkbox if you agree to the terms and disclaimer.");
		return false;
	}
	
	return true;
}

function validate_realtor_search(frm)
{
	var elem;
	var surName;	
	
	elem = document.getElementById("txtSurname");
	surName = Trim(elem.value);
	if(surName == "" || surName == "(Required)")
	{
		alert('You must supply at least a Surname in order to search for a REALTOR\u00AE.');
		return false;
	}
	else
	{
		frm.action = "";
		elem = document.getElementById("do_search");
		elem.value = "true";
	}
	
	return true;
}

function validate_realtor_request(frm)
{
	var elem;
	
	var i = 0;
	do{
		elem = document.getElementById("email_" + i);
		if(elem != null && elem.value != "")
		{
			if( !is_email_valid(elem.value) )
			{
				elem.focus();
				alert("The email address provided, " + elem.value + ", does not appear to be valid.\n\nPlease check it and try again.");
				return false;
			}
		}
		i++;
	}while(elem != null)
	
	/*if( frm.client_email.value != "" )
	{
		if( !is_email_valid(frm.client_email.value) )
		{
			frm.client_email.focus();
			alert("The email address provided does not appear to be valid.\n\nPlease check it and try again.");
			return false;
		}
	}*/
	
	if( !frm.agree_to_terms.checked )
	{
		alert("You must agree to the Terms and Disclaimer to continue with the order.\r\n\r\nPlease check the checkbox if you agree to the terms.");
		return false;
	}
	
	return true;
}

function validate_formb_request(frm)
{
	if(frm.unitNumber.value == "")
	{
		frm.unitNumber.focus();
		alert("You must supply a unit number.");
		return false;
	}
	
	var rdoChecked = false;
	for(var i=0;i<frm.rdoFeeType.length;i++)
	{
		if(frm.rdoFeeType[i].checked)
		{
			rdoChecked = true;
			break;
		}
		
				
	}
	
	if(!rdoChecked)
	{
		alert("You must specify an order type.");
		return false;
	}
	
	if(!is_phone_valid(frm.delMethodCall.value))
	{
		frm.delMethodCall.focus();
		alert("You must supply a phone number in the correct format (nnn nnn-nnnn) to complete this order");
		return false;
	}
	
	if(!is_email_valid(frm.delMethodEmail.value))
	{
		frm.delMethodEmail.focus();
		alert("You must supply a valid email address to complete this order");
		return false;
	}
	
	return true;
}

function get_formb_fee(frm,regFee,rushFee,urgFee)
{
	var fee = "$0.00";
	
	for(var i=0;i<frm.rdoFeeType.length;i++)
	{
		if(frm.rdoFeeType[i].checked)
		{
			switch(i)
			{
			case 0:
				fee = regFee;
				break;
			case 1:
				fee = rushFee;
				break;
			case 2:
				fee = urgFee;
				break;
			default:
				break;
			}
			break;
		}	
	}
	
	/*if(frm.rdoFeeType[0].checked)
	{
		fee = regFee;
	}
	else
	{
		if(frm.rdoFeeType[1].checked)
		{
			fee = rushFee;
		}
	}*/
	
	return fee;
}

function getHelp(s_url)
{
	var s_h = screen.height;
	var s_w = screen.width;
	var w = s_h // 2; // Make a ratio of the screen size
	var h = s_w / 2;
	var x = (s_w / 2) - (w / 2); // Center it
	var y = (s_h / 2) - (h / 2);
	var popName = "Help_Window";
	
	var open_str = "width=" + w +",height=" + h +",status=no,menubar=no,scrollbars=yes,resizable=yes,left = " + x + ", top = " + y;
	
	var win = window.open (s_url, popName, open_str);
	win.focus();
}

function print_terms(s_type)
{
	var s_h = screen.height;
	var s_w = screen.width;
	var w = s_h / 2; // Make a ratio of the screen size
	var h = s_w / 2;
	var x = (s_w / 2) - (w / 2); // Center it
	var y = (s_h / 2) - (h / 2);
	var popName = "Print_Terms_Window";
	var url = "print_terms.aspx?terms=" + s_type;
	var open_str = "width=" + w +",height=" + h +",status=no,menubar=no,scrollbars=yes,resizable=yes,left = " + x + ", top = " + y;
	
	var win = window.open (url, popName, open_str);
	win.focus();
}

function submit_num_per_page(the_form, i_num_per_page)
{
	the_form.num_per_page.value = i_num_per_page;
	the_form.submit();
}

function get_log_popup(log_id)
{
	var s_h = screen.height;
	var s_w = screen.width;
	var w = s_h / 2; // Make a ratio of the screen size
	var h = s_w / 2;
	var x = (s_w / 2) - (w / 2); // Center it
	var y = (s_h / 2) - (h / 2);
	var popName = "Log_Window";
	var url = "log_popup.aspx?log_id=" + log_id;
	
	var open_str = "width=" + w +",height=" + h +",status=no,menubar=no,scrollbars=yes,resizable=yes,left = " + x + ", top = " + y;
	
	var win = window.open (url, popName, open_str);
	win.focus();
}

function validate_profile_update(frm)
{
	
	var s_first_name =frm.user_first_name.value;
	var s_last_name = frm.user_last_name.value;
	//var s_user_name = frm.user_name.value, s_user_name_empty;
	var s_email		= frm.user_email.value;
	
	
	if( s_first_name == "" )
	{
		frm.user_first_name.focus();
		alert("Please provide the user with a given name (first name)");
		return false;
	}
	
	if( s_last_name == "" )
	{
		frm.user_last_name.focus();
		alert("Please provide the user with a surname");
		return false;
	}
	
	if( !is_email_valid(s_email) )
	{
		frm.user_email.focus();
		alert("Please provide the user with a valid email address.\n\n(eg - person@domain.com)");
		return false;
	}
	
	if( frm.user_password.value == "" )
	{
		frm.user_password.focus();
		alert("Please provide the user with a valid password.");
		return false;
	}
	else if( frm.user_password.value.length < 4 || frm.user_password.value.length > 16 )
	{
		frm.user_password.focus();
		alert("The provided password is an incorrect length.\n\nPasswords are to be between 4 and 16 characters long inclusive.");
		return false;
	}
	else if( frm.user_password.value != frm.user_password_verify.value )
	{
		frm.user_password.focus();
		alert("Your passwords do not match. Please type both them again.\n\nThe second password field verifies\nthat the first one was correctly typed.");
		return false;
	}
	
	if(!confirm("Update Profile?"))
	{
		return false;
	}
	
	return true;
}

function validate_user_id_search(frm)
{
	var i_search_user_id = Replace(frm.search_user_id.value, "*", "");
	if( !isInteger(i_search_user_id) || i_search_user_id < 1 )
	{
		frm.search_user_id.focus();
		alert("You must provide an user is as a positive integer, (A numbers above 0).\n\nYou can also use wildcards (Eg - 23*)");
		return false;
	}
	
	return true;
}

function validate_user_email_search(frm)
{
	var s_email = frm.search_email.value;
	if( s_email == "" )
	{
		frm.search_email.focus();
		alert("You must provide an email address to search on.\n\nYou can also use wildcards (eg - user@domain.com or user*)");
		return false;
	}
	
	return true;
}

function validate_user_status_search(frm)
{
	if(frm.user_status.value < 0)
	{
		frm.user_status.focus();
		alert("Select the user status you want to search");
		return false;
	}
}

function validate_user_type_search(frm)
{
	if(frm.user_type.value < 1)
	{
		frm.user_type.focus();
		alert("Select the user type you want to search");
		return false;
	}
}

function validate_user_name_search(frm)
{
	if( frm.search_user_name.value == "" )
	{
		frm.search_user_name.focus();
		alert("Please provide a username to search.\n\n(You can use wildcards * to search. Eg - bob*) ");
		return false;
	}
	
	return true;
}

function validate_name_search(frm)
{
	if( (frm.search_user_last_name.value == "(Or a surname here)" || frm.search_user_last_name.value == "") && (frm.search_user_first_name.value == "(Enter a first name here)" || frm.search_user_first_name.value == "") )
	{
		alert("Please provide either a surname or a given name to search.\n\n(You can use wildcards * to search. Eg - Smi*) ");
		return false;
	}
	if(frm.search_user_last_name.value == "(Or a surname here)" || frm.search_user_last_name.value == "")
	{
		frm.search_user_last_name.value = "*";
	}
	if(frm.search_user_first_name.value == "(Enter a first name here)" || frm.search_user_first_name.value == "")
	{
		frm.search_user_first_name.value = "*";
	}
	
	return true;
}

function select_docs(theForm, bSelect)
{
	//alert("select_all_docs");
	
	if( theForm.doc_id.length == undefined )
	{
		theForm.doc_id.checked = bSelect;
	}
	else
	{
		for( var i = 0; i < theForm.doc_id.length; i++ )
		{
			theForm.doc_id[i].checked = bSelect;
		}
	}
	
}

function select_all_docs(theForm, bSelect)
{
	//alert("select_all_docs");
	
	if(theForm.doc_id != null)
	{
		if( theForm.doc_id.length == undefined )
		{
			theForm.doc_id.checked = bSelect;
		}
		else
		{
			for( var i = 0; i < theForm.doc_id.length; i++ )
			{
				theForm.doc_id[i].checked = bSelect;
			}
		}
	}
	
}

function select_all_users(theForm, bSelect)
{
	if( theForm.user_ids.length == undefined )
	{
		theForm.user_ids.checked = bSelect;
	}
	else
	{
		for( var i = 0; i < theForm.user_ids.length; i++ )
		{
			theForm.user_ids[i].checked = bSelect;
		}
	}
}

function select_all_blds(theForm, bSelect)
{
	if( theForm.building_ids.length == undefined )
	{
		theForm.building_ids.checked = bSelect;
	}
	else
	{
		for( var i = 0; i < theForm.building_ids.length; i++ )
		{
			theForm.building_ids[i].checked = bSelect;
		}
	}
}

function set_page_action_and_submit(theForm, sValue)
{
	//alert("set_page_action_and_submit");
	theForm.page_action.value = sValue;
	theForm.submit();
}

function clientViewDocs(theForm)
{
	var doc_count = 0;
	
	if(theForm.doc_id != null)
	{
		if( theForm.doc_id.length == undefined )
		{
			if(theForm.doc_id.checked)
			{
				doc_count++;
			}
		}
		else
		{
			for( var i = 0; i < theForm.doc_id.length; i++ )
			{
				if( theForm.doc_id[i].checked)
				{
					doc_count++;
				}
			}
		}		
	}
	
	if( doc_count == 0 )
	{
		alert("Select one or more documents first");
		return false;			
	}
	else
	{
		return confirm("View " + doc_count + " selected document(s)?");
	}
}

function submit_doc_form(theForm, str_form_action, str_page_action)
{
	
	var b_is_valid	= true;
	var s_msg		= "";
	
	// validate
	if(theForm.doc_id != null)
	{
		var doc_count = 0;
		if( theForm.doc_id.length == undefined )
		{
			if(theForm.doc_id.checked)
			{
				if(str_page_action == 'verify_docs' && theForm.doc_id.title == 'True')
				{
					theForm.doc_id.checked = false;
				}
				else
				{
					doc_count++;
				}
			}
		}
		else
		{
			for( var i = 0; i < theForm.doc_id.length; i++ )
			{
				if( theForm.doc_id[i].checked)
				{
					if(str_page_action == 'verify_docs' && theForm.doc_id[i].title == 'True')
					{
						theForm.doc_id[i].checked = false;
					}
					else
					{
						doc_count++;
					}
				}
			}
		}
		if( doc_count == 0 )
		{
			b_is_valid = false;
			s_msg = "Select one or more documents first";			
		}
		else
		{
			var ret;
			if(str_page_action == '')
			{
				ret = confirm("View " + doc_count + " selected document(s)?");
			}
			else if(str_page_action == 'verify_docs')
			{
				ret = confirm("Mark " + doc_count + " selected document(s) as verified?");
			}
			else if(str_page_action == 'delete_docs' || str_page_action == 'remove_staged_docs')
			{
				ret = confirm("Delete " + doc_count + " selected document(s)?");
			}
			else if(str_page_action == 'set_staged_documents')
			{
				if( theForm.doc_id.length == undefined )
				{
					//verify setting for single doc
					s_msg = ChoCho(theForm.doc_id.value);
				}
				else
				{
					for( var i = 0; i < theForm.doc_id.length; i++ )
					{
						if( theForm.doc_id[i].checked)
						{
							//verify settings
							s_msg = ChoCho(theForm.doc_id[i].value);
							if(s_msg != "")
								break;
						}
					}
				}
				
				if(s_msg == "")
				{
					ret = confirm("Finalize the categorization of " + doc_count + " selected document(s)?");
				}
				else
				{
					alert(s_msg);
					return false;
				}
			}
			else if(str_page_action == 'staged_docs')
			{
				ret = confirm("View " + doc_count + " selected document(s)?");
			}
			
			if(ret)
			{
				b_is_valid = true;
			}
			else
			{
				return false;
			}
		}
	}
	else
	{
		return false;
	}
	
	if( b_is_valid )
		do_action_submit(theForm, str_form_action, str_page_action);
	else
		alert(s_msg);
}

function ChoCho(docId)
{
	var msg = "";
	var elems;
	
	elems = document.getElementsByName("doc_type_" + docId);
	if(elems[0].value == "")
	{
		elems[0].focus();
		msg = "You must select a document type";
		return msg;
	}
	
	var docType = elems[0].value;
	
	elems = document.getElementsByName("doc_year_" + docId);
	//if((docType != 200 && docType != 201 && docType != 202) && elems[0].value == "")
	if(elems[0].value == "")
	{
		elems[0].focus();
		msg = "You must select a year for the document";
		return msg;
	}
	
	elems = document.getElementsByName("doc_month_" + docId);
	//if((docType != 100 && docType != 101 && docType != 200 && docType != 201 && docType != 202) && elems[0].value == "")
	if(elems[0].value == "")
	{
		elems[0].focus();
		msg = "You must select a month for the document";
		return msg;
	}
	
	elems = document.getElementsByName("doc_day_" + docId);
	if(elems[0].value == "")
	{
		elems[0].focus();
		msg = "You must select a day for the document";
		return msg;
	}	
	
	if(docType == "300" || docType == "301")
	{
		/*elems = document.getElementsByName("doc_day_" + docId);
		if(elems[0].value == "")
		{
			elems[0].focus();
			msg = "You must select a day for the document";
			return msg;
		}*/
		
		elems = document.getElementsByName("doc_title_" + docId);
		if(elems[0].value == "" || elems[0].value == "(enter a name)")
		{
			elems[0].focus();
			msg = "You must provide a name for the document";
			return msg;
		}
		
		elems = document.getElementsByName("doc_description_" + docId);
		if(elems[0].value == "" || elems[0].value == "(enter up to 255 characters of description)")
		{
			elems[0].focus();
			msg = "You must provide a description for the document";
			return msg;
		}
	}
	
	return msg;
}

function do_action_submit(theForm, str_form_action, str_page_action)
{

	theForm.action = str_form_action;
	theForm.page_action.value = str_page_action;
	
	theForm.submit();
}

function validate_user_form(frm, s_user_first_name_empty, s_user_last_name_empty, s_user_name_empty, s_user_email_empty,s_firm_name_empty,s_street_address_empty,s_city_empty,s_province_empty,s_postal_code_empty,s_phone_empty,s_billing_contact_empty, strata)
{
	if(frm.page_action.value != 'delete_user_full')
	{
		var s_first_name = Replace(frm.user_first_name.value, s_user_first_name_empty, "");
		var s_last_name = Replace(frm.user_last_name.value, s_user_last_name_empty, "");
		var s_user_name = Replace(frm.user_name.value, s_user_name_empty, "");
		var s_email		= Replace(frm.user_email.value, s_user_email_empty, "");
		var s_firm_name		= Replace(frm.user_firm_name.value, s_firm_name_empty, "");
		var s_street_address		= Replace(frm.user_firm_street_address.value, s_street_address_empty, "");
		var s_city		= Replace(frm.user_firm_city.value, s_city_empty, "");
		var s_province		= Replace(frm.user_firm_province.value, s_province_empty, "");
		var s_postal_code		= Replace(frm.user_firm_postal_code.value, s_postal_code_empty, "");
		var s_phone		= Replace(frm.user_firm_phone.value, s_phone_empty, "");
		var s_billing_contact		= Replace(frm.user_firm_billing_contact_name.value, s_billing_contact_empty, "");		
		
		if( s_first_name == "" )
		{
			frm.user_first_name.focus();
			alert("Please provide the user with a given name (first name)");
			return false;
		}
		
		if( s_last_name == "" )
		{
			frm.user_last_name.focus();
			alert("Please provide the user with a surname");
			return false;
		}
		
		if( !is_email_valid(s_email) )
		{
			frm.user_email.focus();
			alert("Please provide the user with a valid email address.\n\n(eg - person@domain.com)");
			return false;
		}
		
		if( s_user_name == "" )
		{
			frm.user_name.focus();
			alert("Please provide the user with a user name.");
			return false;
		}
		
		if( frm.user_password.value == "" )
		{
			frm.user_password.focus();
			alert("Please provide the user with a valid password.");
			return false;
		}
		else if( frm.user_password.value.length < 4 || frm.user_password.value.length > 16 )
		{
			frm.user_password.focus();
			alert("The provided password is an incorrect length.\n\nPasswords are to be between 4 and 16 characters long inclusive.");
			return false;
		}
		else if( frm.user_password.value != frm.user_password_verify.value )
		{
			frm.user_password.focus();
			alert("Your passwords do not match. Please type both them again.\n\nThe second password field verifies\nthat the first one was correctly typed.");
			return false;
		}
																				
		if( frm.user_type != null && frm.user_type.value == "" )
		{
			frm.user_type.focus();
			alert("You must choose a user type.");
			return false;
		}
		
		if( s_firm_name == "" )
		{
			frm.user_firm_name.focus();
			alert("Please provide the user with a firm name.");
			return false;
		}
		if( s_street_address == "" )
		{
			frm.user_firm_street_address.focus();
			alert("Please provide the user with a street address.");
			return false;
		}
		if( s_city == "" )
		{
			frm.user_firm_city.focus();
			alert("Please provide the user with a city.");
			return false;
		}
		if( s_province == "" )
		{
			frm.user_firm_province.focus();
			alert("Please provide the user with a province.");
			return false;
		}
		if( s_postal_code == "" )
		{
			frm.user_firm_postal_code.focus();
			alert("Please provide the user with a postal code.");
			return false;
		}
		if( !is_phone_valid(s_phone) )
		{
			frm.user_firm_phone.focus();
			alert("Please provide the user with a properly formatted (nnn nnn-nnnn) phone number.");
			return false;
		}
		if( s_billing_contact == "" )
		{
			frm.user_firm_billing_contact_name.focus();
			alert("Please provide the user with a billing contact name");
			return false;
		}
		
		if(strata != "" && strata != null)
		{
			var elms = document.getElementsByName(strata);
			var isChecked = false;
			for(var i = 0;i < elms.length;i++)
			{
				if(elms[i].checked)
				{
					isChecked = true;
					break;
				}
			}
			
			if(!isChecked)
			{
				alert("You must choose a strata.");
				return false;
			}
		}

		var confMessage = "Add this user record?";
		
		if (frm.page_action.value == "update_user")
		{
			confMessage = "Update this user record?";
		}
		
		return confirm(confMessage);	
	}
	else
		return true;
}

function is_phone_valid(strPhone)
{
	var reg;
	var mat;
	
	reg = new RegExp("^\\d{3}\\s{1}\\d{3}-\\d{4}$");
	
	mat = reg.exec(strPhone);
	if(mat == null || mat[0] == null || mat[0].length < 1)
	{
		return false;
	}
		
	return true;
}

function validate_search_strata_num(frm)
{
	var arr = new Array("VIS", "SP", "EPS");
	var s_good_chars = "0123456789*";
	
	var val = frm.search_strata_num.value;
	var i_strata_num = 0;
	var n_new_val = "";
	
	val = TrimAll(val.toLowerCase());
	
	for( var i = 0; i < val.length; i++ )
	{
		var c = val.charAt(i);
	
		if( s_good_chars.indexOf(c) > -1 )
		{
			n_new_val += c;
		}
	}
	
	val = n_new_val;

	frm.search_strata_num.value = val;
	
	val = Replace(val, "*", "");
	
	if( !isInteger(val) )
	{
		frm.search_strata_num.focus();
		alert("You must only enter the number portion of the strata number or use number pattern matching!\n\nPlease enter the Strata Plan number as a number only (Eg - 1234 or 123*)");
		return false;
	}
	
	if( val < 1 )
	{
		frm.search_strata_num.focus();
		alert("A strata plan number must greater than 0!\n\nPlease enter the Strata Plan number as a number only (Eg - 1234)");
		return false;
	}
	return true;
}

function validate_search_addr(frm, s_street_num_def, s_street_name_def)
{
	var val = Replace(frm.search_street_num.value, s_street_num_def, "");
	var val2 = Replace(frm.search_street_name.value, s_street_name_def, "");
	
	if( ( val == 0 || val == "" ) && val2 == "" )
	{
		frm.search_street_name.focus();
		alert("You must choose to search on either the building street number or street name or both.\n\nThe street number uses the number portion only (Eg - 2600)");
		return false;	
	}
	
	if( val != "" && val != 0 )
	{
		val = Replace(val, "*", "");
		if( !isInteger(val) )
		{
			frm.search_street_num.focus();
			alert("You must enter the street number as a number only.\n\n(Eg - 2600)\n\nYou can use pattern matching, but only for numbers. (eg - 260*)");
			return false;
		}
	}
	
	return true;
}

function text_on_blur(o_text_box, s_blur_text)
{
	var text_val = o_text_box.value;
	if( text_val == "" )
	{
		o_text_box.value = s_blur_text;
	}
}

function text_on_focus(o_text_box, s_blur_text)
{
	if( o_text_box.value == s_blur_text )
		o_text_box.value = "";
}

function validate_search_bld_name(frm)
{
	if( frm.search_building_name.value == "" )
	{
		frm.search_building_name.focus();
		alert("You must enter a building name or set of characters and wildcard!\n\n(Eg - Green Manor or Green*");
		return false;
	}

	return true;
}

function validate_search_pm_name(frm)
{
	if( frm.search_pm_name.value == "" )
	{
		frm.search_pm_name.focus();
		alert("You must enter a PM name or set of characters and wildcard!\n\n(Eg - bobsmith or bob*");
		return false;
	}

	return true;
}

function validate_login(theForm, sType)
{
	var s_type = "username";
	if( sType == "realtor" )
		s_type = "REALTOR\u00AE ID";
	
	if( sType == "realtor" )
	{
		if(!isInteger(theForm.username.value))
		{
			alert("You must enter a numeric " + s_type + " to log into the system.\n\nYour REALTOR\u00AE ID is a number.");
			theForm.username.focus();
			return false;
		}
	}
	
	if( theForm.username.value == "" )
	{
		alert("You must enter a " + s_type + " to log into the system.");
		theForm.username.focus();
		return false;
	}

	if( theForm.password.value == "" )
	{
		alert("You must enter a password to log into the system");
		theForm.password.focus();
		return false;
	}
	
	return true;
}

function do_sort_submit(theForm, action, extra_val, i_min, i_max)
{
	var frm 		= theForm;
	var sort_asc 	= frm.sort_asc.value;
	
	if( action == "sort_column" )
	{
		if( sort_asc == "ASC" )
			frm.sort_asc.value = "DESC";
		else
			frm.sort_asc.value = "ASC";
	}
	
	if( action == "sort_fld" )
	{
		frm.sort_asc.value = "ASC";
		frm.sort_fld.value = extra_val;
	}
	// reset sort asc and fld
	if( action == "set_num_per_page")
	{
		if( !isNumeric(frm.num_per_page.value) )
		{
			alert("You must enter a number when setting number per page!\n\nEg - 10");
			return;
		}
		
		if( frm.num_per_page.value < i_min || frm.num_per_page.value > i_max )
		{
			frm.num_per_page.focus();
			alert("You must enter a number between within the accepted range when setting number per page!\n\n(Range: " + i_min + " to " + i_max + ")");
			return;
		}
		
		frm.sort_asc.value = "ASC";
		frm.sort_fld.value = "";
	}
	
	frm.submit();
}

function validate_set_num_per_page(frm, i_min, i_max)
{
	if( !isNumeric(frm.num_per_page.value) )
	{
		alert("You must enter a number when setting number per page!\n\nEg - 10");
		return false;
	}
	
	if( frm.num_per_page.value < i_min || frm.num_per_page.value > i_max )
	{
		frm.num_per_page.focus();
		alert("You must enter a number between within the accepted range when setting number per page!\n\n(Range: " + i_min + " to " + i_max + ")");
		return false;
	}
	
	return true;
		
}

function do_page_number_submit(frm, i_page_num)
{
	
	//document.set_page_num_form.page_num.value = i_page_num;
	frm.page_num.value = i_page_num;
	frm.submit();
}

function ShowHideStrataList(val)
{
	if(val == 5)
	{
		strataListDiv.className = "elementshow";
	}
	else
	{
		strataListDiv.className = "elementhide";
	}
}

/**
* Email address validation functions...
**/
function is_email_valid(strEmail)
{
	var emailReg;
	var mat;
	
	emailReg = new RegExp("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
	
	mat = emailReg.exec(strEmail);
	if(mat == null || mat[0] == null || mat[0].length < 1)
	{
		return false;
	}
		
	return true;	
	
	/*arr = strEmail.split("@");
			
	if( arr.length != 2 )
	{
		return false;
	}
	else if( !valid_domain( arr[1] ) )
	{
		return false;
	}
	else if( !valid_email_name(arr[0]) )
	{
		return false;
	}
		
	return true;*/
}

function valid_domain(strDomain)
{
	// These the only valid characters allowed in a domain name...
	// besides periods...
	var i = 0;
	//strDomain = strDomaun.toLowerCase();
	var arr = strDomain.split(".");
	
	if( arr.length < 2 )
	{
		return false;
	}
	
	for( i = 0; i < arr.length; i++ ) 
	{
		if( !valid_domain_field( arr[i] ) ) 
		{
			return false;
		}	
	}

	return true;
}

function valid_domain_field(strField)
{
	var valid = "abcdefghijklmnopqrstuvwxyxz0124567890-";
	var i = 0, m = 0;
	var isValid = false;
	
	strField = strField.toLowerCase();
	
	if( strField == "" )
		return false; // if period get are together to at end or beginning, there will be blanks
		
	for( i = 0; i < strField.length; i++ )
	{
		isValid = false;
		for( m = 0; m < valid.length; m++ )
		{
			if( strField.charAt(i) == valid.charAt(m) )
			{
				isValid = true;
				break;
			}
		}
		if( !isValid )
			return false;
	}
	
	return true;
}

function valid_email_name(strName)
{
	var valid = "abcdefghijklmnopqrstuvwxyz0123456789-_.";
	var isValid = false;
	var i = 0;
	var m = 0;
	var c;
	
	strName = strName.toLowerCase();
	
	if( strName == "" )
		return false; // Bad @ placement...
	
	for( i = 0; i < strName.length; i++ )
	{
		
		c = strName.charAt(i);
		isValid = false
		for( m = 0; m < valid.length; m++ )
		{
			if( c == valid.charAt(m) )
			{
				isValid = true;
				break;
			}
		}
	
		if( !isValid )
			return false;
		
	}
	return true;
}

/**
* String replacement function..
**/
function Replace(Expression, Find, Replace)
{
	var temp = Expression;
	var a = 0;
	
	while( ( a = temp.indexOf(Find) ) > -1 )
	{
		temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}

	return temp;
}

//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}
function LTrimAll(str) {
	if (str==null){return str;}
	for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
	return str.substring(i,str.length);
	}
function RTrimAll(str) {
	if (str==null){return str;}
	for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
	return str.substring(0,i+1);
	}
function TrimAll(str) {
	return LTrimAll(RTrimAll(str));
	}
//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------
function isNull(val){return(val==null);}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val){
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
	}
	
//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val){return(parseFloat(val,10)==(val*1));}

//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}
	
function doctype_onchange(ctrl, id_num)
{
	title_elem = getElem("doc_title", id_num);
	desc_elem = getElem("doc_description", id_num);
	
	title_elem.maxLength = 128;
	if(ctrl.options[ctrl.selectedIndex].value >= 300) //the doc type selected is building/envelope warranty or miscellaneous
	{
		title_elem.value = '(enter a name)';
		title_elem.readOnly = false;
		desc_elem.value = '(enter up to 255 characters of description)';
		desc_elem.readOnly = false;
	}
	else
	{
		title_elem.value = '(not required)';
		title_elem.readOnly = true;
		desc_elem.value = '(not required)';
		desc_elem.readOnly = true;
	}
	
	return true;
}

function getElem(name, id_num)
{
	if(id_num != null)
	{
		return document.getElementsByName(name + "_" + id_num)[0];
	}
	else
	{
		return document.getElementsByName(name)[0];
	}
}

function doc_description_onkeypress(ctrl)
{	
	if(ctrl.value.length >= 256)
	{
		return false;
	}
	
	return true;
}


function check_image_count(theForm,imageCount)
{
	if(imageCount < 15)
	{
		theForm.post_action.value="add_picture";
		theForm.method="post";
		theForm.action="upload_strata_image.aspx";
		return true;
	}
	else
	{
		alert("You already have the maximum number of images for this strata.");
		return false;
	}
	
	return true;
}

function checkImageSelection(theForm)
{
	var sel;
	var chk = false;
	for(var i=0;i<15;i++)
	{
		sel = document.getElementsByName("image_" + i);
		if(sel != null && sel[0] != null && sel[0].checked)
		{
			chk = true;
			break;
		}
	}
	if(chk)
	{
		theForm.post_action.value='delete_pictures';
		return true;
	}
	
	return false;
}


