// JScript File
function show(id) {
	document.getElementById(id).style.visibility = "visible";
}

function changeText(id, strText)	{
	document.getElementById(id).innerHTML= strText;
}

function hide(id) {
	document.getElementById(id).style.visibility = "hidden";
}
function checkIfNumeric()
{
alert(event.keyCode);
 if (event.keyCode < 48 || event.keyCode > 57)
 {  
	alert('in');
	event.returnValue = false
 }
	
}
function DunsFormatWithZeros(id)
{
 
	 var formatDuns ="";  
	 formatDuns=id.value;
	 
	 
	
	 
	 
	 unformatDuns=formatDuns.replace(/-/gi, ""); 
	 if (!(isNaN(unformatDuns)))
	 {
	  if(unformatDuns.length>1)
	  {
		if (unformatDuns.length<5)
		{
				formatDuns = unformatDuns.substring(0,2) + '-' + unformatDuns.substring(2,5);
		}
		else
		{
				formatDuns = unformatDuns.substring(0,2) + '-' + unformatDuns.substring(2,5) + '-' + unformatDuns.substring(5);
		}
	   
	    id.value=formatDuns;
	 }
	 else
	 {
		id.value=unformatDuns;
	 }

	
	 var DunsLength =0;
	 formatDuns=id.value
	 DunsLength=formatDuns.length;
	 if(formatDuns.charAt(DunsLength-1)=='-')
	 {
		id.value=formatDuns.substring(0,(DunsLength-1));
	 }
	} 
}


function DunsFormat(id)
{
	var nonNumericFlag="0"
	if(!(event.keyCode==37 || event.keyCode==39))
	{
	
	
		var unformatDuns =""; 
		var formatDUNS ="";
		formatDUNS = id.value;
		var DunsLength=0;
		var keyValue="";
		keyValue=String.fromCharCode(event.keyCode);
		//alert('Key Vaue '+keyValue);
		//if(isNaN(keyValue))
		//{
			
		//	if (!(event.keyCode == 8 || event.keyCode == 46))
		//	{
			
		//		if((event.keyCode <= 47 && event.keyCode >= 32)||(event.keyCode <= 127 && event.keyCode >= 58))
		//		{
		//			alert('Please enter numeric values');
		//			formatDUNS= formatDUNS.replace(keyValue.toLowerCase(), ""); 
		//			formatDUNS= formatDUNS.replace(keyValue.toUpperCase(), "");
		//		}
		//	}
		//}
	
	
	
		//Showing error message on entering non numeric values
	
		if (!(event.keyCode == 8 || event.keyCode == 46))
		{
			//alert(event.keyCode);
			if (!(event.keyCode==45))// key code=45 for '-'
			{
				if(!(event.keyCode==32))
				{
					unformatDuns=formatDUNS.replace(/-/gi, ""); // if key pressed is not '-' then remove all '-' and check the textbox value
					if(isNaN(unformatDuns))
					{
						nonNumericFlag="1"
						if(unformatDuns.length>9)
						{
							alert('You are not allowed to enter more than 9 digits.All non numeric values will be removed from this field.');
							
						}
						else
						{
							alert('You are not allowed to enter non numeric values.All non numeric values will be removed from this field.');
							
						}	
					}
				}
				else
				{
						nonNumericFlag="1"
						if(unformatDuns.length>9)
						{
							alert('You are not allowed to enter more than 9 digits.All non numeric values will be removed from this field.');
							
						}
						else
						{
							alert('You are not allowed to enter non numeric values.All non numeric values will be removed from this field.');
							
						}
					formatDUNS=formatDUNS.replace(/ /gi, ""); // if key pressed is space bar then remove all space
				}
			}
			else // if key pressed is '-', then show error message
			{
					nonNumericFlag="1"
					if(unformatDuns.length>9)
						{
							alert('You are not allowed to enter more than 9 digits.All non numeric values will be removed from this field.');
							//nonNumericFlag="0"
						}
						else
						{
							alert('You are not allowed to enter non numeric values.All non numeric values will be removed from this field.');
							//nonNumericFlag="1"
						}
			}
		}
	
		//Removing non numeric values
		var i=0;
		var flag=0;
		var formatDunsLenth=0;
		formatDunsLenth=formatDUNS.length
		for (i=0;i<formatDunsLenth;i++)
		{
		//alert('unformatDuns.charat('+i+')='+unformatDuns.charAt(i));
			if(isNaN(formatDUNS.charAt(i)))
			{
				if(!(formatDUNS.charAt(i)=='-'))
				{
					formatDUNS=formatDUNS.replace(formatDUNS.charAt(i), ""); // removing all non-numeric values
					//flag=1;
					
					i=-1;
				}
			}
		}
		unformatDuns=formatDUNS.replace(/-/gi, ""); 
	
	//Displaying error message on entering value greater than 9 digit
	if (unformatDuns.length>9)
	{
		if (!(event.keyCode == 8 || event.keyCode == 46))
		{
			unformatDuns=unformatDuns.substring(0,9)
			if(nonNumericFlag=="0")
			{
				//var substringLength=(unformatDuns.length)-1
				//unformatDuns=unformatDuns.substring(0,substringLength)
				
				alert ("You are not allowed to enter a value greater than 9 digits");
			}	
		}	
		
	}
	 
	
		if (!(event.keyCode == 8 || event.keyCode == 46))
		{ 
			
			if(flag==0)
			{ 
			
				if(unformatDuns.length>1)
				{
					if (unformatDuns.length<5)
					{
						formatDUNS = unformatDuns.substring(0,2) + '-' + unformatDuns.substring(2,5);
					}
					else
					{
						formatDUNS = unformatDuns.substring(0,2) + '-' + unformatDuns.substring(2,5) + '-' + unformatDuns.substring(5);
					}
		   
					id.value=formatDUNS;
					if(id.value=="00-000-0000")
					{
						alert("00-000-0000 is not a valid DUNS");
						id.value="";
					}
				}
				else
				{
					id.value=unformatDuns;
					if(id.value=="00-000-0000")
					{
						alert("00-000-0000 is not a valid DUNS");
						id.value="";
					}
				}
			}
			else
			{
				id.value=formatDUNS;
				if(id.value=="00-000-0000")
					{
						alert("00-000-0000 is not a valid DUNS");
						id.value="";
					}
			}
		
		}

}

	return true;
}

