﻿// 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+$/,"");
}

// here field1 = name, field2 = email Id, field3 = Upload a file
function ValidateApplication(Field1, Field2, Field3)
{
    if ((document.getElementById(Field1).value == "") || (document.getElementById(Field2).value == "") || (document.getElementById(Field3).value == ""))
    {
        alert("Please Enter value in compulsory field");
        return false;
    }
    else if(!(echeck(document.getElementById(Field2).value)))
    {
        return false;
    }
    return true;
}

// To open a file as a pop up
// Any file can be opened. Just prpper path should be provided.
function openWin(openFile)
{
    window.open(openFile, "","location=0, width=515, height=350, top=100, scrollbars=yes, left=100");
}

function openDWNWin(vID)
{
    //alert(vID);
	var xVar = vID;
	if(xVar == 194)
	{
		window.open("http://www.nseindiaipo.com/issueforms/html/index.html", "","");
	}
	else
	{
		if(xVar == 196)
		{
			window.open("http://www.bseindia.com/bookbuilding/newbookbuilding.asp?scrip_cd=353&scripname=Engineers+India+Limited&status=F&ir_flag=IPO", "","");
		}
		else
		{
			window.open("Download.aspx?FId="+vID, "","location=0, width=618, height=550, top=150, scrollbars=yes, left=200");
	
		}
	}


}

//function openDWNWinTender(vID)
//{
//    window.open("DownloadTenders.aspx?FId="+vID, "","location=0, width=618, height=550, top=150, scrollbars=yes, left=200");
//}

function openDWNWinTender(openFile)
{
    window.open(openFile, "","location=0, width=618, height=550, top=150, scrollbars=yes, left=200");
}



function ValidateDWN()
{
    if (document.getElementById("txtPIN").value.trim() == "") 
    {
        alert("Please Enter PIN!");
        document.getElementById("txtPIN").focus();
        return false;
    }
    else if (document.getElementById("drpCountry").value.trim() == "") 
    {
        alert("Please Select Country!");
        document.getElementById("drpCountry").focus();
        return false;
    }
    
//    if (document.getElementById("drpCountry").value.trim() != "") 
//    {
//        ShowDisClaimer();
//    }
    
    return true;
}
  
function ShowDisClaimer()
{
    alert(document.getElementById("drpCountry").value);
    if (document.getElementById("drpCountry").value.trim() == "India") 
    {
        document.getElementById("dvDD").style.display='none';
        document.getElementById("dvDisclaimer").style.display='block';
    }
    else
    {
        document.getElementById("dvDD").style.display='block';
        document.getElementById("dvDisclaimer").style.display='none';
    }
}        
function ValidateLink(Field1, Field2)
{
    if ((document.getElementById(Field1).value == "") || (document.getElementById(Field2).value == ""))
    {
        alert("Please Enter value in compulsory field");
        return false;
    }
    return true;
}

function LoginValidate(UserName,Passward)
{
    //alert('Hi')
	if(document.getElementById(UserName).value.trim()=="" || document.getElementById(UserName).value.trim()==null)
	{
		 alert("Please Enter User Name!");
		 document.getElementById(UserName).focus();
		 return false;
	}
	else if(document.getElementById(Passward).value.trim()=="" || document.getElementById(Passward).value.trim()==null)
	{
		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_drpQualification").value.trim()=="")
	{
		 alert("Please Select Highest Qualification.!");
		 document.getElementById("UcCareerRequest1_drpQualification").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 FeedbackValidation()
{
    if(document.getElementById("txtName").value.trim()=="")
	{
		 alert("Please Enter Name!");
		 document.getElementById("txtName").focus();
		 return false;
	}
	else if(document.getElementById("txtCompany").value.trim()=="")
	{
		 alert("Please Enter Company!");
		 document.getElementById("txtCompany").focus();
		 return false;
	}
	else if(document.getElementById("txtEmail").value.trim()=="")
	{
		 alert("Please Enter Email Id!");
		 document.getElementById("txtEmail").focus();
		 return false;
	}
	
	if (document.getElementById("txtTelephone").value.trim() !="")
	{
	    if (checknumber(document.getElementById("txtTelephone").value.trim()))
	    {
	        alert("Telephone No. should be numeric!");
	        document.getElementById("txtTelephone").focus();
	        return false;
	    }
	}
	
	if (document.getElementById("txtFax").value.trim() !="")
	{
	    if (checknumber(document.getElementById("txtFax").value.trim()))
	    {
	        alert("Fax No. should be numeric!");
	        document.getElementById("txtFax").focus();
	        return false;
	    }
	}
	if(echeck(document.getElementById("txtEmail").value.trim()))
	{
	    return true;
	}
	else
	{
	    document.getElementById("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;
}

