﻿// JScript File

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
var Phonechars =  phoneNumberDelimiters + "+";

var strError;
var reInteger = /^\d+$/
/// Msg Box:================
var txt1;
function Msg(txt) { 
txt1=txt;
alert(txt); 
} 


function EnDis(obj) 
{ 
document.getElementById(obj).enabled=false;
document.getElementById(obj).value = "Wait..."; 
} 

//=====================

function dt(obj)
{
    if (obj.length==2)
    {
    obj.value=obj.value + "/";
    obj.focus();
   
    }
    else if (obj.length==5)
    {
    obj.value=obj.value + "/";
    obj.focus();
       }
  }
   
  // Remove Items from List Box
  function deleteitem(obj)
  {
    var ind;
    ind=document.getElementById(obj).selectedIndex;
    if (ind>=0)
    {
        if (confirm('Are you sure to delete selected element?')==true)
        {
        document.getElementById(obj).remove(ind);
        document.getElementById(obj).refresh();
        }
    }
   }
  
  
    function cdata()
    {
    if (confirm('Are you sure?')==true)
    //obj.value="Ok";
      document.getElementById("hf").value="Ok";
    else
    //obj.value="No";
        document.getElementById("hf").value="No";
    }
    
    function cont()
    {
    if (confirm('MSR DCR has been saved!\nDo you want to continue for another one DCR ?')==true)
          //document.getElementById("ms").value="Ok";
          location.href="dcrmsrdcrentry.aspx";
          
    else
            //document.getElementById("ms").value="No";
             location.href="dcrmastermenu.aspx";
    }
    function loadPage(msg,pagename)
    {
    if (confirm(msg)==true)
          //document.getElementById("ms").value="Ok";
          location.href=pagename;
          
    else
            //document.getElementById("ms").value="No";
             location.href=pagename;
    }

function select(Obj)
    {
    document.dcrchemistmaster.Obj.select();
    }

function isSelected(objControl, strCaption)
{
    strError = ""; 
    if(objControl.selectedIndex == -1 || objControl.selectedIndex == -0)
    {
        strError = "Please select " + strCaption;
    }
    return strError;
}


function timeformat(e)
{
    if (!((e.keyCode>=48 && e.keyCode<=57) || (e.keyCode==58) || (e.keyCode==32) || (e.keyCode==65) || (e.keyCode==97) || (e.keyCode==77) || (e.keyCode==109) || (e.keyCode==80) || (e.keyCode==112)))
    {
        e.returnValue=false;
    }
}


function checkcolon(e)
{
    if (e.keyCode==39)
    {
    e.returnValue=false;
    }
}
// Only number etnry where only number is required//
function numonly(e)
{
    if (!(e.keyCode>=48 && e.keyCode<=57))
    {
    e.returnValue=false;
    }
}

function numonlyRs(e)
{
    if (!((e.keyCode>=48 && e.keyCode<=57)||(e.keyCode==46)))
    {
    e.returnValue=false;
    }
}

function onlydate(e)
{
    if (!(e.keyCode>=47 && e.keyCode<=57))
    {
    e.returnValue=false;
    }
}
function gridcolumn(e)
{
    if (!((e.keyCode>=48 && e.keyCode<=57)||(e.keyCode==44)))
    {
    e.returnValue=false;
    }
}

function onlyDouble(e)
{
    if (!((e.keyCode>=48 && e.keyCode<=57) || (e.keyCode==46)))
    {
    e.returnValue=false;
    }
}
function disableEnter(e)
{
    if (e.keyCode==13)
    {
    e.returnValue=false;
    }
}


/////////////////////////////////////////////////////
//function checkColon(e)
//{
//if (!((e.keyCode>=0 && e.keyCode<=38)||(e.keyCode>=40)))
//{
// e.return=false;   
//}
//}


function SetErrorLabel(controlID,strError)
{
	var lblError = document.getElementById(controlID);
	lblError.innerHTML = strError;
}

function isEmpty(objControl)
{
    var strValue = Trim(objControl.value);
    if(strValue !="")
    {
        return true;
    }
    return false;
}