function PopulateFamCC(){
//populates the familiy select list
	if (document.SelfReg.com_sg_search.value == "0")
	{	document.getElementById('comm_fm_select').innerHTML = 'Please Select a Top Level Commodity';
	}
	else
	{	document.getElementById('comm_fm_select').innerHTML = 'Loading Second Level Commodities...';

		//do AJAX to get search results
		ajaxRequest('/SelfAssessment/AJAXData.asp?SGC=' + document.SelfReg.com_sg_search.value, 
			'comm_fm_select');
	}
	return true;
}

function AddSelectCC(){
//add the commodity code selected from the drowdown boxes

	
	//if this is the first comm, clear out the start notice
	if (CommCount == 0){
		document.getElementById('Comm_List').innerHTML = '<b>Selected Commodities:</b><br>';
	}
	var CommCode = document.SelfReg.com_sg_search[document.SelfReg.com_sg_search.selectedIndex].value + '' 
		+ document.SelfReg.FM_Code[document.SelfReg.FM_Code.selectedIndex].value

	var CommTitle = document.SelfReg.com_sg_search[document.SelfReg.com_sg_search.selectedIndex].text + '-' 
		+ document.SelfReg.FM_Code[document.SelfReg.FM_Code.selectedIndex].text
			
	//add the comm to the list if it is not already in there
	if (document.getElementById('Comm' + CommCode) == null){
		document.getElementById('Comm_List').innerHTML = document.getElementById('Comm_List').innerHTML +
			'<span ID="Comm' + CommCode + '">' + CommTitle + 
			' - <a href="javascript:RemoveComm(\'' + CommCode + '\');">' +
			'Remove This Commodity</a><input type="hidden" name="Comm' + CommCount + '" value="' + CommCode + '">' +
			'<br></span>';
		} else {
			if (document.getElementById('Comm' + CommCode).innerHTML == ''){
				document.getElementById('Comm' + CommCode).innerHTML = '' + CommTitle + 
					' - <a href="javascript:RemoveComm(\'' + CommCode + '\');">' +
					'Remove This Commodity</a><input type="hidden" name="Comm' + CommCount + '" value="' + CommCode + '">' +
					'<br>';
		}	
	}
	
	CommCount +=1;
	document.SelfReg.commCount.value = CommCount;
}

