/******************************************
Function name : getMasterString
Return type : boolean
Comments : Function will return the main string
User instruction : getMasterString()
******************************************/
function getMasterString()
{
    return "Sorry, we can not complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n";
}


/******************************************
Function name : toggleOption
Return type : None
Comments : Function will toggle the select all checkbox option.
User instruction : toggleOption(spanChk)
******************************************/
function toggleOption(spanChk)
{
    var xState=spanChk.checked;
    var theBox=spanChk;

    elm=theBox.form.elements;
    for(i=0;i<elm.length;i++)
    {
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
        {
            if(xState == false)
                elm[i].checked = false;
            else
                elm[i].checked = true;
        }
    }
}

/******************************************
Function name :deSelectCheckbox
Return type :none
Comments : Function will deSelect the main check box
User instruction : deSelectCheckbox()
******************************************/

function deSelectCheckbox(formname)
{
    
	document.forms[1].selectAll.checked=false;
}

/******************************************
Function name : askConfirm
Return type : boolean
Comments : Function will return the true or false after asking for confirmation
User instruction : askConfirm(type)
******************************************/
function askConfirm(type)
{    
    
    var sen = "Are you sure you want to "+type+"?";
    if(confirm(sen))
        return true;
    else
        return false;
}

/******************************************
    Function name : setValidAction
    Return type : boolean
    comments : JavaScript to perform valid actin for the list.
 ******************************************/
function setValidAction(value,formname,filename,action)
{

        if(value == 'Delete')
        {
            message = "delete selected "+filename;        
        }
        var flag = validator(message,formname);            
        if(flag)
        {
            if(value == 'Delete')
            {
                formname.action = action+'?act=del';
            }
            formname.submit();
        }
        else
        {
            //alert('hiii'); return false;
            //formname.frmChangeAction.value='';    
            document.forms[0].selectAll.checked=false;                
            elm=document.forms[0].elements;
            //alert(elm.length); return false;
            for(i=0;i<elm.length;i++)
            {
                if(elm[i].type=="checkbox")
                {            
                    elm[i].checked = false;
                
                }
            }
            return false;
        }
}

/******************************************
Function name : validator
Return type : boolean
Comments : Function will return the true or error message after validating checkboxes
User instruction : validator(btnType)
******************************************/
var btnType;
function validator(btnType,formname)
{
    
    var obj = formname;
    var error="", flagCheck=0;
    
    var len = obj.elements.length; 
      
    var i=0;
     
    for(i=0;i<len;i++) 
    {
        if(obj.elements[i].type=='checkbox')
        {
            if(obj.elements[i].checked)
            {
                //if(btnType == 'Delete')
                    return askConfirm(btnType);
                //else
                    //return true;
            }
            else
                flagCheck = 1;
        }
    }
   
    if(flagCheck == 1)
        error += "\nPlease select at least one record.";
            
    return checkError(error);
}




/******************************************
Function name : checkError
Return type : boolean
comments : Function will return the true or false acording to form validation
User instruction : checkError(error)
******************************************/
function checkError(error)
{      
 
    var flag=false;
    var MasterString = getMasterString();
      //alert(error); return false;  
    if(error != "")
    {
        MasterString = MasterString + error;
        flag=true;
    }
    
    if(flag == true)
    {
        alert(MasterString);
        return false;
    }
    else
        return true;
}

