/***************************************************************************/
/*     PROGRAMMER     :  DPT                                               */
/*     SCRIPT NAME    :  js.js					                           */
/*     CREATED ON     :  23/MAR/2005                                       */
/*     LAST MODIFIED  :  08/APR/2005									   */
/*     MODIFIED ON    :  08/APR/2005									   */
/*     MODIFIED BY    :  SDYA	  										   */
/*     MODIFIED ON    :  15/APR/2005									   */
/*     MODIFIED BY    :  DPT 	  										   */
/*     MODIFIED ON    :  28/APR/2005									   */
/*     MODIFIED BY    :  SDYA	  										   */
/*                                                                         */
/*     Java Script Functions For the Site                                  */
/***************************************************************************/

    /*----------------------------------------------------------------
    Description   :- function to validate add/edit job form
    Programmer    :- DPT
    Last Modified :- 23/MAR/2005
	Modified on	  :- 08/APR/2005
	Modified by   :- SDYA
    -------------------------------------------------------------------*/
	function job_validate()
    {
    	//job title
        if(document.frm_job.txt_title.value=="")
        {
        	alert("Please enter the job title");
            document.frm_job.txt_title.focus();
            return false;
        }
    	//job category
        if(document.frm_job.list_job_cate.value=="")
        {
        	alert("Please select the job category");
            document.frm_job.list_job_cate.focus();
            return false;
        }
    	//job experience level
        if(document.frm_job.list_exp_levl.value=="")
        {
        	alert("Please select the job experience level");
            document.frm_job.list_exp_levl.focus();
            return false;
        }
    	//job location
        if(document.frm_job.txt_location.value=="")
        {
        	alert("Please enter the job location");
            document.frm_job.txt_location.focus();
            return false;
        }
    	//job education requirement
        if(document.frm_job.txt_edu_req.value=="")
        {
        	alert("Please enter the job education requirement");
            document.frm_job.txt_edu_req.focus();
            return false;
        }
    	//job description
        if(document.frm_job.txta_description.value=="")
        {
        	alert("Please enter the job title");
            document.frm_job.txta_description.focus();
            return false;
        }
    	//job requirements
        if(document.frm_job.txta_requirements.value=="")
        {
        	alert("Please enter the job requirements");
            document.frm_job.txta_requirements.focus();
            return false;
        }
    	//job industry
        if(document.frm_job.cbo_industryid.value=="")
        {
        	alert("Please choose an industry");
            document.frm_job.cbo_industryid.focus();
            return false;
        }

        //validate salary
        if(isNaN(document.frm_job.txt_salary.value))
        {
        	alert("Please enter a valid salary");
         	document.frm_job.txt_salary.focus();
            return false;
        }
        return true;
    }

    /*----------------------------------------------------------------
    Description   :- function to confirm the status updating of a record
				     id1 and id2 are other extra ids which are to be passed
    Programmer    :- DPT
    Last Modified :- 3027/MAR/2005
    -------------------------------------------------------------------*/
    function updatestatusconfirm(page,name,id,status,id1,id2)
    {
        if(id1==undefined) id1 = 0;
        if(id2==undefined) id2 = 0;
    	if(confirm("Are you sure you want to update the status of this " + name + "?"))
        	window.location = page + "?id=" + id + "&status=" + status + "&name=" + name + "&id1=" + id1 + "&id2=" + id2;
    }

	/*----------------------------------------------------------------
    Description   :- function to show the calender on invite applicant page
    Programmer    :- DPT
    Last Modified :- 28/MAR/2005
    -------------------------------------------------------------------*/
	function show_calendar(obj)
	{
		gfPop.fStartPop(obj,Date);
	}

	/*----------------------------------------------------------------
    Description   :- function to validate invite applicant page
    Programmer    :- DPT
    Last Modified :- 27/MAR/2005
    -------------------------------------------------------------------*/
    function invite_validate()
    {
		//interview date
    	if(document.frm_invite.txt_interviewdate.value=="")
        {
	        alert("Please enter the date for interview");
            document.frm_invite.txt_interviewdate.focus();
			return false;
        }
		
		//start time
		if(document.frm_invite.cbo_starthour.value=="00" && document.frm_invite.cbo_startminute.value=="00")
		{
			alert("Please enter the stat time of the interview");
			document.frm_invite.cbo_starthour.focus();
			return false;
		}

		//end time
		if(document.frm_invite.cbo_endhour.value=="00" && document.frm_invite.cbo_endminute.value=="00")
		{
			alert("Please enter the end time of the interview");
			document.frm_invite.cbo_endhour.focus();
			return false;
		}

    	//interview
    	if(document.frm_invite.cbo_interviewid.value=="")
        {
	        alert("Please choose an interview");
            document.frm_invite.cbo_interviewid.focus();
			return false;
        }

        //message
       	if(document.frm_invite.txta_message.value=="")
        {
	        alert("Please enter your message");
            document.frm_invite.txta_message.focus();
			return false;
        }
    }

	/*----------------------------------------------------------------
    Description   :- function to validate add/edit interview
    Programmer    :- DPT
    Last Modified :- 28/MAR/2005
    -------------------------------------------------------------------*/
    function interview_validate()
    {
    	//interview title
        if(document.frm_interview.txt_title.value=="")
        {
        	alert("Please enter the interview title");
            document.frm_interview.txt_title.focus();
            return false;
        }
    	//interview title length
        if(document.frm_interview.txt_title.value.length>255)
        {
        	alert("Title can have maximum 255 characters");
            document.frm_interview.txt_title.focus();
            return false;
        }
    	//job
        if(document.frm_interview.cbo_jobid.value=="")
        {
        	alert("Please choose a job");
            document.frm_interview.cbo_jobid.focus();
            return false;
        }
    	//startdate
        if(document.frm_interview.txt_startdate.value=="")
        {
        	alert("Please enter the start date");
            document.frm_interview.txt_startdate.focus();
            return false;
        }
    	//enddate
        if(document.frm_interview.txt_enddate.value=="")
        {
        	alert("Please enter the end date");
            document.frm_interview.txt_enddate.focus();
            return false;
        }

    }

	/*----------------------------------------------------------------
    Description   :- function to reload the form once the user
    				choses the question type on add/edit question page
    Programmer    :- DPT
    Last Modified :- 30/MAR/2005
    -------------------------------------------------------------------*/
    function reloadform()
    {
        //sumit to the same form
        document.frm_question.action = "";
        document.frm_question.submit();
    }

	/*----------------------------------------------------------------
    Description   :- function to validate add/edit question form
    Programmer    :- DPT
    Last Modified :- 30/MAR/2005
    -------------------------------------------------------------------*/
    function question_validate()
    {
		//question typeid
        if(document.frm_question.cbo_questiontypeid.value=="")
        {
        	alert("Please choose the question type");
            document.frm_question.cbo_questiontypeid.focus();
            return false;
        }

		//question
        if(document.frm_question.txta_question.value=="")
        {
        	alert("Please enter the question");
            document.frm_question.txta_question.focus();
            return false;
        }

        //answer choices based on question type
        qtype = document.frm_question.cbo_questiontypeid.value;
        if(qtype==1 || qtype==2 || qtype==3 || qtype==4 || qtype==5 || qtype==9)
        {
            //answerchoices
            if(document.frm_question.txta_answerchoices.value=="")
            {
                alert("Please enter the answer choices");
                document.frm_question.txta_answerchoices.focus();
                return false;
            }
		}
        if(qtype==6 || qtype==7)
        {
            //rowchoices
            if(document.frm_question.txta_rowchoices.value=="")
            {
                alert("Please enter the row names");
                document.frm_question.txta_rowchoices.focus();
                return false;
            }
            //columnchoices
            if(document.frm_question.txta_columnchoices.value=="")
            {
                alert("Please enter the column names");
                document.frm_question.txta_columnchoices.focus();
                return false;
            }
        }

        return true;
    }

	/*----------------------------------------------------------------
    Description   :- show question type example help window
    Programmer    :- DPT
    Last Modified :- 30/MAR/2005
    -------------------------------------------------------------------*/
    function showquestiontypehelp(id)
    {
        if(id==undefined) id = 0;
        url = "questiontypes.php?id=" + id;
		nw = open(url,'QuestionTypesPreview','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=1,copyhistory=no,width=600,height=350')
        nw.focus();
    }

    /*----------------------------------------------------------------
    Description   :- function to validate staff add/edit form
    Programmer    :- DPT
    Last Modified :- 30/MAR/2005
    -------------------------------------------------------------------*/
    function staff_validate(id)
    {
    	//username
        if(document.frm_staff.txt_username.value=="")
        {
        	alert("Please enter the username");
            document.frm_staff.txt_username.focus();
            return false;
        }
        //while editing don't show password
        if(id==undefined)
        {
	        //password
	        if(document.frm_staff.txt_password.value=="")
	        {
	            alert("Please enter the password");
	            document.frm_staff.txt_password.focus();
	            return false;
	        }
        }
        return true;
    }

    /*----------------------------------------------------------------
    Description   :- function for search resume page
    Programmer    :- DPT
    Last Modified :- 31/MAR/2005
    -------------------------------------------------------------------*/
	function SelCountValidate()
    {	
		var testlen1 = document.advance_search.list_job_cate1.length;
	    var testlen2 = document.advance_search.list_lang1.length;
	    var ct = 0;
	    var ct1 = 0;
        for (i = 0; i < testlen1; i++)
	        if(document.advance_search.list_job_cate1[i].selected)
	        {
		        ct++;
	        }
	        if(ct >= 6)
	        {
	            alert("Select up to 5 categories that apply to the resume you are looking for.");
	            return false;
	        }
	        else
	        {
	            for (j = 0; j < testlen2; j++)
	                if(document.advance_search.list_lang1[j].selected)
	                {
		                ct1++;
	                }
	                if(ct1 >= 6)
	                {
	                    alert("Select up to 5 Languages that apply to the resume you are looking for.");
	                    return false;
	                }
	        }
    }

    /*----------------------------------------------------------------
    Description   :- function to validate the salesrepresentatives add/edit form
    Programmer    :- DPT
    Last Modified :- 06/APR/2005
    -------------------------------------------------------------------*/
    function salesrep_validate(id)
    {
        if(id==undefined) id = 0;

        //user name
        if(document.frm_users.txt_username.value=='')
        {
            alert("Please enter user name");
            document.frm_users.txt_username.focus();
            return false;
        }
        //this is only for addition
        if(!id)
        {
	        //password
	        if(document.frm_users.txt_password.value=='')
	        {
	            alert("Please enter password");
	            document.frm_users.txt_password.focus();
	            return false;
	        }
        }
        //first name
        if(document.frm_users.txt_fname.value=='')
        {
            alert("Please enter first name");
            document.frm_users.txt_fname.focus();
            return false;
        }
        //last name
        if(document.frm_users.txt_lname.value=='')
        {
            alert("Please enter last name");
            document.frm_users.txt_lname.focus();
            return false;
        }
        //country
        if(document.frm_users.cbocountry.value=='')
        {
            alert("Please select the country");
            document.frm_users.cbocountry.focus();
            return false;
        }
        //sales target recruiter
        if(document.frm_users.txt_recruiter_target.value=='')
        {
            alert("Please enter the sales target for recruiters");
            document.frm_users.txt_recruiter_target.focus();
            return false;
        }
        //sales target company
        if(document.frm_users.txt_company_target.value=='')
        {
            alert("Please enter the sales target for company");
            document.frm_users.txt_company_target.focus();
            return false;
        }
        //email id
        if(document.frm_users.txt_email.value=='')
        {
            alert("Please enter the email id");
            document.frm_users.txt_email.focus();
            return false;
        }
        return true;
    }

    /*----------------------------------------------------------------
    Description   :- function to validate the contact sales rep form
    Programmer    :- DPT
    Last Modified :- 06/APR/2005
    -------------------------------------------------------------------*/
    function contact_salesrep_validate()
    {
        //subject
        if(document.frm_contact.txt_subject.value=='')
        {
            alert("Please enter the subject");
            document.frm_contact.txt_subject.focus();
            return false;
        }
        //messagae
        if(document.frm_contact.txta_message.value=='')
        {
            alert("Please enter your message");
            document.frm_contact.txta_message.focus();
            return false;
        }

    }

    /*----------------------------------------------------------------
    Description   :- function to validate the company add/edit form
    Programmer    :- DPT
    Last Modified :- 06/APR/2005
    -------------------------------------------------------------------*/
    function company_manage_validate(id)
    {
        if(id==undefined) id = 0;

        //user name
        if(document.frm_users.txt_username.value=='')
        {
            alert("Please enter user name");
            document.frm_users.txt_username.focus();
            return false;
        }
        //this is only for addition
        if(!id)
        {
	        //password
	        if(document.frm_users.txt_password.value=='')
	        {
	            alert("Please enter password");
	            document.frm_users.txt_password.focus();
	            return false;
	        }
        }
        //first name
        if(document.frm_users.txt_fname.value=='')
        {
            alert("Please enter first name");
            document.frm_users.txt_fname.focus();
            return false;
        }
        //last name
        if(document.frm_users.txt_lname.value=='')
        {
            alert("Please enter last name");
            document.frm_users.txt_lname.focus();
            return false;
        }
        //country
        if(document.frm_users.cbocountry.value=='')
        {
            alert("Please select the country");
            document.frm_users.cbocountry.focus();
            return false;
        }
        //email id
        if(document.frm_users.txt_email.value=='')
        {
            alert("Please enter the email id");
            document.frm_users.txt_email.focus();
            return false;
        }
        return true;
    }

    /*----------------------------------------------------------------
    Description   :- function to confirm the selection of a bid
    Programmer    :- DPT
    Last Modified :- 08/APR/2005
    -------------------------------------------------------------------*/
    function confirm_select(id)
    {
    	//confirm
        if(confirm("Are you sure you want to select this bid?"))
        	window.location = "updatestatus_validate.php?name=bid&status=Selected&id=" + id;
    }

    /*----------------------------------------------------------------
    Description   :- function to confirm the rejection of a bid
    Programmer    :- DPT
    Last Modified :- 08/APR/2005
    -------------------------------------------------------------------*/
    function confirm_reject(id)
    {
    	//confirm
        if(confirm("Are you sure you want to reject this bid?"))
        	window.location = "updatestatus_validate.php?name=bid&status=Selected&id=" + id;
    }

    /*----------------------------------------------------------------
    Description   :- function to validate the postfeedback form
    Programmer    :- DPT
    Last Modified :- 11/APR/2005
    -------------------------------------------------------------------*/
    function postfeedback_validate()
    {
		//comments
        if(document.frm_feedback.txta_feedback.value=="")
        {
        	alert("Please enter your comments");
            document.frm_feedback.txta_feedback.focus();
            return false;
        }
        return true;
    }

    /*----------------------------------------------------------------
    Description   :- function to set the flags to identify which textbox is having the focus currently
    Programmer    :- DPT
    Last Modified :- 12/APR/2005
    -------------------------------------------------------------------*/
    function setflagforactiveobject(opt)
    {
		if(opt=="to")
        {
         	flag_toemailid = 1;
            flag_ccemailid = 0;
        }
        else
        {
        	flag_toemailid = 0;
            flag_ccemailid = 1;
        }
    }

    /*----------------------------------------------------------------
    Description   :- function to validate the send mail form
    Programmer    :- DPT
    Last Modified :- 12/APR/2005
    -------------------------------------------------------------------*/
    function sendmail_validate()
    {
    	//to
        if(document.frm_sendmail.txt_toemailid.value=='')
        {
        	alert("Please enter the to address");
            document.frm_sendmail.txt_toemailid.focus();
            return false;
        }

    	//subject
        if(document.frm_sendmail.txt_subject.value=='')
        {
        	alert("Please enter the subject");
            document.frm_sendmail.txt_subject.focus();
            return false;
        }
    	//message
        if(document.frm_sendmail.txta_message.value=='')
        {
        	alert("Please enter your message");
            document.frm_sendmail.txta_message.focus();
            return false;
        }
        return true;
    }

    /*----------------------------------------------------------------
    Description   :- function to confirm the deletion of an email
    Programmer    :- DPT
    Last Modified :- 12/APR/2005
    -------------------------------------------------------------------*/
    function mail_delete(id)
    {
    	//confirm the deletion of a mail
    	if(confirm("Are you sure you want to delete this mail from your inbox?"))
        	window.location = "delete_validate.php?id=" + id + "&name=message";
    }

    /*----------------------------------------------------------------
    Description   :- function to delete the selected emails from the inbox
    Programmer    :- DPT
    Last Modified :- 12/APR/2005
    -------------------------------------------------------------------*/
    function deleteemails()
    {
        //get all elements of the form
        for(i=0;i<document.frm_inbox.elements.length;i++)
        {
            //if not submit button
            if(document.frm_inbox.elements[i].type!="submit")
            {
    	    	//check whether selected
	            if((document.frm_inbox.elements[i].checked)) return true;

            }
        }
        alert("Please select the mail(s) to be deleted");
        return false;
    }

    /*----------------------------------------------------------------
    Description   :- function to get the selected contact from the addressbook list box and add it to the "To" field
    Programmer    :- DPT
    Last Modified :- 12/APR/2005
    -------------------------------------------------------------------*/
    function getcontact()
    {
    	//if focus is on "To"
        if(flag_toemailid)
        {
	        //if already any value is entered
	        if(document.frm_sendmail.txt_toemailid.value!='')
	            //then add to the list
	            document.frm_sendmail.txt_toemailid.value = document.frm_sendmail.txt_toemailid.value + ", " + document.frm_sendmail.list_addressbook.value;
	        else
	            document.frm_sendmail.txt_toemailid.value = document.frm_sendmail.list_addressbook.value;
		}
        else
        {
	        //if already any value is entered
	        if(document.frm_sendmail.txt_ccemailid.value!='')
	            //then add to the list
	            document.frm_sendmail.txt_ccemailid.value = document.frm_sendmail.txt_ccemailid.value + ", " + document.frm_sendmail.list_addressbook.value;
	        else
	            document.frm_sendmail.txt_ccemailid.value = document.frm_sendmail.list_addressbook.value;
        }
    }

    /*----------------------------------------------------------------
    Description   :- function to validate the attachment in send mail form
    Programmer    :- DPT
    Last Modified :- 12/APR/2005
    -------------------------------------------------------------------*/
    function attachment_validate()
    {
    	if(document.frm_sendmail.txt_attachment.value=='')
        {
        	alert("Please choose the attachment file");
            document.frm_sendmail.txt_attachment.focus();
            return false;
        }
        document.frm_sendmail.mode.value  = "attachment";
        document.frm_sendmail.submit();
    }

    /*----------------------------------------------------------------
    Description   :- function to remove an attachment from send mail form
    Programmer    :- DPT
    Last Modified :- 12/APR/2005
    -------------------------------------------------------------------*/
    function removeattachment(attachment)
    {
    	if(confirm("Are you sure you want to remove this attachment?"))
        {
        	document.frm_sendmail.mode.value = "remove";
            document.frm_sendmail.attachmentname.value = attachment;
            document.frm_sendmail.submit();
        }
        return false;

    }

    /*----------------------------------------------------------------
    Description   :- function to validate the report abuse form
    Programmer    :- DPT
    Last Modified :- 15/APR/2005
    -------------------------------------------------------------------*/
    function reportabuse_validate()
    {
		//comments
        if(document.frm_report.txta_comments.value=="")
        {
        	alert("Please enter your comments");
            document.frm_report.txta_comments.focus();
            return false;
        }
        return true;
    }