﻿String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

//open the link new window(used for show attachment)
function OpenAttachment(strLink)
{
    var winH = screen.availHeight - 32;
    var winW = screen.availWidth - 10;
    window.open(strLink, 'frmAttachment', 'width=' + winW + ',height=' + winH + ',resizable=yes,value=top,toolbar=no,scrollbars=no,top=1,left=1');
}

//Delete record confirmation
function CMTDeleteRowConfirmation()
{
    if(confirm("Are you sure to delete this record?")==true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//Check only numeric value including dot(.)
function CMTChecknumber(vSTR)
{
    var anum=/(^\d+$)|(^\d+\.\d+$)/
    if (anum.test(vSTR))
        testresult=false;
    else
    {
        testresult=true;
    }
        return testresult;
}

//Check valid phone number. With 0-9 , +,-,.,(,)symblos.
function CMTCheckPhoneNumber(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;
    }

//Check valid EmailId
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)
		{
		   document.getElementById("validmsg").innerHTML="Invalid Email ID!"
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   document.getElementById("validmsg").innerHTML="Invalid Email ID!"
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr-1)
		{
		    document.getElementById("validmsg").innerHTML="Invalid Email ID!"
		    return false;
		}
    	if (str.indexOf(at,(lat+1))!=-1)
		{
		   document.getElementById("validmsg").innerHTML="Invalid Email ID!"
		   return false;
		}

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		{
		   document.getElementById("validmsg").innerHTML="Invalid Email ID!"
		   return false;
		}

		if (str.indexOf(dot,(lat+2))==-1)
		{
		   document.getElementById("validmsg").innerHTML="Invalid Email ID!"
		   return false;
		}
		if (str.indexOf(" ")!=-1)
		{
		   document.getElementById("validmsg").innerHTML="Invalid Email ID!"
		   return false;
		}
		return true;
}


//Gridview All Chekbox Check

  function SelectAll(id,grd,cellno)
        {
       
            //get reference of GridView control
            var grid = document.getElementById(grd);
            //variable to contain the cell of the grid
            var cell;
            
            if (grid.rows.length > 0)
            {
                //loop starts from 1. rows[0] points to the header.
                for (i=1; i<grid.rows.length; i++)
                {
                    //get the reference of first column
                    cell = grid.rows[i].cells[Number(cellno)];
                    
                    //loop according to the number of childNodes in the cell
                    for (j=0; j<cell.childNodes.length; j++)
                    {           
                        //if childNode type is CheckBox                 
                        if (cell.childNodes[j].type =="checkbox")
                        {
                        //assign the status of the Select All checkbox to the cell checkbox within the grid
                            cell.childNodes[j].checked = document.getElementById(id).checked;
                        }
                    }
                }
            }
        }