function isEmailID(objControl)
{
	strError = "";
	var strValue;
	strValue = objControl.value;
	reg = new RegExp("^([\\w-]{1}[\\w-\\'\\.]{1,50})@((([\\w-]{3,50}\\.){1}))(([a-zA-Z]{2,4})|(([a-zA-Z]{2,4})\\.([a-zA-Z]{2})))$");
	if(reg.test(strValue) == false)
	{
	    return false;
	}
	return true;
}

function isValidAge(objControl)
{
    strError = "";
    var strValue;
    strValue = objControl.value;
    reg = new RegExp("^[1-9]{1}[0-9]{0,2}$");
    if(reg.test(strValue) == false)
    {
        strError = "Age is invalid ";
    }
    return strError;
}

function isValidCountry(objControl)
{
    strError = "";
    var strValue;
    strValue = objControl.value;
    reg = new RegExp("^[A-Za-z]{1,20}$");
    if(reg.test(strValue) == false)
    {
        strError = "Country is invalid ";
    }
    return strError;
}

function isValidLength(objControl, intMinLength, intMaxLength)
{
	strError = "";
	if (objControl.value.length >= intMinLength && objControl.value.length <= intMaxLength )
	{
		strError = "";
	}
	else
	{
		strError = "Message is more than specified limit. ";
	}
	return strError;
	
}

function ValidEmail(Email)
{
	var l_Email=Email;		
	if(Email.slice(0,1)== "@")
	{
		return(false);
	}
						
	if(Email.search("@") >= 0)
	{
		l_Email=Email.slice(Email.indexOf("@")+1,Email.length)
		if(l_Email.search("@") >= 0)
		{
			return(false);
		}
	}
	else
	{
		return(false);
	}	
	//Searching for "." string
	if(Email.indexOf(".") > 0)
	{
		if(Email.slice(Email.indexOf(".")+1,Email.indexOf(".")+2)== ".")
		{
			return(false);
		}
			
		if(Email.slice(Email.length-1,Email.length)== "." || Email.slice(0,1)== ".")
		{
			return(false);
		}
		else
		{
			return(true);
		}
	}
	else
	{
		return(false);
	}
}

function isValidPhone(objControl)
{
    strError = "";
    var strValue;
    strValue = objControl.value;
    reg = new RegExp("^[0-9]{1}[0-9]{0,14}$");
    if(reg.test(strValue) == false)
    {
        return false;
    }
    return true;
}

function isDigit(objControl)
{
    var strValue;
    strValue = objControl.value;
    reg = new RegExp("^[1-9]{1}[0-9]*$");
    if(reg.test(strValue) == false)
    {
        return false;
    }
    return true;
   
}

function isValidContestName(objControl)
{
	var strValue = objControl.value;
	reg = new RegExp("^[a-zA-Z ]{2,30}$");
	if(reg.test(strValue) == false)
	{
		return false;
	}
    return true;
}

function isFloat(objControl)
{
	var strValue = objControl.value;
	reg = new RegExp("^[0-9]*[.]{0,1}[0-9]+$");
	if(reg.test(strValue) == false)
	{
		return false;
	}
    return true;
}

function isDateCal(objControl)
{
    strError = "";
    var strValue;
    strValue = objControl.value;
    reg = new RegExp("^[0-9]{2}[-]{1}[0-9]{2}[-]{1}[0-9]{4}$");
    if(reg.test(strValue) == false)
    {
        return false;
    }
    return true;
}

//function trim(inputString)
//{    
//	// Removes leading and trailing spaces from the passed string. Also removes
//	// consecutive spaces and replaces it with one space. If something besides
//	// a string is passed in (null, custom object, etc.) then return the input.	
//	if (typeof inputString != "string") { return inputString; }
//	var retValue = inputString;
//	var ch = retValue.substring(0, 1);
//	while (ch == " ") { // Check for spaces at the beginning of the string
//		retValue = retValue.substring(1, retValue.length);
//		ch = retValue.substring(0, 1);
//	}
//	ch = retValue.substring(retValue.length-1, retValue.length);
//	while (ch == " ") { // Check for spaces at the end of the string
//		retValue = retValue.substring(0, retValue.length-1);
//		ch = retValue.substring(retValue.length-1, retValue.length);
//	}
//	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
//		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
//	}
//	return retValue; // Return the trimmed string back to the user