function AddCC(intCCCode){
//add the commodity code from the search results
	//if this is the first comm, clear out the start notice
	if (CommCount == 0){
		document.getElementById('Comm_List').innerHTML = '<b>Selected Commodities:</b><br>';
	}
	//add the site to the list if it is not already in there
	if (document.getElementById('Comm' + intCCCode) == null){
		document.getElementById('Comm_List').innerHTML = document.getElementById('Comm_List').innerHTML +
			'<span ID="Comm' + intCCCode + '">' + 
			document.getElementById('CC' + intCCCode).innerHTML + 
			' - <a href="javascript:RemoveComm(\'' + intCCCode + '\');">' +
			'Remove This Commodity</a><input type="hidden" name="Comm' + CommCount + '" value="' + intCCCode + '">' +
			'<br></div>';
		} else {
			if (document.getElementById('Comm' + intCCCode).innerHTML == ''){
				document.getElementById('Comm' + intCCCode).innerHTML = '' +
					document.getElementById('CC' + intCCCode).innerHTML + 
					' - <a href="javascript:RemoveComm(\'' + intCCCode + '\');">' +
					'Remove This Commodity</a><input type="hidden" name="Comm' + CommCount + '" value="' + intCCCode + '">' +
					'<br>';
		}	
	}
	
	CommCount +=1;
	document.SelfReg.commCount.value = CommCount;

}

function RemoveComm(intCommID){
//removes the site from the Site_List section

	document.getElementById('Comm' + String(intCommID)).innerHTML = '';
//	return true;
}

function CommSearch(){
	if (document.SelfReg.CommSearchString.value == ''){
		alert('The commodity search must have a term to search for.');
		return false;
	}
	
//	document.getElementById('CommSearchResults').innerHTML = '<b>Search Results:</b><br>Performing Search...';
	
	//do AJAX to get search results
	ajaxRequest('/SelfAssessment/AJAXData.asp?comm=' + document.SelfReg.CommSearchString.value, 
		'CommSearchResults');

}

