﻿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 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 ShowUserLogin()
{
	if (document.getElementById('adminlogin').style.display == '')
		{
			document.getElementById('adminlogin').style.display = 'none';
		}
	if (document.getElementById('ContactLayer').style.display == '')
		{
		document.getElementById('ContactLayer').style.display = 'none';
		}
	if (document.getElementById('userlogin').style.display == 'none')
		{
			document.getElementById('userlogin').style.display = '';
			document.getElementById('useremail').focus();
		}
	else
		{
			document.getElementById('userlogin').style.display = 'none';
		}
}

function ShowAdminLogin()
{
	if (document.getElementById('userlogin').style.display == '')
		{
			document.getElementById('userlogin').style.display = 'none';
		}
	if (document.getElementById('ContactLayer').style.display == '')
		{
		document.getElementById('ContactLayer').style.display = 'none';
		}
	if (document.getElementById('adminlogin').style.display == 'none')
		{
			document.getElementById('adminlogin').style.display = '';
			document.getElementById('adminusername').focus();
		}
	else
		{
			document.getElementById('adminlogin').style.display = 'none';
		}
}

function ShowContact()
{
	if (document.getElementById('userlogin').style.display == '')
		{
			document.getElementById('userlogin').style.display = 'none';
		}
	if (document.getElementById('adminlogin').style.display == '')
		{
		document.getElementById('adminlogin').style.display = 'none';
		}
	if (document.getElementById('ContactLayer').style.display == 'none')
		{
			document.getElementById('ContactLayer').style.display = '';
		}
	else
		{
			document.getElementById('ContactLayer').style.display = 'none';
		}
}

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 = ''
		}
}