function validateForm() 
{ 
    var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
    j=0;
    //    /^([-a-zA-Z0-9._]+@[-a-zA-Z0-9.]+(\.[-a-zA-Z0-9]+)+)$/;
    //var regEmail = /^[0-9a-z]+(([\.\-_])[0-9a-z]+)*@[0-9a-z]+(([\.\-])[0-9a-z-]+)*\.[a-z]{2,4}$/;
    var regEmail = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";
    var regBlank = /[^\s]/;
    //var regSpace = /[\s]/;
    var regSpace = /^([a-zA-Z0-9-/_!#@]+)$/;
    //var regAlphaNum = /^([a-zA-Z0-9-/_ :;#!@\n\r.,$*&%?^~`=+(){}\[\]\"\'\\]+)$/;
    var regAlphaNum = /^([a-zA-Z0-9_#@!]+)$/;
     var regDate = /^([0-9_]+-[0-9][0-9]+-[0-9][0-9]+)$/; 
   var regChar = /^([a-zA-Z]+)$/;
    var MasterString = getMasterString(); 
    //alert (validateForm.arguments[1].name);
    //alert("sss--->"+document.forms[""+args[0]].elements[""+args[0]].value);
    for (i=1; i<(args.length-2); i+=3) 
    {    
        mesg=args[i+1];
        test=args[i+2]; 
        val=document.forms[""+args[0]].elements[""+args[i]];
        
            if (val) 
            {    
                nm=mesg; 
                noVal = val;
                val = val.value;
                
            if(test=='BLNK')
            {
             if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
             if (val<0) errors+='- '+nm+' must contain a number.\n';
             }            
             else if(test=='CHKURL' && val !="")
                {
                    p=val.indexOf('http://');
                    s=val.indexOf('.');
                    if (p<0 || p==(val.length-1))
                    {
                        errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
        
                    }
                    else if(s<p || s==(val.length-1))
                    {
                        errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
                    }

                }
             else
                {
            if(regBlank.test(val))
            {
                if(test.indexOf('isEqual')!=-1)
                {
                    result = trim(val);

                if(result.length==0){
                                        
                errors += '- '+nm+' is required.\n'; 
                }else{
                    
                    equal_obj_val = test.substring(8,test.indexOf(":"));
                    mesg_string =test.substring((test.indexOf(":")+1));

                    if(val != document.forms[""+args[0]].elements[""+equal_obj_val].value)
                    { 
                        errors+='- '+nm+' and '+mesg_string+' must be same.\n';
                    }
                }
                }
                else if(test.indexOf('isAlphaNum')!=-1)
                {
                result = trim(val);
                if(result.length==0){
                errors += '- '+nm+' is required.\n'; 
                }else{
                    if(!regAlphaNum.test(val))
                    {
                        errors += '- '+nm+' is not valid.\n';
                        //errors+='- '+nm+': Only Alpha Numeric and "_ , . - ! @ # () {} [] " coma,  single cots and Chars Allowed.\n';
                    }
                }
                
                }
                else if(test.indexOf('isSpace')!=-1)
                {
                result = trim(val);
                
                if(result.length==0)
                {
                    errors += '- '+nm+' is required.\n'; 
                }
                else
                {
                    if(!regSpace.test(val))
                    {
                        errors+='- '+nm+': Only Alpha Numeric and "_ - ! @ # " Allowed.\n';
                        //errors += '- '+nm+' is not valid.\n';
                    }
                }
                }
                else if (test.indexOf('isDate')!=-1) 
                { 
                    p=val.indexOf('-');
                   // alert(test.indexOf('isDate'));
                       var sliptdate    = val.split("-");
                    
                    /*******************Added by rupesh Date is not before current date and month*********************/
                    var today=new Date(),TY=today.getFullYear(),TM=today.getMonth(),TD=today.getDate(),TH=today.getHours();
                    TM+=1;            
                    if(TM<=9) 
                    {    
                        TM='0'+TM;
                    }
                    if(TD<=9)
                    {
                        TD='0'+TD;
                    }
                    /*******************Added by rupesh*********************/
                    
                    var sY=sliptdate[0];
                    var sM=sliptdate[1];
                    var sD=sliptdate[2];
                    
                    /*******************Added by rupesh*********************/
                    //alert(TM);
                    if(sY<TY ) {
                        
                        errors+='- '+nm+' should be greater than current date.\n';
                    }
                    else if(sM==TM && sD<TD && sY==TY) { 

                        errors+='- '+nm+' should be greater than current date.\n';
                        
                    }
                    else if(sM<TM && sY==TY) { 

                        errors+='- '+nm+' should be greater than current date.\n';
                        
                    }
                    
                    /*************************Added by rupesh********************/
                    else if (p != 4 || sY.length != 4 || sM.length != 2 || sD.length != 2 )
                    {
                        errors+='- '+nm+' must contain Valid Date YYYY-MM-DD.\n';
        
                    }
                    else if(!regDate.test(val))
                    {
                        errors+='- '+nm+'  must contain Valid Date YYYY-MM-DD.\n';
                    }
                    else if(sM>12 || sD>31 || sY<2006)
                    {
                        errors+='- '+nm+'  must contain Valid Date YYYY-MM-DD.\n';
                    }
                 }
                else if (test.indexOf('isEmail')!=-1) 
                { 
                    p=val.indexOf('@');
                    s=val.indexOf('.');
                    if (p<1 || p==(val.length-1))
                    {
                        errors+='- '+nm+' must contain an e-mail Address.\n';
        
                    }
                    //else if(s<p || s==(val.length-1))
                    else if(!regEmail.test(val))
                    {
                        errors+='- '+nm+' must contain a valid e-mail Address.\n';
                    }
                 }
                else if (test.indexOf('isUrl')!=-1) 
                { 
                    p=val.indexOf('http://');
                    s=val.indexOf('.');
                    if (p<0 || p==(val.length-1))
                    {
                        errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
        
                    }
                    else if(s<p || s==(val.length-1))
                    {
                        errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
                    }
                 }
                 else if(test.indexOf('isMp3')!=-1)
                 {
                    function reverse(val) 
                    {    
                        var length = val.length;
                        var letters = new Array(length);
                        var letters2 = new Array(length);
                        var backword = "";
                        for (i=0; i<=length-1; i++) 
                        {
                            letters[i] = val.substring(i, i+1);
                        }
                        f = 0
                        for (j=i-1; j>=0; j--) 
                        {
                            letters2[f] = letters[j];
                            f++;
                        }
                        for (h=0; h<=letters2.length-1; h++) 
                        {
                            backword +=letters2[h];
                        }
                         return backword;
                    }
                    var back = reverse(val);
                    var ValExt    = back.split(".");
                    var ValExt = reverse(ValExt[0]);
                    
                    if (ValExt == "mp3" || ValExt == "MP3") 
                    {
                        flag="yes";
                    } 
                    else 
                    {
                        flag="no";                        
                    } 
                    if(flag=="no")
                    {
                        errors+='- '+nm+' must be (mp3).\n';                        
                    }
                 
                 }
                 else if (test.indexOf('isChar')!=-1) 
                 { 
                    var first_char;
                    
                    if(val.match(regChar)==null)
                    {
                         errors+='- '+nm+' must contain a character.\n';
                    }
                 }
                 else if(test.indexOf('isCheckbox')!=-1)//Check is check box is not checked generate error
                {    
                    var valueCheckbox = noVal.checked;
                    if(!valueCheckbox)
                    {
                        errors+='- '+'You must accept Privacy Policy and Terms of Use.\n';
                    }
                }
				 else if (test!='R' || test=='Numbers') 
                 {
                 result = trim(val);
                    if(result.length==0){
                        
                        if(errors.indexOf('Phone') == -1)
                    errors += '- '+nm+' is required.\n'; 
                    }
                    
                    if (isNaN(val)) 
                    {
                     if(errors.indexOf('Phone') == -1)
                     errors+='- '+nm+' must contain a number.\n';
                    }
                    else
                    {
                    if(test=='Numbers' && !isNaN(val))
                    {
                    var i1;
                    var num1=0;
                        for (i1 = 0; i1 < val.length; i1++)
                        {   
                            // Check that current character is number.
                            var c = val.charAt(i1);
                            if (((c < "0") || (c > "9"))) num1=1;
                        }
                        if(num1==1)
                        {
                            if(errors.indexOf('Phone') == -1)
                            errors+='- '+nm+' can only contain numbers.\n';
                        }
                    }
                 }
                    if (test.indexOf('inRange') != -1) 
                    { num = parseFloat(val);
                        p=test.indexOf(':');
                        min=test.substring(8,p); 
                        max=test.substring(p+1);
                        
                        if (num<min || max<num) 
                            if(min==max)
                            {
                              if(min==1 && max==1 & num==0)
                                {
                            errors+='- '+nm+' should  be more than '+min+'.\n';
                                }
                                if(min!=1 && max!=1 && min==max)
                                {
                            errors+='- '+nm+' should not be more than '+min+'.\n';
                                }
                            }                
                            
                        else
                        {
                        errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
                        }
                    } 
                    if (val.indexOf('-') != -1) 
                    { 
                        errors='- '+nm+' must contain a number.\n';
                    } 
                    if (val.indexOf('+') != -1) 
                    { 
                        errors='- '+nm+' must contain a number.\n';
                    }
                    
                }else if (test.charAt(0)=='R')
                {
                result = trim(val);
                if(result.length==0){
                    
                errors += '- '+nm+' is required.\n'; 
                }
                } 
            }
            else if (test.charAt(0) == 'R' || test=='Numbers'){
                if(errors.indexOf('Phone') == -1 && test=='Numbers')
                {
                errors += '- '+nm+' is required.\n'; 
                }
                if (test.charAt(0) == 'R')
                {                    
                errors += '- '+nm+' is required.\n';     
                }
            }
        }
            }
        if(errors !="")
        {    if(j<=0)
            {
                focusitem = document.forms[""+args[0]].elements[""+args[i]];
                j++;
            }    
        }
    } 
    
  if (errors)
  {
    
    alert( MasterString+'\n' +errors);
    focusitem.focus();
    return false;
   }
   else
    return true;
  document.MM_returnValue = (errors == '');
}


function stripHTML(str){
      var re= /<\S[^><]*>(&nbsp;)*/g ;
      return str.replace(re, "") ;
}

function ltrim(str) { 
    for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
    return str.substring(k, str.length);
}

function rtrim(str) {
    for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
    return str.substring(0,j+1);
}


function trim(str) {
    return ltrim(rtrim(str));
}


function isWhitespace(charToCheck) {
    var whitespaceChars = " \t\n\r\f";
    return (whitespaceChars.indexOf(charToCheck) != -1);
}



/***********************************************
function name : checkEditCategory(formname)
Comment : this is used for check category field is empty or not
************************************************/
function checkEditCategory(formName)
{
    if(validateForm(formName,'frmCategoryName','Category Name','R'))
      {  
            return true;
      } 
      else 
      {
           return false;
      }
    
}



/***********************************************
function name : checkEditCategory(formname)
Comment : this is used for check category field is empty or not
************************************************/
function checkPlatinumMemberEnquiryForm(formName)
{
     
	  if(validateForm(formName,'frmContactFirm','Contact Information: primary contact at your firm','R',
	                  'frmContactPhoneNumber','Contact Information: phone number','RisNaN',
					  'frmContactEmailID','Contact Information: email address','RisEmail',
					  'frmLocalNewsPaperName','Local NewsPaper: newspaper','R',
					  'frmLocalNewsPaperPhone','Local NewsPaper: phone number','R',
					  'frmBusinessEditor','Local NewsPaper: business editor','R',
					  'frmLocalNewsPaperBusinessEditorEmail','Local NewsPaper: email','RisEmail',
					  'frmBusinessGeneralName','Business Journal: local Business general name','R',
					  'frmBusinessGeneralPhoneNumber','Business Journal: phone number','RisNaN',
                      'frmBusinessGeneralEmailID','Business Journal: email','RisEmail',
                      'frmBusinessGeneralEditor','Business Journal: editor','R',
                      'frmPublicRelationMoreInformation','Public Relations: award related details','R',
                      'frmWebsiteURL','Search Engine Optimization: website url','RisUrl',
                      'frmWebMaster','Search Engine Optimization: webmaster','R',
                      'frmWebMasterPhoneNumber','Search Engine Optimization: phone number','RisNaN',
                      'frmWebMasterEmailAddress','Search Engine Optimization: email address','RisEmail',
                      'frmWebMasterProfession','Search Engine Optimization: profession','R',
                      'frmSpeciality','Search Engine Optimization: specialty','R',
                      'frmImage','Search Engine Optimization: image','RisNaN',
                      'frmClientInterface','Search Engine Optimization: client interface','RisNaN',
                      'frmInformationAccess','Search Engine Optimization: information access','RisNaN',
                      'frmGenerateNewBusiness','Search Engine Optimization: new business','RisNaN',
                      'frmGenerateProspectList','Search Engine Optimization: prospect list','RisNaN',
                      'frmSetAppoinments','Search Engine Optimization: set appoinments','RisNaN',
                      'frmCountOfContacts','Newsletter marketing: count of contacts', 'RisNan', 'frmProspectContacts','Newsletter marketing: prospect contacts', 'RisNaN'))
	  {  
            return false    ;
      } 
      else 
      {
           return false;
      }
    
}

/***********************************************
function name : checkValidNewsLetter(formname)
Comment : this is used for check news letter form filed
************************************************/
function checkValidNewsLetter(formName)
{
    if(validateForm(formName,'frmTitle','Newsletter title','R'))
      {  
            return true;
      } 
      else 
      {
           return false;
      }
    
}

/***********************************************
function name : checkValidNewsLetterSend(formname)
Comment : this is used for check add/edit question form filed
************************************************/
function checkValidNewsLetterSend(formname)
{
	   var MasterString = getMasterString();
	   var errorString = '';
	   
	   total_option=document.frmNewsLetterSend.sendNewsUser.options.length;
	   boolCheck=document.frmNewsLetterSend.sendNewsLetterAll.checked;
	  
		   var j=0;
		   for(i=0;i<total_option;i++)
		   {
			  if(document.frmNewsLetterSend.sendNewsUser[i].value == '' && document.frmNewsLetterSend.sendNewsUser[i].selected)
			  {
				   j=0;
				   break;
			  }
			  else
			  {
				  j=j+1;
				  break;	
			  }
		   }
		   
		   for(i=0;i<total_option;i++)
		   {
			   if(!document.frmNewsLetterSend.sendNewsUser[i].selected)
			   {
					if(i == (total_option-1))
					{
				   	    boolChekMultiBox = true;	
					}

			   }
			   else
			   {
				   boolChekMultiBox = false;
				   break;
			   }

		   }
		   
	   if(document.getElementById('frmTitle').value == '') 
       {
              errorString += '- Newsletter title is required.\n';     
       }
	   if(boolChekMultiBox && !document.frmNewsLetterSend.sendNewsLetterAll.checked)
	   {
		   errorString += '- Either select atleast one user from select box OR tick check box for send news letter to all user.\n';
	   }
	   if(j==0)
	   {
		   errorString += '- Either select atleast one user from select box OR tick check box for send news letter to all user.\n'; 
	   }
	   if(errorString == '')
       {
            return true;  
       }
       else
       {
            alert(MasterString+' \n '+errorString); 
            return false;   
        } 
}

/***********************************************
function name : checkValidQuestion(formname)
Comment : this is used for check add/edit question form filed
************************************************/
function checkValidQuestion(formName)
{

	    var MasterString = getMasterString();
        var errorString = '';
        var boolfocus = false;
        var elementID ;
        // condition for checked radio button is checked or not 
		count=document.frmQuestionAdd.frmanswer.length;
		var boolRadio = false;
		//alert(document.getElementById('frmQuestion').value+'aaaaa');
        for(i=0;i<count;i++)
		{
				  if(document.frmQuestionAdd.frmanswer[i].checked)
				  {
					  boolRadio = true;
					  break;
				  }
				  else
				  {
					  boolRadio = false;
					  continue;
 
				  }
		}
        // end condition here 
       if(document.getElementById('frmQuestionCategory').value == '') 
       {
              errorString += '- Category is required.\n';     
              boolfocus = true; 
              elementID = 'frmQuestionCategory';     
       }
       if(document.getElementById('frmQuestion').value == '') 
       {
              errorString += '- Question is required.\n';     
              if(!boolfocus )
              {
              boolfocus = true; 
              elementID = 'frmQuestion';     
              }
       }
	   if(document.getElementById('frmOption1').value == '') 
       {
              errorString += '- Option1 is required.\n';     
              if(!boolfocus )
              {
              boolfocus = true; 
              elementID = 'frmOption1';     
              }
       }
	   if(document.getElementById('frmOption2').value == '') 
       {
              errorString += '- Option2 is required.\n';     
              if(!boolfocus )
              {
              boolfocus = true; 
              elementID = 'frmOption2';     
              }
       }
	   if(document.getElementById('frmOption3').value == '') 
       {
              errorString += '- Option3 is required.\n';     
              if(!boolfocus )
              {
              boolfocus = true; 
              elementID = 'frmOption3';     
              }
       }
	   if(document.getElementById('frmOption4').value == '') 
       {
              errorString += '- Option4 is required.\n';     
              if(!boolfocus )
              {
              boolfocus = true; 
              elementID = 'frmOption4';     
              }
       }	
	   if(!boolRadio)
	   { 	
			errorString += '- Please select one answer .\n';
	   }
			   
	   if(errorString == '')
       {
            return true;  
       }
       else
       {
            alert(MasterString+' \n '+errorString); 
            if(boolfocus)
            {
             document.getElementById(elementID).focus();
            }
            return false;   
        } 
	
}

function showQuestion(str)
{ 
	//doAjax('getQuestion.php','q='+str, 'showQuestionList' );
	//alert(str); return false;
	var pars 	= Form.serialize('questionListing');
	var myAjax =  new Ajax.Request('getQuestion.php?q='+str,{method:'post',cache:false,parameters: pars, onLoading: textSearchLoad, onComplete: showQuestionList} );
}
function textSearchLoad() 
{
    $('searchLoad').style.display = 'block';
}
function showQuestionList(originalRequest) 
{
   //alert(originalRequest.responseText);
   strQuestion = originalRequest.responseText;
   //alert(strQuestion); 
   if(strQuestion == 'complete')
   {
   		//window.location.href='test_paper_complete.php?act=complete';
        window.location.href='invite_friend.php?act=complete';
		//document.getElementById("quetionhere").innerHTML=originalRequest.responseText;
   }
   else if(strQuestion == 'vanish')
   {
	    window.location.href='test_paper_complete.php?act=vanish';
   }
   else
   {
	   //alert(originalRequest.responseText);
       document.getElementById("quetionhere").innerHTML=originalRequest.responseText;
       
   }
} 
//function showQuestionList (showlist) 
//{
//   document.getElementById("quetionhere").innerHTML=showlist;   
//} 
//function CheckQuestionAnsqwer(QuestAns)
//{
//	doAjax('getQuestion.php','qa='+QuestAns, 'showQuestionAnsStatus' );
//}
//function showQuestionAnsStatus(showStatus)
//{
//	alert(showStatus); 
//}

function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

 return true;
}

function checkType(val)
{
    if(val == 'R')
    {
        document.getElementById('scoreRangeFrom').disabled = false;
        document.getElementById('scoreRangeTo').disabled = false;  
    }
    if(val == 'GT')
    {
        document.getElementById('scoreRangeFrom').disabled = false;
        document.getElementById('scoreRangeTo').disabled = true; 
    }
    
    if(val == 'LT')
    {
        document.getElementById('scoreRangeFrom').disabled = true;
        document.getElementById('scoreRangeTo').disabled = false; 
    }
}

function checkValidScoreRange(formname)
{
    var MasterString = getMasterString();
    var errorString = '';
    var boolfocus = false;
    var boolR     = false;
    var boolGT    = false;
    var boolLT    = false;
    var elementID ;
    
    if(document.getElementById('scoreRangeTypeR').checked)
    {
        boolR = true;
        
    }
    if(document.getElementById('scoreRangeTypeGT').checked)
    {
        boolGT = true;
        
    }
    if(document.getElementById('scoreRangeTypeLT').checked)
    {
        boolLT = true;
        
    }
    
    if(document.getElementById('scoreRangeTitle').value == '') 
    {
          errorString += '- Score range title is required.\n';     
          boolfocus = true; 
          elementID = 'scoreRangeTitle';     
    }
    

    
    if(boolR)
    {
    
        if(document.getElementById('scoreRangeFrom').value == '') 
        {
              errorString += '- Score range from is required.\n';     
              if(!boolfocus )
              {
                boolfocus = true; 
                elementID = 'scoreRangeFrom';     
              }
        }
        if(document.getElementById('scoreRangeTo').value == '') 
        {
              errorString += '- Score range to is required.\n';     
              if(!boolfocus )
              {
                boolfocus = true; 
                elementID = 'scoreRangeTo';     
              }
        }
        if(document.getElementById('scoreRangeFrom').value != '' && document.getElementById('scoreRangeTo').value != '') 
        {
              
              if(document.getElementById('scoreRangeFrom').value >= document.getElementById('scoreRangeTo').value )
              {
                  errorString += '- Score range from can not be greater than from score range to or equal.\n';     
                  if(!boolfocus )
                  {
                    boolfocus = true; 
                    elementID = 'scoreRangeFrom';     
                  }
              }    
        }
        
    }
    if(boolGT)
    {
         if(document.getElementById('scoreRangeFrom').value == '') 
        {
              errorString += '- Score range from is required.\n';     
              if(!boolfocus )
              {
                boolfocus = true; 
                elementID = 'scoreRangeFrom';     
              }
        }
    }
    
    if(boolLT)
    {
         if(document.getElementById('scoreRangeTo').value == '') 
        {
              errorString += '- Score range To is required.\n';     
              if(!boolfocus )
              {
                boolfocus = true; 
                elementID = 'scoreRangeTo';     
              }
        }
    }
    
    if(document.getElementById('scoreRangePercent').value == '') 
    {
          errorString += '- Score range percent is required.\n';     
          if(!boolfocus )
          {
            boolfocus = true; 
            elementID = 'scoreRangePercent';     
          }
    }
    else if(isNaN(document.getElementById('scoreRangePercent').value)) 
    {
          errorString += '- Score range percent can be numeric only.\n';     
          if(!boolfocus )
          {
            boolfocus = true; 
            elementID = 'scoreRangePercent';     
          }
    }
   
    if(errorString == '')
    {
       
       document.frmScoreRangeAdd.action = document.frmScoreRangeAdd.action;
       document.frmScoreRangeAdd.submit(); 
       return true; 
    }
   else
   {
        alert(MasterString+' \n '+errorString); 
        if(boolfocus)
        {
         document.getElementById(elementID).focus();
        }
        return false;   
    } 
   // return false;
     
        
}


function checkTypeCat(val)
{
    if(val == 'R')
    {
        document.getElementById('catScoreRangeFrom').disabled = false;
        document.getElementById('catScoreRangeTo').disabled = false;  
    }
    if(val == 'GT')
    {
        document.getElementById('catScoreRangeFrom').disabled = false;
        document.getElementById('catScoreRangeTo').disabled = true; 
    }
    
    if(val == 'LT')
    {
        document.getElementById('catScoreRangeFrom').disabled = true;
        document.getElementById('catScoreRangeTo').disabled = false; 
    }
}

function checkValidCatScoreRange(formname)
{
    var MasterString = getMasterString();
    var errorString = '';
    var boolfocus = false;
    var boolR     = false;
    var boolGT    = false;
    var boolLT    = false;
    var elementID ;
    
    if(document.getElementById('catScoreRangeTypeR').checked)
    {
        boolR = true;
        
    }
    if(document.getElementById('catScoreRangeTypeGT').checked)
    {
        boolGT = true;
        
    }
    if(document.getElementById('catScoreRangeTypeLT').checked)
    {
        boolLT = true;
        
    }
    
    if(boolR)
    {
    
        if(document.getElementById('catScoreRangeFrom').value == '') 
        {
              errorString += '- Category Score range from is required.\n';     
              if(!boolfocus )
              {
                boolfocus = true; 
                elementID = 'catScoreRangeFrom';     
              }
        }
        if(document.getElementById('catScoreRangeTo').value == '') 
        {
              errorString += '- Category Score range to is required.\n';     
              if(!boolfocus )
              {
                boolfocus = true; 
                elementID = 'catScoreRangeTo';     
              }
        }
        if(document.getElementById('catScoreRangeFrom').value != '' && document.getElementById('catScoreRangeTo').value != '') 
        {
              
              if(document.getElementById('catScoreRangeFrom').value >= document.getElementById('catScoreRangeTo').value )
              {
                  errorString += '- Category Score range from can not be greater than from category score range to or equal.\n';     
                  if(!boolfocus )
                  {
                    boolfocus = true; 
                    elementID = 'catScoreRangeFrom';     
                  }
              }    
        }
        
    }
    if(boolGT)
    {
         if(document.getElementById('catScoreRangeFrom').value == '') 
        {
              errorString += '- Category Score range from is required.\n';     
              if(!boolfocus )
              {
                boolfocus = true; 
                elementID = 'catScoreRangeFrom';     
              }
        }
    }
    
    if(boolLT)
    {
         if(document.getElementById('catScoreRangeTo').value == '') 
        {
              errorString += '- Category Score range To is required.\n';     
              if(!boolfocus )
              {
                boolfocus = true; 
                elementID = 'catScoreRangeTo';     
              }
        }
    }
    
   
    if(errorString == '')
    {
       
       document.frmCateScoreRangeAdd.action = document.frmCatScoreRangeAdd.action;
       document.frmCatScoreRangeAdd.submit(); 
       return true; 
    }
   else
   {
        alert(MasterString+' \n '+errorString); 
        if(boolfocus)
        {
         document.getElementById(elementID).focus();
        }
        return false;   
    } 
   // return false;
}

/***************************************** from here added by sumit for bestof us ***********************************/

function validRegistration(formName)
{
	
	if(validateForm(formName,'userName','Username','R','password','Password','RisSpace','passwordConfirm','Confirm Password', 'RisEqualpassword:Password','firstName','First Name','R','lastName','Last Name','R','email','Email','R','birth_date','Birth date','R','birth_month','Birth month','R','birth_year','Birth year','R','address','Address','R','city','City',
    'R','stateId','State','R','zipcode','Zipcode','R'))
      {  
            return true;
      } 
      else 
      {
           return false;
      }
}

function validApplyList(formName)
{
	
	if(validateForm(formName,'firstName','First Name','R','lastName','Last Name','R','professionId','Profession','R','phone','Phone','RisNaN','email','Email','R','companyName','Firm/Facility','R','street1','Address 1','R','stateId','State','R','city','City','R','postalCode','Zipcode','RisAlphaNum','reason_apply','Reason for apply','R'))
    {  
            return true;
    } 
    else 
    {
           return false;
    }
}

function validUpgradeForm(formName)
{
	
	var MasterString = getMasterString();
    var errorString = '';
    var boolfocus = false;
	if(document.getElementById('firstname').value == '') 
	{
		  errorString += '- First name is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'firstname';     
		  }
	}

	if(document.getElementById('lastname').value == '') 
	{
		  errorString += '- Last name is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'lastname';     
		  }
	}
	
	if(document.getElementById('professionId').value == '') 
	{
		  errorString += '- Profession is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'professionId';     
		  }
	}
	
	if(document.getElementById('email').value == '') 
	{
		  errorString += '- Email is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'email';     
		  }
	}
	if(document.getElementById('phone').value == '') 
	{
		  errorString += '- Phone is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'phone';     
		  }
	}
	
	if(document.getElementById('business').value == '') 
	{
		  errorString += '- Firm/Faclity is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'business';     
		  }
	}
	if(document.getElementById('address1').value == '') 
	{
		  errorString += '- Address Line 1 is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'address1';     
		  }
	}
	
	if(document.getElementById('city').value == '') 
	{
		  errorString += '- City is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'city';     
		  }
	}
	
	if(document.getElementById('state').value == '') 
	{
		  errorString += '- State is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'state';     
		  }
	}
	
	if(document.getElementById('zip').value == '') 
	{
		  errorString += '- Postal Code is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'zip';     
		  }
	}
	if((document.getElementById('ug_college')) || (document.getElementById('ug_Year')) || (document.getElementById('ug_degree')))
	{
		
		if((document.getElementById('ug_college').value != '') || (document.getElementById('ug_Year').value != '') || (document.getElementById('ug_degree').value != ''))
		{
			 if(document.getElementById('ug_college').value == '') 
			 {
				  errorString += '- Under graduate college is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'ug_college';     
				  }
			 }
			 if(document.getElementById('ug_Year').value == '') 
			 {
				  errorString += '- Under graduate year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'ug_Year';     
				  }
			 }
			 if(document.getElementById('ug_degree').value == '') 
			 {
				  errorString += '- Under graduate degree is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'ug_Year';     
				  }
			 }
			 
		}
	}
	
	if((document.getElementById('adv_college')) || (document.getElementById('adv_Year')) || (document.getElementById('adv_degree')))
	{/*
		
		if((document.getElementById('adv_college').value != '') || (document.getElementById('adv_Year').value != '') || (document.getElementById('ug_degree').value != ''))
		{
			 if(document.getElementById('adv_college').value == '') 
			 {
				  errorString += '- Advance college is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'adv_college';     
				  }
			 }
			 if(document.getElementById('adv_Year').value == '') 
			 {
				  errorString += '- Advance year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'adv_Year';     
				  }
			 }
			 if(document.getElementById('adv_degree').value == '') 
			 {
				  errorString += '- Advance degree is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'adv_degree';     
				  }
			 }
			 
		}
	*/}
	
	if((document.getElementById('c_firm_name')) || (document.getElementById('c_from_year')) || (document.getElementById('c_to_year')))
	{
		
		if((document.getElementById('c_firm_name').value != '') || (document.getElementById('c_from_year').value != '') || (document.getElementById('c_to_year').value != ''))
		{
			 if(document.getElementById('c_firm_name').value == '') 
			 {
				  errorString += '- Current work history is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'c_firm_name';     
				  }
			 }
			 if(document.getElementById('c_from_year').value == '') 
			 {
				  errorString += '- Current work history from year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'c_from_year';     
				  }
			 }
			 if(document.getElementById('c_to_year').value == '') 
			 {
				  errorString += '- Current work history to year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'c_to_year';     
				  }
			 }
			 
			 if(document.getElementById('c_to_year').value < document.getElementById('c_from_year').value)
			 {
				  errorString += '- Current work to year can not be less then from year .\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'c_to_year';     
				  }
			 }
			 
		}
	}
	
	if((document.getElementById('pr_firm_name')) || (document.getElementById('pr_from_year')) || (document.getElementById('pr_to_year')))
	{
		
		if((document.getElementById('pr_firm_name').value != '') || (document.getElementById('pr_from_year').value != '') || (document.getElementById('pr_to_year').value != ''))
		{
			 if(document.getElementById('pr_firm_name').value == '') 
			 {
				  errorString += '- Prior work history is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'pr_firm_name';     
				  }
			 }
			 if(document.getElementById('pr_from_year').value == '') 
			 {
				  errorString += '- Prior work history from year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'pr_from_year';     
				  }
			 }
			 if(document.getElementById('pr_to_year').value == '') 
			 {
				  errorString += '- Prior work history to year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'pr_to_year';     
				  }
			 }
			 
			 if(document.getElementById('pr_to_year').value < document.getElementById('pr_from_year').value)
			 {
				  errorString += '- Prior work to year can not be less then from year .\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'pr_to_year';     
				  }
			 }
			 
		}
	}
	
	
		