function SaveContact(){
//saves the entered contact information to the document
var strHTML;
var bLogin;
var intContactID = document.SelfReg.EditContactID.value - 0;

//validate content first
	if ((document.SelfReg.ContactFirstName.value == '') || (document.SelfReg.ContactFirstName.value == null)){
		alert('The First Name field is blank. The contact information cannot be saved without a first name.');
		return false;
	}
	if ((document.SelfReg.ContactLastName.value == '') || (document.SelfReg.ContactLastName.value == null)){
		alert('The Last Name field is blank. The contact information cannot be saved without a last name.');
		return false;
	}
	if ((document.SelfReg.ContactEmail.value == '') || (document.SelfReg.ContactEmail.value == null)){
		alert('The Email field is blank. The contact information cannot be saved without an email address.');
		return false;
	}
	//Added on jan 19 - Sreevidya
	if (!(emailValidation(document.SelfReg.ContactEmail.value)))
	{
		alert('Enter valid email address');
		document.getElementById('ContactEmail').focus()	
		return false;
	}
	//else
	//{
	//alert('hi');
	//}
	
	if ((document.SelfReg.ContactTitle.value == '') || (document.SelfReg.ContactTitle.value == null)){
		alert('The Title field is blank. The contact information cannot be saved without a title.');
		return false;
	}
	if ((document.SelfReg.ContactPhone.value == '') || (document.SelfReg.ContactPhone.value == null)){
		alert('The Telephone field is blank. The contact information cannot be saved without a telephone number.');
		return false;
	}
	if ((document.SelfReg.ContactFax.value == '') || (document.SelfReg.ContactFax.value == null)){
		alert('The Fax field is blank. The contact information cannot be saved without a fax number.');
		return false;
	}
	if (ValidateRoles() == false){
		alert('No Role has been checked for this contact. Each contact must have at least one role.');
		return false;
	}
	if (ValidateNCMR() == false){
		alert('Both NCMR Contact and NCMR Backup Contact Should not be a same person');
		return false;
	}

//if valid content then save it
	if (document.SelfReg.CurrentContactID.value - 0 == 0) {
	//first entry so get rid of contact notice
		document.getElementById('contact_list').innerHTML = '';
	};
	
	if (document.SelfReg.ContactLoginRequired.checked == true){
			bLogin = 1;
		}
		else
		{
		   bLogin = 0;
		}
	strHTML = '<span ID="ContactID' + intContactID + '">' +
		'<table width="100%" border=1 cellpadding=0 cellspacing=0>' +
		'<tr><td>Name:</td><td>' + document.SelfReg.ContactFirstName.value + ' ' + 
		document.SelfReg.ContactLastName.value + '</td>' +
		'<td>Title:</td><td>' + document.SelfReg.ContactTitle.value + '</td></tr>' +
		'<tr><td>Email Address:</td><td colspan=3>' + document.SelfReg.ContactEmail.value + '</td></tr>' +
		'<tr><td>Telephone Number:</td><td>' + document.SelfReg.ContactPhone.value + '</td>' +
		'<td>Fax Number:</td><td>' + document.SelfReg.ContactFax.value + '</td></tr>' +
		'<tr><td>Roles:</td><td colspan=3>' + ShowRoles(intContactID) + '</td></tr></table>' +
		'<input type="hidden" name="' + intContactID + 'FirstName" ID="' + intContactID + 'FirstName" value="' + document.SelfReg.ContactFirstName.value +'">' +
		'<input type="hidden" name="' + intContactID + 'LastName" ID="' + intContactID + 'LastName" value="' + document.SelfReg.ContactLastName.value +'">' +
		'<input type="hidden" name="' + intContactID + 'Title" ID="' + intContactID + 'Title" value="' + document.SelfReg.ContactTitle.value +'">' +
		'<input type="hidden" name="' + intContactID + 'Email" ID="' + intContactID + 'Email" value="' + document.SelfReg.ContactEmail.value +'">' +
		'<input type="hidden" name="' + intContactID + 'Phone" ID="' + intContactID + 'Phone" value="' + document.SelfReg.ContactPhone.value +'">' +
		'<input type="hidden" name="' + intContactID + 'Fax" ID="' + intContactID + 'Fax" value="' + document.SelfReg.ContactFax.value +'">';
        '<input type="hidden" name="' + intContactID + 'Login_Requested" ID="' + intContactID + 'Login_Requested" value="' + bLogin +'">';
	if (document.SelfReg.ContactAddress1.value != ""){
		strHTML = strHTML + '<table width="100%" border=1 cellpadding=0 cellspacing=0>' +
			'<tr><td>Address:</td><td>' + document.SelfReg.ContactAddress1.value + '</td>' +
			'<td>City:</td><td>' + document.SelfReg.ContactCity.value + '</td></tr>' +
			'<tr><td>&nbsp;</td><td>' + document.SelfReg.ContactAddress2.value + '</td>' +
			'<td>State/Province:</td><td>' + document.SelfReg.ContactState.value + '</td></tr>' +
			'<tr><td>Country</td><td>' + document.SelfReg.ContactCountry.value + '</td>' +
			'<td>Postal Code:</td><td>' + document.SelfReg.ContactPostalCode.value + '</td></tr></table>' +
			'<input type="hidden" name="' + intContactID + 'Address1" ID="' + intContactID + 'Address1" value="' + document.SelfReg.ContactAddress1.value +'">' +
			'<input type="hidden" name="' + intContactID + 'Address2" ID="' + intContactID + 'Address2" value="' + document.SelfReg.ContactAddress2.value +'">' +
			'<input type="hidden" name="' + intContactID + 'City" ID="' + intContactID + 'City" value="' + document.SelfReg.ContactCity.value +'">' +
			'<input type="hidden" name="' + intContactID + 'State" ID="' + intContactID + 'State" value="' + document.SelfReg.ContactState.value +'">' +
			'<input type="hidden" name="' + intContactID + 'Country" ID="' + intContactID + 'Country" value="' + document.SelfReg.ContactCountry.value +'">' +
			'<input type="hidden" name="' + intContactID + 'PostalCode" ID="' + intContactID + 'PostalCode" value="' + document.SelfReg.ContactPostalCode.value + '">';
	}

	strHTML = strHTML + '<table width="100%" border=1 cellpadding=0 cellspacing=0>' +
		'<tr><td bgcolor=silver align=center><a href="javascript:EditContact(' + intContactID + ');">Edit this Contact</a> ' +
		'- <a href="javascript:DeleteContact(' + intContactID + ');">Remove this Contact</a></td></tr></table></span>';
	
	if ((ContactCount == intContactID) || (ContactCount == 0)){
	//ContactCount will only equal ContactID for a new record. so add a new contact record
		document.getElementById('contact_list').innerHTML = document.getElementById('contact_list').innerHTML + strHTML;
		ContactCount = ContactCount + 1;
		document.SelfReg.CurrentContactID.value = ContactCount;
		document.SelfReg.EditContactID.value = ContactCount;
	} else {
	//update existing contact record
		document.getElementById('ContactID' + intContactID).innerHTML = strHTML;
	};

//clear the form
	ClearContact();
	
	return true;
};

