﻿function fnShowExpertsList()
{
    var expertID=document.getElementById("ctl00$ContentPlaceHolder1$hidExpertID").value;
    alert(expertID);
    var strURL="admin-expert-list.aspx?expertID=" +expertID;
    window.open(strURL, null,'height=600,width=800,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
    //fnOpenWindow(strURL);
}


   
function fnCallParentFunction()
{
   alert("Called FGunctoin");
    var obj=document.getElementById("chkExpert");
    var strText;
    var strExpertID;
    alert(obj);
    alert(obj[i].checked);
    
    for (var i=0; i < obj.length; i++)
       {
           if (obj[i].checked)
           {
               strText = obj[i].text;
               strExpertID=obj[i].value;
               break;
           }
       }

    //var strText=obj.options[obj.selectedIndex].text;
    //var strExpertID=obj.options[obj.selectedIndex].value;
    alert(strText+ " , " + strExpertID);
    //window.opener.fnSetExpertID(strText,strExpertID);
    //window.close();
}
function fnSetExpertID(strText,strExpertID)
{
     var objExpertID=document.getElementById("ctl00$ContentPlaceHolder1$hidExpertID");
     var objExpertName=document.getElementById("ctl00$ContentPlaceHolder1$hidExpertID");
     objExpertID.value=strExpertID;
     objExpertName.value=strText;
}

// JScript File
// Removes leading and ending whitespaces
function trim(value)
{
    return LTrim(RTrim(value));
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

function fnCheckddlvalue(controlID,strvalue,strName)
{
    
    if(strvalue != "0")
    {
        document.getElementById(controlID).style.backgroundColor = "white";
        return true;
    }    
    else
    {
        var control=document.getElementById(controlID)
        control.style.backgroundColor = "#cad7ec";
        //control.focus();
        strMessage=strMessage +"\n----" + strName;  
       
        return false;
    }
}

//Rakesh on 08-09-2008
function fnCheckListBoxValue(controlID,strvalue,strName)
{
    
    if(strvalue != "")
    {
        document.getElementById(controlID).style.backgroundColor = "white";
        return true;
    }    
    else
    {
        var control=document.getElementById(controlID)
        control.style.backgroundColor = "#cad7ec";
        //control.focus();
        strMessage=strMessage +"\n----" + strName;         
        return false;
    }
}
//Rakesh wrk end

function fnCheckInput(controlID,strValue,strType,strName,mand)
       {
      strValue =trim(strValue);
        var blncheck="1";  
      
        if(mand=="1")
        {
          
            if(strValue=="")
            {
                blncheck="0" 
            }
        }
        
        //check password
        if(mand=="2")
        {
          
            if(strValue=="")
            {
                blncheck="0" 
            }
        }
        
        if(strType=="alpha")
        {
            if(alphaNumericCheck(strValue)==false)
            {   
                 blncheck="0" ;
             
            }
        }
        if(strType=="alphaOnly")
        {
            if(alphaOnly(strValue)==false)
            {   
                 blncheck="0" ;
             
            }
        }
        
        if(strType=="alphanumericwithspaces")
        {
            if(alphaNumericCheckWithSpaces(strValue)==false)
            {   
                 blncheck="0" ;
             
            }
        }
        
        
        //check string 
        if(strType=="string")
        {
            if(checkString(strValue)==false)
            {
               blncheck="0"
            }
       }

        //check integer
        if(strType=="integer")
        {
        if(checkNumber(strValue)==false)
            {
               blncheck="0";
            }
        }
        
          if(strType=="decimal")
        {
        if(checkDecimal(strValue)==false)
            {
               blncheck="0";
            }
        }

        //chevk std

        if(strType=="std")
        {
            
            if(fnCheckSTDCode(strValue)==false)
            {
                blncheck="0";
            }
       }
       //Change Begin
       //Code added to validate STD Code for India by Vikash Kumar on 18 May, 2007
       
        if(strType=="stdcode")
        {
            
            if(fnCheckSTD(strValue)==false)
            {
                blncheck="0";
            }
       }
       
       //Chage End

        //check email
        if(strType=="email")
        {
            if(checkMail(strValue)==false)
            {
               blncheck="0";
          }
       }
        if(strType=="time")
        {
            if(checkTime(strValue)==false)
            {
               blncheck="0";
          }
       }
       //Change by Anjali
       if(strType=="MobilePhoneNumber")
        {
            if(checkMobilePhoneNumber(strValue)==false)
            {
               blncheck="0";
          }
       }
       
       if(strType=="title")
        {
            if(checkTitle(strValue)==false)
            {
               blncheck="0";
          }
       }
           //Change by Anjali completed
       if(strType == 'url')
       {
            if(validateURL(strValue) == false)
            {
                blncheck="0";
            }
       }
       
        
       //If checking is valid
      if(blncheck=="1")
      {
         document.getElementById(controlID).style.backgroundColor = "white";
         return true;
      }  
      else
      {  
         var control=document.getElementById(controlID)
         control.style.backgroundColor = "#cad7ec";//"#cad7ec";        
         if(strMessage == "")
            control.focus();
         strMessage=strMessage + "\n----" + strName;   
         return false;
       }
    
   }



 function fnCheckSTDCode(str)
   {
   if(str!="")
   {
      if(str!="0")
      {
           if(checkCode(str))
           {
                if(str.length<1)
                {
                    return false;
                }
                if(str.length>6)
                {
                    return false;
                }
               return true;
           }
            else
            {
            return false;
            }
       }
      
   }
   return true;
   }  
   

function fnCheckSTD(str)
   {
   if(str!="")
   {
      if(str!="0")
      {
           if(checkCode(str))
           {
                if(str.length<3)
                {
                    return false
                }
                if(str.length>9)
                {
                    return false
                }
               return true;
           }
            else
            {
            return false;
            }
       }
      
   }
   return true;
   }  
 
//Change End
   
   
function checkTime(str)
{
 if(str!="")
 {
      
      if(str.match(/^[0-9]+:[0-9]/))
       {

          var arySplit=str.split(":")
          if(arySplit[0]>12)
          {
            return false;
          }
           if(arySplit[1]>59)
          {
          return false;
          }
          return true;
       }
      else
      { 
         return false;
      }  
  }
      return true;   
}

//validate number     

function checkNumber(str)
{

 if(str!="")
 {
      //if(str.match(/^(+)?\d+(\.\d{2})?$/))
      if(str.match(/^\d+$/)) 
       {
          return true;
       }
      else
      { 
         return false;
      }  
 }
      return true;    
}

   //Change by Anjali 
 
 //Validate phone number should allow [0-9, - , ()]      
function checkMobilePhoneNumber(str)
{

    //if(str.match(/^\[0-9()-]*[0-9]$))
    //if(str.match(/\d*/))  
    if(str.match(/^[0-9()-]*/)) 
       {
          return true;
       }
      else
      { 
         return false;
      }  
 
 }
 
 function checkTitle(str)
{
   
    if(str.match(/^[a-zA-Z ()&-/]+$/)) 
       {
          return true;
       }
      else
      { 
         return false;
      }  
 
 }
     
   //Change by Anjali completed
       

//validate number   

function checkDecimal(str)
{

 if(str!="")
 {
      //if(str.match(/^(+)?\d+(\.\d{2})?$/))
      
        if(str.match(/^(\d+\.\d{0,2}|\d+)$/)) 
       {
          return true;
       }
      else
      { 
         return false;
      }  
 }
      return true;    
}  

function checkCode(str)
{

 if(str!="")
 {
 //(-)?\d
      if(str.match(/^[0-9+]+$/))
       {
       
          return true;
       }
      else
      { 
      
         return false;
      }  
   }
     
      return true;    
}
 

//validate string

function checkString(str)
{
//[a-zA-Z'.\s]

    if(str!="")
    {
        if(str.match(/^[a-zA-Z'.,()\s]+$/))
        {
            return true;
        }
        else
        {
           return false;
        }
    }
    return true;
}     

     

//function to validate mail
function checkMail(str)
{      

    var emailID=str;
	
	//if ((emailID==null)||(emailID==""))
	//{
	//	return false;
	//}
	if (echeck(emailID)==false)
	{
	    return false;
	}
	return true
}  

function echeck(str) {

        
        if(str != null && 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 E-mail ID")
		       return false;
		    }

		    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		       //alert("Invalid E-mail ID")
		       return false;
		    }

		    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		        //alert("Invalid E-mail ID")
		        return false;
		    }

		     if (str.indexOf(at,(lat+1))!=-1){
		        //alert("Invalid E-mail ID")
		        return false;
		     }

		     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		        //alert("Invalid E-mail ID")
		        return false;
		     }

		     if (str.indexOf(dot,(lat+2))==-1){
		        //alert("Invalid E-mail ID")
		        return false;
		     }
    		
		     if (str.indexOf(" ")!=-1){
		        //alert("Invalid E-mail ID");
		        return false;
		     }
             
 		     return true	
 		 }				
	}


//function checkMail(str)
//{
//    if(str!="")
//    {
//        if(str.match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/))
//        {
//            return true;
//        }
//        else
//        {
//           return false;
//        }
//    }
//    return true;
//}     


function alphaNumericCheck(str)
{
    if(str!="")
    {
    
        //var regex=/^[0-9A-Za-z]+$/; //^[a-zA-z]+$/
        var regex=/^[\w\s\d\s-+'+"+.+,+_+-+]*$/;
        if(regex.test(str))
        {
          return true;
         } 
       else {
         return false;
       }
    }
    return true;
}

function alphaOnly(str)
{
    if(str!="")
    {
        var regex=/[a-zA-Z ]+$/;        
        if(regex.test(str))
        {
          return true;
        } 
       else {
         return false;
       }
    }
    return true;
}

function alphaNumericCheckWithSpaces(str)
{
   ///This is for alphaNumeric Number with space accepted.
    if(str!="")
    {
          
      //var regex=/[a-zA-Z0-9 ]+$/;
      
      var regex=/^[a-zA-Z\s\d]*$/;
      //var regex=/^[a-zA-Z0-9'.\\s]{1,100}$/;
      
      
        if(regex.test(str))
        {
          return true;
         } 
       else {
         return false;
       }
    }    
    return true;
}


function alphaNumericValidator(str) {
// if empty fields are invalid,
// replace the * by a +
// * = if any or more
// + = 1 or more
// \w = a letter (= [a-zA-Z])
// \d = a number (= [0-9])
// \s = white space (= [ \n\r\t])
// \n = new line
// \r = carriage return
// \t = tabs
// ^ = the beginning of the string
// $ = the end of the string
// [\w\d\s] = [a-zA-Z0-9 \n\r\t]
return /^[\w\d\s]*$/.test(str);
}
 function fnConfirm(strMessage)
        {
            
            input_box=confirm(strMessage);
            if (input_box==true)

            { 
                // Output when OK is clicked
                //alert ("You clicked OK"); 
                return true;
            }

            else
            {
                // Output when Cancel is clicked
                //alert ("You clicked cancel");
                return false;
            }

        }
       
function CheckForHTMLTag(strToCheck)
{    
    if(strToCheck.match(/([\<])([^\>]{1,})*([\>])/i) == null)
        return false;
    else
        return true;
}

function validateURL(strUrlToCheck) { 
    var v = new RegExp(); 
    v.compile("[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
    if (!v.test(strUrlToCheck)) 
    { 
        return false; 
    } 
    return true;/*
    if (/^w+([.-]?w+)*.w+([.-]?w+)*(.w{2,3})+$/.test(valor)){
        return (true);
    } else {
        return (false);
    }*/

    
} 