//CODE ADEED BY VINEET	
	if(document.getElementById('cardNumber').value == '') 
	{
		  errorString += '- Credit Card Number is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'cardNumber';     
		  }
	}
    if(isNaN(document.getElementById('cardNumber').value))
    {
		errorString += '- Credit Card should be a number\n.';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'cardNumber';     
		  }	
	}
	if(document.getElementById('cexpirym').value == '') 
	{
		  errorString += '- Expiry Date Month is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'cexpirym';     
		  }
	}
	if(document.getElementById('cexpiryy').value == '') 
	{
		  errorString += '- Expiry Date Year is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'cexpiryy';     
		  }
	}
//END OF CODE 
	
	
	
	if(errorString == '')
    {
       return true; 
    }
   else
   {
        alert(MasterString+' \n '+errorString); 
        if(boolfocus)
        {
        	 document.getElementById(elementID).focus();
        }
        return false;   
    } 
	
	
}

function validLogin(formName)
{
	if(validateForm(formName,'userName','Username','R','password','Password','RisSpace'))
      {  
            return true;
      } 
      else 
      {
           return false;
      }	
}

function validChangePassword(formName)
{
	if(validateForm(formName,'oldPassword','Old Password','RisSpace','newPassword','New Password','RisSpace','confirmPassword','Confirm Password', 'RisEqualnewPassword:New Password'))
      {  
            return true;
      } 
      else 
      {
           return false;
      }	
}
function validNomination(formName)
{
	if(validateForm(formName,'firstName','First name','R','lastName','Last Name','R','professionId','Profession','R','phone','Phone','RisNaN','email','Email','R','companyName','Firm/Facility','R','street1','Address Line 1','R','city','City','R','stateId','State','R','postalCode','Zipcode','RisAlphaNum','nominatorFirstName','Nominator first name','R','nominatorLastName','Nominator last name','R','nominatorEmail','Nominator email','R'))
      {  
            return true;
      } 
      else 
      {
           return false;
      }
}
function validContactPage(formName)
{
	if(validateForm(formName,'name','Name','R','email','Email','RisEmail','phone','Phone','RisNaN'))
      {  
            return true;
      } 
      else 
      {
           return false;
      }
}