function EditContact(intContactID){
//moves the contact info for the specified contact ID back to the edit portion
	document.SelfReg.ContactFirstName.value = document.getElementById(intContactID + 'FirstName').value;
	document.SelfReg.ContactLastName.value = document.getElementById(intContactID + 'LastName').value;
	document.SelfReg.ContactTitle.value = document.getElementById(intContactID + 'Title').value;
	document.SelfReg.ContactEmail.value = document.getElementById(intContactID + 'Email').value;
	document.SelfReg.ContactPhone.value = document.getElementById(intContactID + 'Phone').value;
	document.SelfReg.ContactFax.value = document.getElementById(intContactID + 'Fax').value;
	if (document.getElementById(intContactID + 'Address1')){
	//if there is an address for the contact, load it
		document.SelfReg.ContactAddress1.value = document.getElementById(intContactID + 'Address1').value;
		document.SelfReg.ContactAddress2.value = document.getElementById(intContactID + 'Address2').value;
		document.SelfReg.ContactCity.value = document.getElementById(intContactID + 'City').value;
		document.SelfReg.ContactState.value = document.getElementById(intContactID + 'State').value;
		document.SelfReg.ContactCountry.value = document.getElementById(intContactID + 'Country').value;
		document.SelfReg.ContactPostalCode.value = document.getElementById(intContactID + 'PostalCode').value;
	} else {
	//no address data for the contact so clear the fields
		document.SelfReg.ContactAddress1.value = '';
		document.SelfReg.ContactAddress2.value = '';
		document.SelfReg.ContactCity.value = '';
		document.SelfReg.ContactState.value = '';
		document.SelfReg.ContactCountry.value = '';
		document.SelfReg.ContactPostalCode.value = '';
	}

	document.SelfReg.EditContactID.value = intContactID;

	LoadRoles(intContactID);
	
//	return true;
};

