﻿function LoginCheckUser()
{
if (document.getElementById('useremail').value == '')
	{
	document.getElementById('useremailtext').style.color = "#FF0000";
	}
else
	{
	document.getElementById('useremailtext').style.color = "#000000";
	}
	
if (document.getElementById('userpassword').value == '')
	{
	document.getElementById('userpasswordtext').style.color = "#FF0000";
	}
else
	{
	document.getElementById('userpasswordtext').style.color = "#000000";
	}

if (document.getElementById('useremail').value != '' & document.getElementById('userpassword').value != '')
	{
	document.getElementById('userloginform').submit();
	}
}

function LoginCheckNetwork()
{
if (document.getElementById('networkusername').value == '')
	{
	document.getElementById('networkusernametext').style.color = "#FF0000";
	}
else
	{
	document.getElementById('networkusernametext').style.color = "#000000";
	}
	
if (document.getElementById('networkpassword').value == '')
	{
	document.getElementById('networkpasswordtext').style.color = "#FF0000";
	}
else
	{
	document.getElementById('networkpasswordtext').style.color = "#000000";
	}

if (document.getElementById('networkusername').value != '' & document.getElementById('networkpassword').value != '')
	{
	document.getElementById('networkloginform').submit();
	}
}

function LoginCheckAdmin()
{
if (document.getElementById('adminusername').value == '')
	{
	document.getElementById('adminusernametext').style.color = "#FF0000";
	}
else
	{
	document.getElementById('adminusernametext').style.color = "#000000";
	}
	
if (document.getElementById('adminpassword').value == '')
	{
	document.getElementById('adminpasswordtext').style.color = "#FF0000";
	}
else
	{
	document.getElementById('adminpasswordtext').style.color = "#000000";
	}

if (document.getElementById('adminusername').value != '' & document.getElementById('adminpassword').value != '')
	{
	document.getElementById('adminloginform').submit();
	}
}

