﻿// JScript File

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function ValidateSubscribe()
{
    if(document.getElementById("txtSubMain").value.trim()=="Enter your email ID here…")
	{
		 alert("Please Enter enter your email Id!");
		 document.getElementById("txtSubMain").focus();
		 return false;
	}
    else if(document.getElementById("txtSubMain").value.trim()=="")
	{
		 alert("Please Enter enter your email Id!");
		 document.getElementById("txtSubMain").focus();
		 return false;
	}
	else if(document.getElementById("chkNAV").checked==false && document.getElementById("chkFact").checked==false && document.getElementById("chkNAFO").checked==false && document.getElementById("chkNEWS").checked==false && document.getElementById("chkProducts").checked==false && document.getElementById("chkOthers").checked==false)
	{
	     alert("Please select atleast one option for Subscribe!");
		 document.getElementById("chkNAV").focus();
		 return false;
	}
	
	if(echeck(document.getElementById("txtSubMain").value.trim()))
	{
	    return true;
	}
	else
	{
	    document.getElementById("txtSubMain").focus();
	    return false;
	}
	
	return true;
}

function LoginValidate(UserName,Passward)
{
    //alert('Hi')
	if(document.getElementById(UserName).value.trim()=="")
	{
		 alert("Please Enter User Name!");
		 document.getElementById(UserName).focus();
		 return false;
	}
	else if(document.getElementById(Passward).value.trim()=="")
	{
		alert("Please Enter Password!");
		document.getElementById(Passward).focus();
		return false;
	}
	return true;	
}

function CareerValidation()
{
    if(document.getElementById("UcCareerRequest1_txtName").value.trim()=="")
	{
		 alert("Please Enter Name!");
		 document.getElementById("UcCareerRequest1_txtName").focus();
		 return false;
	}
	else if(document.getElementById("UcCareerRequest1_txtTelephone").value.trim()=="")
	{
		 alert("Please Enter Contact No.!");
		 document.getElementById("UcCareerRequest1_txtTelephone").focus();
		 return false;
	}
	else if(document.getElementById("UcCareerRequest1_txtEmailId").value.trim()=="")
	{
		 alert("Please Enter Email Id!");
		 document.getElementById("UcCareerRequest1_txtEmailId").focus();
		 return false;
	}
	else if(document.getElementById("UcCareerRequest1_txtQualification").value.trim()=="")
	{
		 alert("Please Enter Qualification.!");
		 document.getElementById("UcCareerRequest1_txtQualification").focus();
		 return false;
	}
	
	if (document.getElementById("UcCareerRequest1_txtTelephone").value.trim() !="")
	{
	    if (checknumber(document.getElementById("UcCareerRequest1_txtTelephone").value.trim()))
	    {
	        alert("Contact No. should be numeric!");
	        document.getElementById("UcCareerRequest1_txtTelephone").focus();
	        return false;
	    }
	}
	
	if(echeck(document.getElementById("UcCareerRequest1_txtEmailId").value.trim()))
	{
	    return true;
	}
	else
	{
	    document.getElementById("UcCareerRequest1_txtEmailId").focus();
	    return false;
	}
	
	return true;
}

function NAVSubscribe()
{
    if(document.getElementById("txtName").value.trim()=="")
	{
		 alert("Please Enter Name!");
		 document.getElementById("txtName").focus();
		 return false;
	}
	else if(document.getElementById("txtEmail").value.trim()=="")
	{
		 alert("Please Enter Email Id!");
		 document.getElementById("txtEmail").focus();
		 return false;
	}
	if(echeck(document.getElementById("txtEmail").value.trim()))
	{
	    return true;
	}
	else
	{
	    document.getElementById("txtEmail").focus();
	    return false;
	}
	
	return true;
}

function Grievance()
{
    if(document.getElementById("UcGrievance1_txtName").value.trim()=="")
	{
		 alert("Please Enter Name!");
		 document.getElementById("UcGrievance1_txtName").focus();
		 return false;
	}
	
	else if(document.getElementById("UcGrievance1_txtContact").value.trim()=="")
	{
		 alert("Please Enter Contact No.!");
		 document.getElementById("UcGrievance1_txtContact").focus();
		 return false;
	}
	else if(document.getElementById("UcGrievance1_txtEmail").value.trim()=="")
	{
		 alert("Please Enter Email Id!");
		 document.getElementById("UcGrievance1_txtEmail").focus();
		 return false;
	}
	else if(document.getElementById("UcGrievance1_txtComplain").value.trim()=="")
	{
	      alert("Please Enter Complain!");
	      document.getElementById("UcGrievance1_txtComplain").focus();
	      return false;
	}
	
	if (document.getElementById("UcGrievance1_txtContact").value.trim() !="")
	{
	    if (checknumber(document.getElementById("UcGrievance1_txtContact").value.trim()))
	    {
	        alert("Contact No. should be numeric!");
	        document.getElementById("UcGrievance1_txtContact").focus();
	        return false;
	    }
	}
	
	if(echeck(document.getElementById("UcGrievance1_txtEmail").value.trim()))
	{
	    return true;
	}
	else
	{
	    document.getElementById("UcGrievance1_txtEmail").focus();
	    return false;
	}
	
	return true;
	

}


