String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}		
function checkRadioButtonStatus()
{
	var rad_val1 = "";
	var rad_val2 = "";
	var rad_val3 = "";
	var rad_val4 = "";	
	
	//emergency
	for (var i=0; i < document.frmSubscription.rdemerg.length; i++)
	{
		if (document.frmSubscription.rdemerg[i].checked)
		{
			rad_val1 = document.frmSubscription.rdemerg[i].value;
		}
	}
	if (rad_val1 == "")
	{				
		alert("You must specify if you want to be subscribed to the Emergencies notifications or not.")
		statuscheck = "N";
		return;		
	}else{
		document.frmSubscription.hiddenrdemerg.value = rad_val1;
	}	
	
	//jobs
	for (var i=0; i < document.frmSubscription.rdjobs.length; i++)
	{
		if (document.frmSubscription.rdjobs[i].checked)
		{
			rad_val2 = document.frmSubscription.rdjobs[i].value;
		}
	}
	if (rad_val2 == "")
	{				
		alert("You must specify if you want to be subscribed to the Jobs notifications or not.")
		statuscheck = "N";
		return;		
	}else{
		document.frmSubscription.hiddenrdjobs.value = rad_val2;
	}	
	//community calendar
	for (var i=0; i < document.frmSubscription.rdEvents.length; i++)
	{
		if (document.frmSubscription.rdEvents[i].checked)
		{
			rad_val3 = document.frmSubscription.rdEvents[i].value;
		}
	}
	if (rad_val3 == "")
	{				
		alert("You must specify if you want to be subscribed to the Community Calendar notification or not.")
		statuscheck = "N";
		return;		
	}else{
		document.frmSubscription.hiddenrdevents.value = rad_val3;
	}
		
	//bidders
	for (var i=0; i < document.frmSubscription.rdbids.length; i++)
	{
		if (document.frmSubscription.rdbids[i].checked)
		{
			rad_val4 = document.frmSubscription.rdbids[i].value;
		}
	}
	if (rad_val4 == "")
	{				
		alert("You must specify if you want to be subscribed to the Bidder's job notification or not.")
		statuscheck = "N";
		return;		
	}else{
		document.frmSubscription.hiddenrdbids.value = rad_val4;
	}	
	
}
function checkMandatoryFields(src)
{
	a = src.value;
	if (a == "")
	{
		alert("You must enter a valid e-mail address")
		document.frmSubscription.txtemail.focus() 		
		statuscheck = "N";
		return;
	}
	var at = a.indexOf("@") 
	var name = a.substring(0, at) 
	var isp = a.substring(at + 1, a.length) 
	var dot = a.lastIndexOf(".") 
	if (at == -1 || at == 0 || name == "" || isp == "" || dot == -1 || dot == (a.length - 1)) { 
			alert("Please make sure that you include your correct email address.");
			//document.frmSubscription.txtemail.focus();
			src.focus();
			statuscheck = "N";
	} 
}
function check_Bidders()
{
	if (document.frmSubscription.hiddenrdbids.value == "Y")
	{
		var jobTypesSelected = "";
		if (document.frmSubscription.txtCompanyName.value == "")
		{
			alert("Please enter the Contractor name.");
			statuscheck = "N";
			document.frmSubscription.txtCompanyName.focus();
			return;
		}		
		for (var i=0; i < document.frmSubscription.lbJobTypes.length; i++)
		{
			if (document.frmSubscription.lbJobTypes[i].selected)
			{
				jobTypesSelected += document.frmSubscription.lbJobTypes[i].value + "|";
			}
		}		
		if (jobTypesSelected == "")
		{
			alert("You must specify which Job types you wish to be notified of.");
			statuscheck = "N";
			return;
		}
	}
}
function check_Events()
{
	if (document.frmSubscription.hiddenrdevents.value == "Y")
	{
		var communitiesSelected = "";
		var categoriesSelected = "";
		for (var i=0; i < document.frmSubscription.lbCommunity.length; i++)
		{
			if (document.frmSubscription.lbCommunity[i].selected)
			{
				communitiesSelected += document.frmSubscription.lbCommunity[i].value + "|";
			}
		}		
		if (communitiesSelected == "")
		{
			alert("You must specify a Community to receive notifications from.");
			statuscheck = "N";
			return;
		}
		
		for (var i=0; i < document.frmSubscription.lbCategory.length; i++)
		{
			if (document.frmSubscription.lbCategory[i].selected)
			{
				categoriesSelected += document.frmSubscription.lbCategory[i].value + "|";
			}
		}				
	}
}
function submit_onclick()
{		
	statuscheck	 = "Y";
	checkMandatoryFields(document.frmSubscription.txtemail);
	if (statuscheck != "N")
	{
		checkRadioButtonStatus();			
	}
	if (statuscheck != "N")
	{
		check_Bidders();			
	}	
	if (statuscheck != "N")
	{
		check_Events();			
	}	
	if (statuscheck != "N")
	{
		document.frmSubscription.submit();
	}
}     
function change_onclick()
{
	statuscheck	 = "Y";
	if (document.frmSubscription.txtemailChange.value == "")
	{
		alert("You must specify the e-mail address that you wish to make subscription changes to.");
		statuscheck = "N";
		document.frmSubscription.txtemailChange.focus();
		return;		
	}
	else
	{
		checkMandatoryFields(document.frmSubscription.txtemailChange);
	}
	if (statuscheck != "N")
	{
		document.frmSubscription.submit();
	}	
}
function checkFields()
{			
	if (document.frmSubscription.hiddenaction.value == "done")
	{
		document.getElementById('linksubmit').outerHTML="<font class='regularblackaction'>Submit</font>"
	}	
}				 
function switchDiv(src)
{			
	if (src == 'a')
	{			
		var rad_val1 = "";
		for (var i=0; i < document.frmSubscription.rdbids.length; i++)
		{
			if (document.frmSubscription.rdbids[i].checked)
			{
				rad_val1 = document.frmSubscription.rdbids[i].value;
			}
		}
		if (rad_val1 == "Y")
		{
			document.all["divBidTypes"].style.display = '';
		}
		else
		{
			document.all["divBidTypes"].style.display = 'none';
		}				
	}
	else if (src == "b")
	{
		var rad_val1 = "";
		for (var i=0; i < document.frmSubscription.rdEvents.length; i++)
		{
			if (document.frmSubscription.rdEvents[i].checked)
			{
				rad_val1 = document.frmSubscription.rdEvents[i].value;
			}
		}
		if (rad_val1 == "Y")
		{
			document.all["divEventTypes"].style.display = '';
		}
		else
		{
			document.all["divEventTypes"].style.display = 'none';
		}				
	}
}