function CheckAgreeApplicationForm()
{
	if (document.getElementById('Agree').checked == false)
	{
		alert('You must agree that all the information is complete and accurate.');
		return false
	}
			
	if (ValidateForm() == false)
	{
		return false
	}
	return true
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(UpID){
	var emailID=document.getElementById('Email')
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	if (UpID == 'yes') {
	if (CheckNewPass()==false){
	document.getElementById('newpass').focus()
	return false
	}}
	return true
 }

function CheckNewPass()
{
	if (document.getElementById('newpass').value == document.getElementById('confirmpass').value)
		{
			if (document.getElementById('newpass').value == '')
				{
					alert('Password cannot be blank!');
					return false
				}
			return true
		}
	else
		{
			alert('Passwords do not match!');
			document.getElementById('newpass').value = '';
			document.getElementById('confirmpass').value = '';
			return false
		}
}

function DeleteConfirm(IdID)
{
	var confirmation = confirm('Are you sure you want to delete this account?')
	if (confirmation == true)
		{
		document.location = 'admin_save_account.asp?page=delete&id=' + IdID
		}
}

function Show(Obj1)
{
var Obj = document.layers ? document.layers[Obj1] :
document.getElementById ?  document.getElementById(Obj1) :
document.all[Obj1];

if (Obj.style.display == "none")
{
Obj.style.display = "block"
}
else
{
Obj.style.display = "none"
}
}

function ChangePass()
{
	if (document.getElementById('newpass').value != document.getElementById('confirmpass').value)
		{
			alert('Passwords do not match.');
			document.getElementById('newpass').value = '';
			document.getElementById('confirmpass').value = '';
			document.getElementById('newpass').select()
		}
	else
		{
			document.getElementById('PassForm').submit()
		}
}

function DeleteConfirmUser()
{
	var confirmation = confirm('Are you sure you want to delete your account?')
	if (confirmation == true)
		{
		document.location = 'user_save_account.asp?page=delete'
		}
}

function DeleteConfirmAdminAccount(UsernameID)
{
	var confirmation = confirm('Are you sure you want to delete this account?')
	if (confirmation == true)
		{
		document.location = 'manage_admin_accounts.asp?page=delete&username=' + UsernameID
		}
}

function DeleteConfirmAllyNetworkAccount(networkId)
{
	var confirmation = confirm('Are you sure you want to delete this account?')
	if (confirmation == true)
		{
		document.location = 'manage_ally_network_accounts.asp?page=delete&id=' + networkId
		}
}

function ShowUserLogin()
{
	document.getElementById('adminLogin').style.display = 'none';
	document.getElementById('networkLogin').style.display = 'none';
	document.getElementById('contactLayer').style.display = 'none';
	if (document.getElementById('userLogin').style.display == '')
	{
		document.getElementById('userLogin').style.display = 'none';
	}
	else
	{
		document.getElementById('userLogin').style.display = '';
	}
}

function ShowAdminLogin()
{
	document.getElementById('networkLogin').style.display = 'none';
	document.getElementById('contactLayer').style.display = 'none';
	document.getElementById('userLogin').style.display = 'none';
	if (document.getElementById('adminLogin').style.display == '')
	{
		document.getElementById('adminLogin').style.display = 'none';
	}
	else
	{
		document.getElementById('adminLogin').style.display = '';
	}
}

function ShowNetworkLogin()
{
	document.getElementById('adminLogin').style.display = 'none';
	document.getElementById('contactLayer').style.display = 'none';
	document.getElementById('userLogin').style.display = 'none';
	if (document.getElementById('networkLogin').style.display == '')
	{
		document.getElementById('networkLogin').style.display = 'none';
	}
	else
	{
		document.getElementById('networkLogin').style.display = '';
	}
}

function ShowContact()
{
	document.getElementById('adminLogin').style.display = 'none';
	document.getElementById('networkLogin').style.display = 'none';
	document.getElementById('userLogin').style.display = 'none';
	if (document.getElementById('contactLayer').style.display == '')
	{
		document.getElementById('contactLayer').style.display = 'none';
	}
	else
	{
		document.getElementById('contactLayer').style.display = '';
	}
}

function CheckMail()
{
var Send = 'yes'
if (document.getElementById('ContactForm').name.value == '')
	{
	Send = 'no'
	document.getElementById('fromField').style.color = '#FF0000'
	}
else
	{
	document.getElementById('fromField').style.color = '#000000'
	}
	
if (document.getElementById('ContactForm').email.value == '')
	{
	Send = 'no'
	document.getElementById('emailField').style.color = '#FF0000'
	}
else
	{
	document.getElementById('emailField').style.color = '#000000'
	}
	
if (document.getElementById('body').value == '')
	{
	Send = 'no'
	document.getElementById('bodyField').style.color = '#FF0000'
	}
else
	{
	document.getElementById('bodyField').style.color = '#000000'
	}

if (Send == 'yes')
	{
	document.getElementById('ContactForm').submit()
	}

}

function ServCheck()
{
	if (document.getElementById('B5').value == 'Service Provider')
		{
			document.getElementById('serv1').style.display = ''
			document.getElementById('serv2').style.display = ''
			document.getElementById('serv3').style.display = ''
			document.getElementById('serv4').style.display = 'none'
		}
	else
		{
			document.getElementById('serv1').style.display = 'none'
			document.getElementById('serv2').style.display = 'none'
			document.getElementById('serv3').style.display = 'none'
			document.getElementById('serv4').style.display = ''
		}
}
function DeleteApplicationConfirm(IdID)
{
	var confirmation = confirm('Are you sure you want to delete this item?')
	if (confirmation == true)
		{
			window.open('delete.asp?id=' + IdID + '','deleteWindow');
			var t=setTimeout("location.reload(true)",3000);
		}
}

function Show(Obj1)
{
var Obj = document.layers ? document.layers[Obj1] :
document.getElementById ?  document.getElementById(Obj1) :
document.all[Obj1];

if (Obj.style.display == "none")
{
Obj.style.display = "block"
}
else
{
Obj.style.display = "none"
}
}

function DeleteConfirmCategory(IdID,Category)
{
	var confirmation = confirm('Are you sure you want to delete \'' + Category + '\' from your categories?\n\n**ALL ITEM CATEGORIES SET TO \'' + Category + '\' WILL BE RESET TO \'Other\'.**')
	if (confirmation == true)
		{
		document.location = 'categories.asp?page=delete&id=' + IdID;
		}
}

function DeleteConfirmType(IdID,Type)
{
	var confirmation = confirm('Are you sure you want to delete \'' + Type + '\' from your types?\n\n**ALL ITEM TYPES SET TO \'' + Type + '\' WILL BE RESET TO \'Other\'.**')
	if (confirmation == true)
		{
		document.location = 'types.asp?page=delete&id=' + IdID;
		}
}

function DeleteConfirmPaymentType(IdID,PaymentType)
{
	var confirmation = confirm('Are you sure you want to delete \'' + PaymentType + '\' from your payment types?\n\n**ALL ITEM PAYMENT TYPES SET TO \'' + PaymentType + '\' WILL BE RESET TO \'Other\'.**')
	if (confirmation == true)
		{
		document.location = 'paymenttypes.asp?page=delete&id=' + IdID;
		}
}

function ConfirmClearAll()
{
	var confirmation = confirm('Are you sure you want to clear all expenses?')
	if (confirmation == true)
		{
		document.location = 'clearexpenses.asp';
		}
}

function ChangeFilter(Filter)
{
	if (Filter == 'category')
		{
			document.getElementById('category').style.display = 'block';
			document.getElementById('type').style.display = 'none';
			document.getElementById('paymenttype').style.display = 'none';
			document.getElementById('date').style.display = 'none';
			document.getElementById('buttons').style.display = 'block';
		}
	if (Filter == 'type')
		{
			document.getElementById('category').style.display = 'none';
			document.getElementById('type').style.display = 'block';
			document.getElementById('paymenttype').style.display = 'none';
			document.getElementById('date').style.display = 'none';
			document.getElementById('buttons').style.display = 'block';
		}
	if (Filter == 'paymenttype')
		{
			document.getElementById('category').style.display = 'none';
			document.getElementById('type').style.display = 'none';
			document.getElementById('paymenttype').style.display = 'block';
			document.getElementById('date').style.display = 'none';
			document.getElementById('buttons').style.display = 'block';
		}
	if (Filter == 'date')
		{
			document.getElementById('category').style.display = 'none';
			document.getElementById('type').style.display = 'none';
			document.getElementById('paymenttype').style.display = 'none';
			document.getElementById('date').style.display = 'block';
			document.getElementById('buttons').style.display = 'none';
		}
	if (Filter == '')
		{
			document.getElementById('category').style.display = 'none';
			document.getElementById('type').style.display = 'none';
			document.getElementById('paymenttype').style.display = 'none';
			document.getElementById('date').style.display = 'none';
			document.getElementById('buttons').style.display = 'block';
		}

}
