﻿// JScript File

var whitespace = " \t\n\r";



/****************************************************************/

function replaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace(fromStr, toStr);
	}
	return new_s;
}

/****************************************************************/

function sqlSafe (s)
{
	var new_s = s;
	new_s = replaceAll (new_s, "'", "|");
	new_s = replaceAll (new_s, "|", "''");
	new_s = replaceAll (new_s, "\"", "|");
	new_s = replaceAll (new_s, "|", "''");
	return new_s;
}

/****************************************************************/

function makeSafe (i)
{
	i.value = sqlSafe (i.value);
}

/****************************************************************/

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

/****************************************************************/

function isWhitespace (s)

{

 var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}
//**********************************************************************************************************
//                             For Confirming Delete
//
//**********************************************************************************************************

    function confirm_delete()
    {
      if (confirm("Are you sure you want to delete this item?")==true)
      {
        return true;
      }
      else
      {
        return false;
      }
    }
    
//**********************************************************************************************************
//                             For Sending Mails
//
//**********************************************************************************************************

    function confirm_schedule()
    {
      if (confirm("Are you sure you want to mail schedule?")==true)
      {
        return true;
      }
      else
      {
        return false;
      }
    }
    
//**********************************************************************************************************
//                             To Recall Meetings
//
//**********************************************************************************************************

    function Recall_Meetings()
    {
      if (confirm("Are you sure you want to cancel this meeting?")==true)
      {
        return true;
      }
      else
      {
        return false;
      }
    }
    
//**********************************************************************************************************
//                             For Validating FckEditor Value
//
//**********************************************************************************************************

    function getEditorValue(objEditor, MSG)
    {
    
        // Get the editor instance that we want to interact with.
        var s = FCKeditorAPI.GetInstance(objEditor);
        s.Focus();
        if(s.GetXHTML()==""||s.GetXHTML()==null)
        {
            alert("You need to enter information for " + MSG);
            //s.focus();
            return false;            
        }
        else
        {            
            return true;
        }
    } 
    
    
    function FCKUpdateLinkedField(id)
    {
        
        try
        {
            if(typeof(FCKeditorAPI) == "object")
            {
                FCKeditorAPI.GetInstance(id).UpdateLinkedField();
            }
        }
        catch(err)
        {
        }
    }

    
//**********************************************************************************************************
//                             For Comparing Dates
//
//**********************************************************************************************************

    function CompLtDate(adate,bdate)
    {
    
        a = adate.split('/');
        b = bdate.split('/');
        var sDate = new Date(a[2],a[1],a[0]-1);
        var eDate = new Date(b[2],b[1],b[0]-1);       
        
        
        if (sDate <= eDate )
          {
            return true;
          }
       else
          {
            return false;
          }
      }
      
    function CompGtDate(adate,bdate)
    {
       a = adate.split('/');
       b = bdate.split('/');
       var sDate = new Date(a[2],a[1],a[0]-1);
       var eDate = new Date(b[2],b[1],b[0]-1);
       
       if (sDate >= eDate )
       {
            return true;
       }
       else
       {
            return false;
       }
      }
  
//**********************************************************************************************************
//                             For Validating Date Format
//
//**********************************************************************************************************

function validDate(enterdate,fieldname) 
{
	    var RegExPattern = /^(((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00|[048])))$/;

        if (enterdate.value.match(RegExPattern))
        {        
        }
        else
        {
            alert("Please enter "+ fieldname +" in dd/MM/yyyy format."); 
            enterdate.focus();
            return false;
        }
    
	return true;
}



 //**********************************************************************************************************
 //                                               For Clearing Form Fields
 //
 //**********************************************************************************************************

function Clear(frmname)
{
    for (i = 0; i < document.forms[frmname].elements.length; i++ )
    {
   
        switch(document.forms[frmname].elements[i].type)
        {
        case 'text':
            document.forms[frmname].elements[i].value = "";
            break;
        case 'textarea':
            document.forms[frmname].elements[i].value = "";
            break;
        case 'checkbox':
            document.forms[frmname].elements[i].checked = false; 
            break;
        case 'radio':
            document.forms[frmname].elements[i].checked = false; 
            break;
        case 'select-one':
            document.forms[frmname].elements[i].value = document.forms[frmname].elements[i].options[0].value;
            break;
        
        }    
    }
}
 //**********************************************************************************************************
 //                                               For Comparing Two Fields
 //
 //**********************************************************************************************************

function Compare(objField1,objField2, FieldName1, FieldName2)
{
	var strField1 =objField1.value;
	var strField2 =objField2.value;


	if(strField1==strField2)
	{
	return true;
	}
	else
	{
	alert(FieldName1+" do not match with "+FieldName2);
	objField1.value="";
	objField2.value="";
	
	objField1.focus();
	return false;
	}
	return true;
}

 //**********************************************************************************************************
 //                                For Forcing User to Enter a Value in TextBox
 //
 //**********************************************************************************************************

function ForceEntry(objField, FieldName)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) 
	{
		alert("You need to enter information for " + FieldName);
		objField.focus();
		objField.select();
		return false;
	}

	return true;
}

//**********************************************************************************************************
//                                For Forcing User to Upload Banner
//
//**********************************************************************************************************