function validProfile(formName)
{
	
	var MasterString = getMasterString();
    var errorString = '';
    var boolfocus = false;
	if(document.getElementById('firstname').value == '') 
	{
		  errorString += '- First name is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'firstname';     
		  }
	}

	if(document.getElementById('lastname').value == '') 
	{
		  errorString += '- Last name is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'lastname';     
		  }
	}
	
	if(document.getElementById('professionId'))
	{
		if(document.getElementById('professionId').value == '') 
		{
			  errorString += '- Profession is required.\n';     
			  if(!boolfocus )
			  {
				boolfocus = true; 
				elementID = 'professionId';     
			  }
		}
	}
	
	if(document.getElementById('email'))
	{
		if(document.getElementById('email').value == '') 
		{
			  errorString += '- Email is required.\n';     
			  if(!boolfocus )
			  {
				boolfocus = true; 
				elementID = 'email';     
			  }
		}
	}
	
	if(document.getElementById('phone'))
	{
		if(document.getElementById('phone').value == '') 
		{
			  errorString += '- Phone is required.\n';     
			  if(!boolfocus )
			  {
				boolfocus = true; 
				elementID = 'phone';     
			  }
		}
	}
	
	if(document.getElementById('business'))
	{
		if(document.getElementById('business').value == '') 
		{
			  errorString += '- Firm/Faclity is required.\n';     
			  if(!boolfocus )
			  {
				boolfocus = true; 
				elementID = 'business';     
			  }
		}
	}
	
	if(document.getElementById('address1').value == '') 
	{
		  errorString += '- Address Line 1 is required.\n';     
		  if(!boolfocus )
		  {
			boolfocus = true; 
			elementID = 'address1';     
		  }
	}
	
	if(document.getElementById('city'))
	{
		if(document.getElementById('city').value == '') 
		{
			  errorString += '- City is required.\n';     
			  if(!boolfocus )
			  {
				boolfocus = true; 
				elementID = 'city';     
			  }
		}
	}
	
	if(document.getElementById('state'))
	{
		if(document.getElementById('state').value == '') 
		{
			  errorString += '- State is required.\n';     
			  if(!boolfocus )
			  {
				boolfocus = true; 
				elementID = 'state';     
			  }
		}
	}
	
	if(document.getElementById('zip'))
	{
		if(document.getElementById('zip').value == '') 
		{
			  errorString += '- Postal Code is required.\n';     
			  if(!boolfocus )
			  {
				boolfocus = true; 
				elementID = 'zip';     
			  }
		}
	}
	if((document.getElementById('ug_college')) || (document.getElementById('ug_Year')) || (document.getElementById('ug_degree')))
	{
		
		if((document.getElementById('ug_college').value != '') || (document.getElementById('ug_Year').value != '') || (document.getElementById('ug_degree').value != ''))
		{
			 if(document.getElementById('ug_college').value == '') 
			 {
				  errorString += '- Under graduate college is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'ug_college';     
				  }
			 }
			 if(document.getElementById('ug_Year').value == '') 
			 {
				  errorString += '- Under graduate year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'ug_Year';     
				  }
			 }
			 if(document.getElementById('ug_degree').value == '') 
			 {
				  errorString += '- Under graduate degree is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'ug_Year';     
				  }
			 }
			 
		}
	}
	
	if((document.getElementById('adv_college')) || (document.getElementById('adv_Year')) || (document.getElementById('adv_degree')))
	{
		
		if((document.getElementById('adv_college').value != '') || (document.getElementById('adv_Year').value != '') || (document.getElementById('ug_degree').value != ''))
		{
			 if(document.getElementById('adv_college').value == '') 
			 {
				  errorString += '- Advance college is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'adv_college';     
				  }
			 }
			 if(document.getElementById('adv_Year').value == '') 
			 {
				  errorString += '- Advance year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'adv_Year';     
				  }
			 }
			 if(document.getElementById('adv_degree').value == '') 
			 {
				  errorString += '- Advance degree is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'adv_degree';     
				  }
			 }
			 
		}
	}
	
	if((document.getElementById('c_firm_name')) || (document.getElementById('c_from_year')) || (document.getElementById('c_to_year')))
	{
		
		if((document.getElementById('c_firm_name').value != '') || (document.getElementById('c_from_year').value != '') || (document.getElementById('c_to_year').value != ''))
		{
			 if(document.getElementById('c_firm_name').value == '') 
			 {
				  errorString += '- Current work history is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'c_firm_name';     
				  }
			 }
			 if(document.getElementById('c_from_year').value == '') 
			 {
				  errorString += '- Current work history from year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'c_from_year';     
				  }
			 }
			 if(document.getElementById('c_to_year').value == '') 
			 {
				  errorString += '- Current work history to year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'c_to_year';     
				  }
			 }
			 
			 if(document.getElementById('c_to_year').value < document.getElementById('c_from_year').value)
			 {
				  errorString += '- Current work to year can not be less then from year .\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'c_to_year';     
				  }
			 }
			 
		}
	}
	
	if((document.getElementById('pr_firm_name')) || (document.getElementById('pr_from_year')) || (document.getElementById('pr_to_year')))
	{
		
		if((document.getElementById('pr_firm_name').value != '') || (document.getElementById('pr_from_year').value != '') || (document.getElementById('pr_to_year').value != ''))
		{
			 if(document.getElementById('pr_firm_name').value == '') 
			 {
				  errorString += '- Prior work history is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'pr_firm_name';     
				  }
			 }
			 if(document.getElementById('pr_from_year').value == '') 
			 {
				  errorString += '- Prior work history from year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'pr_from_year';     
				  }
			 }
			 if(document.getElementById('pr_to_year').value == '') 
			 {
				  errorString += '- Prior work history to year is required.\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'pr_to_year';     
				  }
			 }
			 
			 if(document.getElementById('pr_to_year').value < document.getElementById('pr_from_year').value)
			 {
				  errorString += '- Prior work to year can not be less then from year .\n';     
				  if(!boolfocus )
				  {
					boolfocus = true; 
					elementID = 'pr_to_year';     
				  }
			 }
			 
		}
	}
	
  if(errorString == '')
  {
       return true; 
  }
  else
  {
        alert(MasterString+' \n '+errorString); 
        if(boolfocus)
        {
        	 document.getElementById(elementID).focus();
        }
        return false;   
    } 
	
	
}
/***************************************** end here added by sumit for bestof us ***********************************/
function showCityUpgrade(str,city)
{
   
    document.getElementById("txtCity").innerHTML="<select name='city' id='city'><option>Loading...</option></select>"
    url="q="+str
    if(city !='')
    {
    url=url+"&city="+city;    
    }
    doAjax('getcity.php',url,'showCityListing' );    
}

function showCityListing(responseText)
{
    
    if(responseText)
    {
        document.getElementById("txtCity").innerHTML=responseText
    }
    else
    {
        document.getElementById("txtCity").innerHTML = "<select name='city' id='city'><option value=''>--select one--</option></select>"  
    }
}

function showSpecialityUpgrade(str, subcateg)
{
    document.getElementById("txtProfessionID").innerHTML="<select name='subCatId' class='text_box'><option>Loading...</option></select>"
    url="catID="+str+"&subcat="+subcateg;
    doAjax('getSpeciality2.php',url,'stateChangedSpeciality' );  
}

function stateChangedSpeciality(responseText) 
{ 
    if(responseText)
    {
        document.getElementById('txtProfessionID').innerHTML=responseText; 
    }
    else
    {
        document.getElementById("txtProfessionID").innerHTML="<select name='subCatId' class='text_box'><option value=''>--select one--</option></select>"        
    }    

}