function ClearContact(){
//clears out all contact edit fields

	document.SelfReg.ContactFirstName.value = '';
	document.SelfReg.ContactLastName.value = '';
	document.SelfReg.ContactTitle.value = '';
	document.SelfReg.ContactEmail.value = '';
	document.SelfReg.ContactPhone.value = '';
	document.SelfReg.ContactFax.value = '';
	document.SelfReg.ContactAddress1.value = '';
	document.SelfReg.ContactAddress2.value = '';
	document.SelfReg.ContactCity.value = '';
	document.SelfReg.ContactState.value = '';
	document.SelfReg.ContactCountry.value = '';
	document.SelfReg.ContactPostalCode.value = '';
	
	ClearRoles();
	document.SelfReg.ContactLoginRequired.checked=false;
	document.SelfReg.Deactivate.checked=false;
	document.SelfReg.EditContactID.value = document.SelfReg.CurrentContactID.value;
//	document.SelfReg.ContactFirstName.value = ContactCount;
	return true;
};

function DeleteContact(intContactID){
//deletes the saved contact information
	document.getElementById('ContactID' + intContactID).innerHTML = '';	

};

function AddSelectedSite(){
//adds the selected site from the dropdown to the selected site list
var intSelectIndex = document.SelfReg.DanaSiteID.selectedIndex;

	if (document.SelfReg.DanaSiteID[intSelectIndex].value == '0'){
		alert('You must select a Dana site from the drop down list.');
		return false;
	}
	
	//if this is the first site, clear out the start notice
	if (SiteCount == 0){
		document.getElementById('Site_List').innerHTML = '<b>Selected Dana Locations:</b><br>';
	}
	
	//add the site to the list if it is not already in there
	if (document.getElementById('DanaSite' + document.SelfReg.DanaSiteID[intSelectIndex].value) == null){
		document.getElementById('Site_List').innerHTML = document.getElementById('Site_List').innerHTML +
			'<span ID="DanaSite' + document.SelfReg.DanaSiteID[intSelectIndex].value + '">' + 
			document.SelfReg.DanaSiteID[intSelectIndex].text + 
			' - <a href="javascript:RemoveSite(' + document.SelfReg.DanaSiteID[intSelectIndex].value + ');">' +
			'Remove This Site</a><input type="hidden" name="DanaID' + SiteCount + '" value="' + 
			document.SelfReg.DanaSiteID[intSelectIndex].value + '">' +
			'<br></div>';
		} else {
			if (document.getElementById('DanaSite' + document.SelfReg.DanaSiteID[intSelectIndex].value).innerHTML == ''){
				document.getElementById('DanaSite' + document.SelfReg.DanaSiteID[intSelectIndex].value).innerHTML = '' +
					document.SelfReg.DanaSiteID[intSelectIndex].text + 
					' - <a href="javascript:RemoveSite(' + document.SelfReg.DanaSiteID[intSelectIndex].value + ');">' +
					'Remove This Site</a><input type="hidden" name="DanaID' + SiteCount + '" value="' + 
					document.SelfReg.DanaSiteID[intSelectIndex].value + '">' +
					'<br>';
		}	
	}
	
	SiteCount += 1;
	
	document.SelfReg.siteCount.value = SiteCount;
	
	return true;
};

function AddSite(intSiteID){
//adds the site from the search results to the selected site list
	//if this is the first site, clear out the start notice
	if (SiteCount == 0){
		document.getElementById('Site_List').innerHTML = '<b>Selected Dana Locations:</b><br>';
	}
	
	//add the site to the list if it is not already in there
	if (document.getElementById('DanaSite' + intSiteID) == null){
		document.getElementById('Site_List').innerHTML = document.getElementById('Site_List').innerHTML +
			'<span ID="DanaSite' + intSiteID + '">' + 
			document.getElementById('DS' + intSiteID).innerHTML + 
			' - <a href="javascript:RemoveSite(' + intSiteID + ');">' +
			'Remove This Site</a><input type="hidden" name="DanaID' + SiteCount + '" value="' + intSiteID + '">' +
			'<br></div>';
		} else {
			if (document.getElementById('DanaSite' + intSiteID).innerHTML == ''){
				document.getElementById('DanaSite' + intSiteID).innerHTML = '' +
					document.getElementById('DS' + intSiteID).innerHTML + 
					' - <a href="javascript:RemoveSite(' + intSiteID + ');">' +
					'Remove This Site</a><input type="hidden" name="DanaID' + SiteCount + '" value="' + intSiteID + '">' +
					'<br>';
		}	
	}
	
	SiteCount += 1;
	
	document.SelfReg.siteCount.value = SiteCount;
	
//	return true;
};
function RemoveSite(intSiteID){
//removes the site from the Site_List section
	document.getElementById('DanaSite' + intSiteID).innerHTML = '';
//	return true;
}

