/*
This is the main js include file
*/
function isInt(Int)
{
	if(Int.toString().search(/^-?[0-9]+$/) == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//***************************************************************************************
function UCWords(str)
{
  var arrStr = str.split(' ');
  var strOut = '';
  var i = 0;

  while (i < arrStr.length)
  {
     firstChar  = arrStr[i].substring(0,1);
     remainChar = arrStr[i].substring(1);
     firstChar  = firstChar.toUpperCase();
     remainChar = remainChar.toLowerCase();
     strOut += firstChar + remainChar + ' ';
     i++;
  }

  return strOut.substr(0,strOut.length - 1);
}


//***************************************************************************************
function SetDropDownBoxDefaultValue(DropDown_id,Default_value,UseRegExpression)
{
	if(UseRegExpression==null)
	{
		var index=0;
		while($('#'+DropDown_id).options[index].text!=null)
		{
			if($('#'+DropDown_id).options[index].text==Default_value
				|| $('#'+DropDown_id).options[index].value==Default_value)
			{
				$('#'+DropDown_id).options[index].selected=true;
				break;
			}
			index++;
		}
	}
	else
	{
		var index=0;
		while($('#'+DropDown_id).options[index].text!=null)
		{
			if(Default_value.test($('#'+DropDown_id).options[index].text)
				|| Default_value.test($('#'+DropDown_id).options[index].value))
			{
				$('#'+DropDown_id).options[index].selected=true;
				break;
			}
			index++;
		}
	}
}
//***************************************************************************************
function ShowCoverDivScreen(Main_Div_id, Content_Div_id, ScreenWidth, ScreenHeight, Content_Div_HTML)
{

	$('#'+Main_Div_id).width($(document).width());
	$('#'+Main_Div_id).height($(document).height());

	$('#'+Content_Div_id).width(ScreenWidth);
	$('#'+Content_Div_id).height(ScreenHeight);

	$('#'+Content_Div_id).css('top', $(window).scrollTop()+($(window).height()/2-$('#'+Content_Div_id).height()/2));
	$('#'+Content_Div_id).css('left', $(window).width()/2-$('#'+Content_Div_id).width()/2);

	$('#'+Content_Div_id).html('');
	$('#'+Content_Div_id).html(Content_Div_HTML);

	//filter: alpha(opacity=50)
	$('#'+Main_Div_id).show();
	$('#'+Content_Div_id).show();

}
//***************************************************************************************
function HideCoverDivScreen(Main_Div_id, Content_Div_id)
{
	$('#'+Content_Div_id).html('');
	$('#'+Main_Div_id).hide();
	$('#'+Content_Div_id).hide();
}
//***************************************************************************************
function ValidatePhoneSyntax()
{
	var phoneRe = /^(\d?-)*[2-9]\d{2}-\d{3}-\d{4}\s*((ext)\.?\s*(\d+))*$/;
	var phone_check_failed=false;
	
	$('.check_phone').each(
		function ()
		{
			if(!phoneRe.test(this.value) && this.value.length>0)
			{
				this.style.background=INPUT_ERROR_COLOR;
				phone_check_failed=true;
			}
			else
			{
				this.style.background='#fff';
			}
		}
	);
	
	if(!phone_check_failed)
	{
		return true;
	}
	else
	{
		return false;
	}	
}
//***************************************************************************************
function ValidateEmailSyntax()
{
	//var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.([a-zA-Z]+)$/;
	var emailRe=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var email_check_failed=false;
	
	$('.check_email').each(
		function ()
		{
			if(!emailRe.test(this.value))
			{
				this.style.background=INPUT_ERROR_COLOR;
				email_check_failed=true;
			}
			else
			{
				this.style.background='#fff';
			}
		}
	);
	
	if(!email_check_failed)
	{
		return true;
	}
	else
	{
		return false;
	}	
}
//***************************************************************************************
function validate_required_fields()
{
	var requiredItemNotField=false;
	
 	strRE = new RegExp( );
	strRE.compile( '^[\s ]*$', 'gi' );
	
	$(".requiredField").each(
		function ()
		{
			if(this.value.length==0
			|| this.value=='PSS'
			|| strRE.test(this.value)
			)
			{
				requiredItemNotField=true;
				this.style.background=INPUT_ERROR_COLOR;
				this.value='';
			}
			else
			{
				this.style.background='#fff';
			}
		}
	);
	
	
	if(!requiredItemNotField)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//***************************************************************************************
function validate_numeric_value()
{
	var requiredItemNotNumeric=false;
	
	$(".required_numeric").each(
		function ()
		{
			var value=this.value;
			value=value.replace(/\,/gi, "");
			value=value.replace(/\./gi, "");
			if(!isInt(value))
			{
				requiredItemNotNumeric=true;
				this.style.background=INPUT_ERROR_COLOR;
				
			}
			else
			{
				this.style.background='#fff';
			}
		}
	);
	
	
	if(!requiredItemNotNumeric)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//***************************************************************************************
function validate_password()
{
	var password=$('#users_password').val();
	var passwordconfirm=$('#users_password_confirm').val();
	
	if(password!=passwordconfirm || password.length==0 || passwordconfirm.length==0)
	{
		$('#users_password').css('background',INPUT_ERROR_COLOR);
		$('#users_password_confirm').css('background',INPUT_ERROR_COLOR);

		if(password!=passwordconfirm)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		$('#users_password').css('background','#fff');
		$('#users_password_confirm').css('background','#fff');
		return true;
	}
}
//***************************************************************************************
function ShowSavingDataDiv()
{
	var DivHtml=''+
	'<table border="0" bgcolor="#F1EDE2" width="100%" height="100%">'+
		'<tr>'+
			'<td width="100%" align="center" style="text-align:center">'+
				'<img src="'+base_url+'images/Loading_Clock.gif" border="0">'+
				'<p>I am saving your data</p>'+
			'</td>'+
		'</tr>'+
	'</table>';

	ShowCoverDivScreen('coverDiv', 'contentDiv', '400', '400', DivHtml);
}
//***************************************************************************************



//******************************************************************************************
//This function was pulled from http://www.htmldog.com/articles/suckerfish/dropdowns/,
//this allows the dropdown menus to function in IE.
//******************************************************************************************
sfHover = function() 
{
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<=sfEls.length; i++)
	{
		sfEls[i].onmouseover=function()
		{
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function()
		{
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//******************************************************************************************