function ForceEntry1(objField, Msg)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) 
	{
		alert(Msg);
		objField.focus();
		objField.select();
		return false;
	}

	return true;
}

function ForceListBox(objField, FieldName)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) 
	{
		alert(FieldName);
//		objField.focus();
//		objField.select();
		return false;
	}

	return true;
}	
 //**********************************************************************************************************
 //                             For Forcing User to Enter a Integer Value in TextBox
 //
 //**********************************************************************************************************

function ForceNumber(objField, FieldName)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) return true;

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}

	return true;
}

 //**********************************************************************************************************
 //                                For Forcing User to Select CheckBox
 //
 //**********************************************************************************************************

function ForceCheckBox(objField, FieldName)
{
    if(objField.checked==false)
    {   
        //alert("You need to select " + FieldName);
		objField.focus();		
		return false;
	}

	return true;
}
//**********************************************************************************************************
 //                                For Forcing User to Select CheckBox/RadioButton List
 //
 //**********************************************************************************************************
function ForceCheckBoxList(chkBox,chkList,msg)
{

 
    var rbl = chkBox;
    var rblist = chkList; 

    var cked = false;
    for(i=0;i<rblist.length;i++)
    {
        if(rblist[i].checked)
        {
            cked = true;
            break;
        }
    }
    if(cked)
    {
        
    }
    else
    {
        alert("Please select " + msg);
        return false;
        
    }
}

//**********************************************************************************************************
//                             For Forcing User to Select a DropDownList
//
//**********************************************************************************************************

function ForceCombo(objField, FieldName)
{

if ((objField.value=='----Select----')||(objField.value=='0'))
{
	alert("Please Select " + FieldName);
	objField.focus();
	return false;
}
else if(objField.value=="")
{
    alert("Please Create " + FieldName);
	objField.focus();
	return false;    
}

}
//**********************************************************************************************************
//                                               For Restricting Length of Textfield
//
//**********************************************************************************************************

function ForceLength(objField, nLength, strWarning)
{

	var strField = new String(objField.value);
	
	if (strField.length > nLength) 
	{
		alert(strWarning);
		return false;
	} else
		return true;
}
//**********************************************************************************************************
//                             For Checking EmailID
//
//**********************************************************************************************************

function isEmail(mail)
{
var email = mail.value

    invalidChars = " /:,;'\"!#&*()"
    if(email == "")
    {                 //email cannot be empty
        alert("You need to enter information for Email ID.");
        mail.focus();
        return false;         
    }

    for(i=0; i<invalidChars.length; i++){ //check for invalid characters
        badChar = invalidChars.charAt(i);
        if(email.indexOf(badChar,0) != -1)
        {
            alert("Please enter valid Email ID."); 
            mail.focus();
            return false;
        }
    }

    atPos = email.indexOf("@",1);         //there must be one "@" symbol
    if(atPos == -1)
    {
        alert("Please enter valid Email ID.");
        mail.focus();
        return false;
    }
    if(email.indexOf("@",atPos+1) != -1)
    { //check to make sure only one "@" symbol
        alert("Please enter valid Email ID.");
        mail.focus();
        return false;
    }

    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1)
    { // make sure there is one "." after the "@"
        alert("Please enter valid Email ID.");
        mail.focus();
        return false;
    }

    if(periodPos+3 > email.length)
    { // must be at least 2 chars after the "."
        alert("Please enter valid Email ID.");
        mail.focus();
        return false;
    }
    return true;
}

//**********************************************************************************************************
//                             For Validating Time
//
//**********************************************************************************************************

function validateTime(entertime,fieldname) 
{  

	var RegExPattern = /^(20|21|22|23|[01]\d|\d)(([:][0-5]\d){1,2})$/;
    if (entertime.value.match(RegExPattern))
    {        
    }
    else
    {
        alert("Please enter "+ fieldname +" in 24hr Format."); 
        entertime.focus();
        return false;
    }
    
	return true;
}


//**********************************************************************************************************
//                                       For Comparing Time
//
//**********************************************************************************************************

function compareTime(enterTime,CompareWith,opt,msg) 
{  
   
    if(opt=='lt')
    {           
	    if(enterTime.value < CompareWith.value)
        {
            alert(msg);
            enterTime.focus();
            return false;
        }
    }
    else if(opt=='gt')
    {
        if(enterTime.value > CompareWith.value)
        {
            alert(msg);
            enterTime.focus();
            return false;
        }
        
    }	
    
	return true;
}



//**********************************************************************************************************
//                             For Validating Phone Number
//
//**********************************************************************************************************

function validatePhone(objField1,fieldname) 
{  

	
	if(objField1.value=="")
	{
	    alert("You need to enter information for " + fieldname);
	    objField1.value="";
	    objField1.focus();
	    return false;	
	}
	else
	{
        
	    var RegExPattern = /^(\([0-9]|[0-9])(\d{2}|\d{2}\))(-|.|\s)?\d{3}(-|.|\s)?\d{4}$/;
        if (objField1.value.match(RegExPattern))
        {        
        }
        else
        {
            alert("Please enter valid " + fieldname); 
            objField1.value="";
            objField1.focus();
            return false;
        }
	}
    
	return true;
}