function FeedbackValidation()
{
    if(document.getElementById("UcFeedback1_txtName").value.trim()=="")
	{
		 alert("Please Enter Name!");
		 document.getElementById("UcFeedback1_txtName").focus();
		 return false;
	}
	else if(document.getElementById("UcFeedback1_txtContact").value.trim()=="")
	{
		 alert("Please Enter Contact No.!");
		 document.getElementById("UcFeedback1_txtContact").focus();
		 return false;
	}
	else if(document.getElementById("UcFeedback1_txtEmail").value.trim()=="")
	{
		 alert("Please Enter Email Id!");
		 document.getElementById("UcFeedback1_txtEmail").focus();
		 return false;
	}
	
	if (document.getElementById("UcFeedback1_txtContact").value.trim() !="")
	{
	    if (checknumber(document.getElementById("UcFeedback1_txtContact").value.trim()))
	    {
	        alert("Contact No. should be numeric!");
	        document.getElementById("UcFeedback1_txtContact").focus();
	        return false;
	    }
	}
	
	if(echeck(document.getElementById("UcFeedback1_txtEmail").value.trim()))
	{
	    return true;
	}
	else
	{
	    document.getElementById("UcFeedback1_txtEmail").focus();
	    return false;
	}
	
	return true;
}

function EnquiryValidation()
{
    if(document.getElementById("UcEnquiry1_txtName").value.trim()=="")
	{
		 alert("Please Enter Name!");
		 document.getElementById("UcEnquiry1_txtName").focus();
		 return false;
	}
	else if(document.getElementById("UcEnquiry1_txtContact").value.trim()=="")
	{
		 alert("Please Enter Contact No.!");
		 document.getElementById("UcEnquiry1_txtContact").focus();
		 return false;
	}
	else if(document.getElementById("UcEnquiry1_txtEmail").value.trim()=="")
	{
		 alert("Please Enter Email Id!");
		 document.getElementById("UcEnquiry1_txtEmail").focus();
		 return false;
	}
	else if(document.getElementById("UcEnquiry1_drpEnquiryAbout").value.trim()=="")
	{
		 alert(" Please Select Enqury About.!");
		 document.getElementById("UcEnquiry1_drpEnquiryAbout").focus();
		 return false;
	}
	
	if (document.getElementById("UcEnquiry1_txtContact").value.trim() !="")
	{
	    if (checknumber(document.getElementById("UcEnquiry1_txtContact").value.trim()))
	    {
	        alert("Contact No. should be numeric!");
	        document.getElementById("UcEnquiry1_txtContact").focus();
	        return false;
	    }
	}
	
	if(echeck(document.getElementById("UcEnquiry1_txtEmail").value.trim()))
	{
	    return true;
	}
	else
	{
	    document.getElementById("UcEnquiry1_txtEmail").focus();
	    return false;
	}
	
	return true;
}


//*****End Of Menu***************************************

function  ShowGraphDiv(vDivId)
{
	HideAll();
	obj = document.getElementById(vDivId);
	obj.style.display = "block";
}

function HideAll()
{
	var i;
	var divs = document.getElementById("MyDiv").getElementsByTagName("div");
	for(i = 0; i < divs.length; i++)
	{
	    divs[i].style.display = "none";
	}
}

//==============================================================================================



function checknumber_OLD(vSTR)
{
    var anum=/(^\d+$)|(^\d+\.\d+$)/
    if (anum.test(vSTR))
        testresult=false;
    else
    {
        testresult=true;
    }
        return testresult;
}

function checknumber(vSTR)
    {
        var stripped =vSTR.replace(/([0-9\-\+\.\(\)]+)/,'')
        stripped =stripped.replace(/([0-9\-\+\.\(\)]+)/,'')
        //alert(stripped)
        
        if (isNaN(parseInt(stripped)))
        {
            if(stripped=="")
            {
                testresult=false;
            }
            else
            {
                testresult=true;
            }
        }
        else
        {
            testresult=false;
        }
            return testresult;
    }

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 Email ID!")
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid Email ID!")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr-1)
		{
		    alert("Invalid Email ID!")
		    return false;
		}
    	if (str.indexOf(at,(lat+1))!=-1)
		{
		   alert("Invalid Email ID!")
		   return false;
		}

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		{
		   alert("Invalid Email ID!")
		   return false;
		}

		if (str.indexOf(dot,(lat+2))==-1)
		{
		   alert("Invalid Email ID!")
		   return false;
		}
		if (str.indexOf(" ")!=-1)
		{
		   alert("Invalid Email ID!")
		   return false;
		}
		return true;
}