//} // Ends the "trim" function



function isPhoneFax(sText)
{
		var ValidChars ="0123456789-/,";
		var IsNum=true;
		var Ch;
		for(i=0; i<sText.length; i++)
		{
			Ch=sText.charAt(i);
			if(ValidChars.indexOf(Ch) == -1)
			{
				IsNum = false;
			}
		}
		return IsNum;
}

function iswebsiteName(objControl)
{
    strError = "";
    var strValue;
    strValue = objControl.value;
     reg = new RegExp("^http://www.[a-zA-Z0-9]+.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|co.uk|fr|ch|ac.uk|ox.ac.uk|se|co.in|cam.ac.uk|city.ac.uk|nl|it|nyu.edu|mobi)$");
    if(reg.test(strValue) == false)
    {
        return false;
    }
    return true;
}

function isHostName(objControl)
{
	strError = "";
	var strValue = objControl.value;
	reg = new RegExp("^(?!http|www|https|ftp|HTTP|FTP|WWW|HTTPS)+([a-zA-Z0-9]+([-]{0,1}[a-zA-Z0-9])*)[.]{1}[a-zA-Z]{1,5}(([.]{1}[a-zA-Z]{1,3})*)$");
	if(reg.test(strValue) == true)
	{
		return true;
	}
	return false;
}

function isURL(objControl)
{ 
	strError = "";
	var strValue = objControl.value;
	
	//reg = new RegExp("^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|nyu.edu)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$");
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	if(regexp.test(strValue) == false)
	{
		return false;
	}
	return true;
}

function LTrim(strTrimStr)
{
 var intTotLen = strTrimStr.length;
    var strWhtSpcs = new String(" \t\n\r");
    var strCpyStr = new String(strTrimStr);

    if (strWhtSpcs.indexOf(strCpyStr.charAt(0)) != -1)
    {
        var intjCtr=0, intiCtr = strCpyStr.length;

        while (intjCtr < intiCtr && strWhtSpcs.indexOf(strCpyStr.charAt(intjCtr)) != -1)
         intjCtr++;
        strCpyStr = strCpyStr.substring(intjCtr, intTotLen);
    }
    return strCpyStr;
}


function RTrim(strTrimStr)
{
 var intTotLen = strTrimStr.length;
    var strWhtSpcs = new String(" \t\n\r");
    var strCpyStr = new String(strTrimStr);

    if (strWhtSpcs.indexOf(strCpyStr.charAt(intTotLen-1)) != -1)
    {
        var intiCtr = intTotLen-1;

        while (intiCtr >= 0 && strWhtSpcs.indexOf(strCpyStr.charAt(intiCtr)) != -1)
                        intiCtr--;

        strCpyStr = strCpyStr.substring(0, intiCtr+1);
    }
    return strCpyStr;
}
function Trim(pstrTrimStr)
{
    return RTrim(LTrim(pstrTrimStr));
}


// Disable Function Key F5
function DisableF5()
{
if (window.event.keyCode==116){
    alert("Dont press F5");
    return false;   
    }
}


/// Enable and Disable the Button while Clicking
////function DisableControl(controlId)
////{
////  document.getElementById(controlId).disabled =true;
////}
//// 
////function DisableControl_SetTimeout(controlId,interval)
////{
////  setTimeout("DisableControl('" +controlId + "')",interval);
////}
//// 
////function btn_Click(control)
////{
////  DisableControl_SetTimeout(control.id,100);
////}

////    var pwin;
////    function newwin(){
////    pwin=window.open("pps/wpmshelp.pps","Test", "width=300,height=300");
////    if (pwin.open)
////    {
////    pwin.close;
////    }
////    pwin.focus();
////    }
////    </script>

function limitCharsLength(Object, MaxLen)

{

if(Object.value.length > (MaxLen-1))

 {

    return false;   

 }

}




