﻿// JScript File
var MasterID='ctl00_ContentPlaceHolder1_';
function validateMagazine()
{
    if(window.document.getElementById(MasterID+'txtNumberOfPages').value=='')
    {
        alert('Please enter Number of Pages');
        window.document.getElementById(MasterID+'txtNumberOfPages').focus();
        return false;
    }
     if(window.document.getElementById(MasterID+'drpMonth').value=='0')
    {
        alert('Please enter month');
        window.document.getElementById(MasterID+'drpMonth').focus();
        return false;
    }
    
    if(window.document.getElementById(MasterID+'txtDescription').value=='')
    {
        alert('Please enter description');
        window.document.getElementById(MasterID+'txtDescription').focus();
        return false;
    }
}

function chkNumeric(comp)
{
	if(isNaN(comp.value))
	{
		alert("Please enter a number. Do not use literals/characters");			
		comp.focus();
		comp.value='';
		return false;
	} 
	return true;					
}

function validateContactus()
{
    if(window.document.getElementById(MasterID+'txtName').value=='')
    {
        alert("Please enter name");
        window.document.getElementById(MasterID+'txtName').focus();
        return false;
        
    }
    if(window.document.getElementById(MasterID+'txtEmail').value=='')
    {
        alert("Please enter email");
        window.document.getElementById(MasterID+'txtEmail').focus();
        return false;
        
    }
    if(window.document.getElementById(MasterID+'txtMessage').value=='')
    {
        alert("Please enter message");
        window.document.getElementById(MasterID+'txtMessage').focus();
        return false;
        
    }
}

function validateEmail(comp)
	{
		var txt,ntxt,i,flg,dot;
		flg=false;
		dot=false;
		ntxt=comp.value;
		txt="";
		
		// Checking if there is value in the Email Id
		if(ntxt!="")
		{	
			for(i=0;i<parseInt(ntxt.length);i++)
			{
				if(ntxt.charAt(i)!=" ") 
				{
					// The code is commented for future references
					//alert(ntxt.charCodeAt(i) + " : " + ntxt.charAt(i));
					
					// Checking if the Email Id is alphanumeric or alphabet
					if((ntxt.charCodeAt(i)>=65 && ntxt.charCodeAt(i)<=90) || (ntxt.charCodeAt(i)>=97 && ntxt.charCodeAt(i)<=122))
					{ 	
						txt=txt+ntxt.charAt(i).toLowerCase();
					}
					// Display a message and set the focus on it if the Email Id is Invalid
					else if(ntxt.charCodeAt(i)==32)
					{
						alert("Invalid email id");
						comp.value="";
						comp.focus();
						return;
					}
					else
					{	
						txt=txt+ntxt.charAt(i);
					}
				}
			}
		
			var txtarr=txt.split("@");
			// The code is commented for future references
			//alert(txtarr.length);
			if(txtarr.length == 2 )
			{
				if(txtarr[1]!="")
				{
					var ntxtarr=txtarr[1].split(".");
					
					if(ntxtarr.length>1)
					{
						var lastDotIndex=ntxtarr.length-1;					  
						for(i=lastDotIndex;i<ntxtarr.length;i++)
						{
							// The code is commented for future references
							//alert("len : " + ntxtarr[i].length + " , val : " + ntxtarr[i]);
							if(ntxtarr[i].length>3 || ntxtarr[i].length<2)
							{
								alert("Invalid email id");
								comp.value="";
								comp.focus();
								return;
							}
						}
					}
					else
					{					
						alert("Invalid email id");
						comp.value="";
						comp.focus();
						return;
					}
				}
				else
				{
					alert("Invalid email id");
					comp.value="";
					comp.focus();
					return;
				}
			}
			else
			{
				alert("Invalid email id");
				comp.value="";
				comp.focus();
				return;
			}
			comp.value=txt;
		}
}
function validateSubscribe()
{
    if(window.document.getElementById(MasterID+'txtName').value=='')
    {
        alert("Please enter name");
        window.document.getElementById(MasterID+'txtName').focus();
        return false;
        
    }
    if(window.document.getElementById(MasterID+'txtUserName').value=='')
    {
        alert("Please enter username");
        window.document.getElementById(MasterID+'txtUserName').focus();
        return false;
        
    }
    if(window.document.getElementById(MasterID+'txtPassword').value=='')
    {
        alert("Please enter password");
        window.document.getElementById(MasterID+'txtPassword').focus();
        return false;
        
    }  
     if(window.document.getElementById(MasterID+'txtConfirmPassword').value=='')
    {
        alert("Please enter confirm password");
        window.document.getElementById(MasterID+'txtConfirmPassword').focus();
        return false;
        
    } 
    if(window.document.getElementById(MasterID+'txtPassword').value!=window.document.getElementById(MasterID+'txtConfirmPassword').value)
    {
        alert("Password and confirm password should be same.");        
        window.document.getElementById(MasterID+'txtConfirmPassword').focus();
        return false;
        
    } 
    
    if(window.document.getElementById(MasterID+'drpIntrest').value=='0')
    {
        alert("Please select  confirm Area of Intrest");
        window.document.getElementById(MasterID+'drpIntrest').focus();
        return false;
        
    } 
    if(window.document.getElementById(MasterID+'txtEmail').value=='')
    {
        alert("Please enter confirm email.");
        window.document.getElementById(MasterID+'txtEmail').focus();
        return false;
        
    } 
     
}

function validateLogin()
{
    if(window.document.getElementById(MasterID+'txtUsername').value=='')
    {
        alert("Please enter username.");
        window.document.getElementById(MasterID+'txtUsername').focus();
        return false;        
    } 
    if(window.document.getElementById(MasterID+'txtPassword').value=='')
    {
        alert("Please enter password");        
        window.document.getElementById(MasterID+'txtPassword').focus();
        return false;        
    } 
}

function clearLogin()
{
    window.document.getElementById(MasterID+'txtUsername').value='';
    window.document.getElementById(MasterID+'txtPassword').value='';
    return false;
    
}
function clearSubscribe()
{

    window.document.getElementById(MasterID+'txtName').value='';
    window.document.getElementById(MasterID+'txtUserName').value='';
    window.document.getElementById(MasterID+'txtPassword').value='';
    window.document.getElementById(MasterID+'txtConfirmPassword').value='';
    window.document.getElementById(MasterID+'txtDesignation').value='';
    window.document.getElementById(MasterID+'drpIntrest').selectedIndex=0;
    window.document.getElementById(MasterID+'txtWorkSector').value='';
    window.document.getElementById(MasterID+'txtEmail').value='';
    window.document.getElementById(MasterID+'txtTel').value='';
    return false;
}
function clearRegistration()
{
    window.document.getElementById(MasterID+'txtName').value='';
    window.document.getElementById(MasterID+'txtUserName').value='';
    window.document.getElementById(MasterID+'txtPassword').value='';
    window.document.getElementById(MasterID+'txtConfirmPassword').value='';
    window.document.getElementById(MasterID+'txtDesignation').value='';
    window.document.getElementById(MasterID+'drpIntrest').selectedIndex=0;
    window.document.getElementById(MasterID+'txtWorkSector').value='';
    window.document.getElementById(MasterID+'txtEmail').value='';
    window.document.getElementById(MasterID+'txtTel').value='';
    return false;
   
}
function clearContactus()
{
    window.document.getElementById(MasterID+'txtName').value='';
    window.document.getElementById(MasterID+'txtEmail').value='';
    window.document.getElementById(MasterID+'txtMessage').value='';
}