function SiteSearch(){
	if (document.SelfReg.SiteSearchString.value == ''){
		alert('The site search must have a term to search for.');
		return false;
	}
	
	document.getElementById('SiteSearchResults').innerHTML = '<b>Search Results:</b><br>Performing Search...';
	
	//do AJAX to get search results
	ajaxRequest('/SelfAssessment/AJAXData.asp?site=' + document.SelfReg.SiteSearchString.value, 
		'SiteSearchResults');

}

function GetFileLevel(){
//returns the second level of file types or only the save button of there are no child types
var intSelectIndex = document.FileUpload.TopLevel.selectedIndex;

	document.getElementById('FileTypeResults').innerHTML = '<em>Loading...</em>';
	
	ajaxRequest('/SelfAssessment/AJAXData.asp?FT=' + document.FileUpload.TopLevel[intSelectIndex].value, 
		'FileTypeResults');
	
	return true;
}
//Added on Jan 08 2009 - Sreevidya
function echeck() 
{
	var emailID1=document.getElementById('email1').value
	var emailID2=document.getElementById('email2').value
	if ((emailID1==null)||(emailID1=="")){
		alert("Please Enter your Email ID")
		document.getElementById('email1').focus()
		document.getElementById('email2').value=""
		return false
	}
	else if (!(emailValidation(emailID1)))
	{
		alert("Invalid E-mail ID")
		document.getElementById('email1').value=""
		document.getElementById('email2').value=""
		document.getElementById('email1').focus()	
		return false
	}
	else if ((emailID2==null)||(emailID2==""))
	{
		alert("Please Enter your Email ID")
		document.getElementById('email2').focus()
		return false
	}
	else if (emailID1!==emailID2)
	{
		alert("The email addresses do not match.")
		document.getElementById('email2').value="";
		document.getElementById('email2').focus()
		return false
	}
	
		
 			
	}
	
	
	function emailValidation(str)
	{
		
		var at="@"
		var dot="."
		var apost="'"
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		//alert(lstr)
		//alert(ldot)
		//alert(lat)
		if (lstr<5){
		   //alert("Invalid E-mail ID")
		   //document.getElementById('email1').value=""
		   //document.getElementById('email2').value=""
		   return false
		  
		}
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   //document.getElementById('email1').value=""
		   //document.getElementById('email2').value=""
		   return false
		  
		}
		if (str.indexOf(apost)!=-1){
		   //alert("Invalid E-mail ID")
		   //document.getElementById('email1').value=""
		   //document.getElementById('email2').value=""
		   return false
		  
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   //document.getElementById('email1').value=""
		   //document.getElementById('email2').value=""
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   // alert("Invalid E-mail ID")
		    //document.getElementById('email1').value=""
			//document.getElementById('email2').value=""
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   // alert("Invalid E-mail ID")
		    //document.getElementById('email1').value=""
			//document.getElementById('email2').value=""
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    //document.getElementById('email1').value=""
		    //document.getElementById('email2').value=""
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   // alert("Invalid E-mail ID")
		    //document.getElementById('email1').value=""
		    //document.getElementById('email2').value=""
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   // alert("Invalid E-mail ID")
		    //document.getElementById('email1').value=""
		    //document.getElementById('email2').value=""
		    return false
		 }

 		 return true
	}
	//Added on jan 21 2009 - Sreevidya
	function isValidEmail()
	{
		
		if(emailValidation(document.getElementById('email').value))
		{
			return true;
		}
		else
		{
			alert('Enter valid email id');
			return false;
			
		}
	}
	//function isValidEmail(emailAddress) {
    //var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    //return re.test(emailAddress);
//}
