﻿// JScript File
function controlLogin()
{
    //document.getElemetById('').value
    
    //ctl00$Login1$txtUsername
    //alert(document.getElementById('ctl00_Login1_txtUsername').value)
    if(document.getElementById('ctl00_Login1_txtUsername').value=="")
    {
        alert('User Name Should Not be Blank');
        document.getElementById('ctl00_Login1_txtUsername').focus();
        return false
    }
    if(document.getElementById('ctl00_Login1_txtpassword').value=="")
    {
        alert('Password Should Not Be blank');
        document.getElementById('ctl00_Login1_txtpassword').focus();
        return false
    }
    return true
}
function addcategory()
{
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtCatName').value=="")
    {
        alert('Category Name Should Not Be blank');
        document.getElementById('ctl00_ContentPlaceHolder1_txtCatName').focus();
        return false
    }
    return true
}
function addsubcategory()
{
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtName').value=="")
    {
        alert('Category Name Should Not Be blank');
        document.getElementById('ctl00_ContentPlaceHolder1_txtName').focus();
        return false
    }
    return true
}
function Product()
{
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtProductId').value=="")
    {
        alert('Product Id Should Not Be blank');
        document.getElementById('ctl00_ContentPlaceHolder1_txtProductId').focus();
        return false
    }
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtProductName').value=="")
    {
        alert('Product Name Should Not Be blank');
        document.getElementById('ctl00_ContentPlaceHolder1_txtProductName').focus();
        return false
    }
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtProductPrice').value=="")
    {
        alert('Product Price Should Not Be blank');
        document.getElementById('ctl00_ContentPlaceHolder1_txtProductPrice').focus();
        return false
    }
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtShortDescription').value=="")
    {
        alert('Short Description Should Not Be blank');
        document.getElementById('ctl00_ContentPlaceHolder1_txtShortDescription').focus();
        return false
    }
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtBigDescription').value=="")
    {
        alert('Detail Description Should Not Be blank');
        document.getElementById('ctl00_ContentPlaceHolder1_txtBigDescription').focus();
        return false
    }
    return true
}
function Search()
{
    if(document.getElementById('ctl00_Search_product1_txtSearchProductname').value=="")
    {
        alert('Search Data Should Not Be blank');
        document.getElementById('ctl00_Search_product1_txtSearchProductname').focus();
        return false
    }
    return true
}
function NewsLetter()
{
    if(document.getElementById('ctl00_NewsLetter1_txtNewsLetterEmail').value=="")
    {
        alert('Email Should Not Be blank');
        document.getElementById('ctl00_NewsLetter1_txtNewsLetterEmail').focus();
        return false
    }
    if ((document.getElementById('ctl00_NewsLetter1_txtNewsLetterEmail').value==null)||(document.getElementById('ctl00_NewsLetter1_txtNewsLetterEmail').value=="")){
		alert("Please Enter your Email ID")
		document.getElementById('ctl00_NewsLetter1_txtNewsLetterEmail').focus()
		return false
	}
	if (echeck(document.getElementById('ctl00_NewsLetter1_txtNewsLetterEmail').value)==false){
		document.getElementById('ctl00_NewsLetter1_txtNewsLetterEmail').value=""
		document.getElementById('ctl00_NewsLetter1_txtNewsLetterEmail').focus()
		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 ValidateEmail(Arg){
//	var emailID=document.getElementById(Arg);
//	
//	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
//	}
//	return true
// }
