﻿/*  This class handles Visibility True or False for 'Other' fields    */
//dropDownPanelId                 -   Id of the container (works with Div) which holds Drop down and other text box.
CreateToggleOnChange = function(dropDownPanelId)
{  
    var dropDownListItem = $(dropDownPanelId + ' select')[0];
    var otherTextBox = $(dropDownPanelId + ' input')[0];
    var otherItem = $(dropDownPanelId + ' div')[1];
    //Default settings
    if($(dropDownListItem)[0].value == '10000' || $(dropDownListItem)[0].value.toLowerCase() == 'other')
    {
        $(otherItem).css({display:"block"});
    } 
    $(dropDownListItem).bind('change',function(){
        var selectedItemValue = $(this)[0].value;        
        if(selectedItemValue == '10000' || selectedItemValue.toLowerCase() == 'other')
        {                    
            otherTextBox.value = '';
            $(otherItem).css({display:"block"}); 
        }
        else
        {
            $(otherItem).css({display:"none"}); 
        }      
        return false;
    });
}

// To display mandatory icon dynamicaly for CancelAgreement page
 CreateDynamicToggleOnChange = function(dropDownPanelId,madatoryDiv,reqErrMsg,otherRequired)
{  
    var otherTextBox = $(dropDownPanelId + ' input')[0];
    var otherItem = $(dropDownPanelId + ' div')[1];
    var dropDownListItem = $(dropDownPanelId + ' select')[0];
    var mandatoryDiv = $(madatoryDiv + ' span')[0];
    var otherRequiredCtr = $('span#' + otherRequired)[0];
    if($(dropDownListItem)[0].value == '10000' || $(dropDownListItem)[0].value.toLowerCase() == 'other')
    {
        $(otherItem).css({display:"block"});
    } 
    //Default settings. need to change according to the reason for cancel table data
    if($(dropDownListItem)[0].value == 'GOTJOBTHROUGHSITE' || $(dropDownListItem)[0].value.toLowerCase() == 'got a job through the site')
    {
        $(mandatoryDiv).css({display:"inline"});
    } 
    $(dropDownListItem).bind('change',function(){
        var selectedItemValue = $(this)[0].value;
        $(reqErrMsg).text("");
         if(selectedItemValue == '10000' || selectedItemValue.toLowerCase() == 'other')
        {                    
            otherTextBox.value = '';
            $(otherItem).css({display:"block"});
              ValidatorEnable(otherRequiredCtr, true);
        }
        else
        {
            $(otherItem).css({display:"none"}); 
             ValidatorEnable(otherRequiredCtr, false);
        } 
                 
        if(selectedItemValue == 'GOTJOBTHROUGHSITE' || selectedItemValue.toLowerCase() == 'got a job through the site')
        {                    
            $(mandatoryDiv).css({display:"inline"}); 
        }
        else
        {
            $(mandatoryDiv).css({display:"none"}); 
        }      
        return false;
    });

}
 CheckRequiredData = function(submitButton,errMsg,dropDownPanelId,madatoryDiv)
    {
        var dropDownListItem = $(dropDownPanelId + ' select')[0];
        var companyName = $(madatoryDiv + ' input')[0];
        $(submitButton).bind('click', function(){
             if($(dropDownListItem)[0].value == 'GOTJOBTHROUGHSITE' || $(dropDownListItem)[0].value.toLowerCase() == 'got a job through the site')
                {                    
                   if(Trim(companyName.value) == "")
                   {
                       $(errMsg).text("Please provide a company name");
                       return false;
                   }
                   else
                   {
                        $(errMsg).text("");
                        return true;
                   }
                }
        });
    }
    

/*  This class handles Visibility True or False for  validation controls   */
CreateToggleOnChangeValidation = function(dropDownPanelId, requiredPanel, requiredControl, submitButton)
{  
    var dropDownListItem = $(dropDownPanelId + ' select')[0];
    var otherTextBox = $(dropDownPanelId + ' input')[0];
    var otherItem = $(dropDownPanelId + ' div')[1];
    var validationCtr = $(dropDownPanelId + ' div[@id*=' + requiredPanel + '] span[@id*=' + requiredControl + ']')[0];
    //Default settings
    var selectedItemValue = dropDownListItem.value;       
    $(dropDownListItem).bind('change',function(){
         var selectedItemValue = dropDownListItem.value;
        if(selectedItemValue.toLowerCase() == 'other' || selectedItemValue == 999)
        {   
            otherTextBox.value = '';
            $(otherItem).css({display:"block"}); 
            ValidatorEnable(validationCtr, true);
        }
        else
        {   
            $(otherItem).css({display:"none"}); 
            ValidatorEnable(validationCtr, false);
        }
        return false;
    });
}

//This function is to validate the industry list.
function validateIndustryList(source, arguments, industriesListControlApproxId, otherTextBoxApproxId, industryErrorMessage, otherIndustryErrorMessage)
{
     var isValid = false;
     var totalSelectedIndustries = $('table[@id*= '+ industriesListControlApproxId +'] td > input[@checked]').length;
     var selectedOtherIndustry = $('table[@id*= '+ industriesListControlApproxId +'] td label:contains("Other")').prev();
     var otherTextBox = $('input[@id*=' + otherTextBoxApproxId + ']');
     var validatorControl = $('#' + source.id)[0];
     if( totalSelectedIndustries == 0)
     {
        source.innerHTML = industryErrorMessage;
        validatorControl.errormessage = industryErrorMessage;
     }
     else if($(selectedOtherIndustry).attr("checked") && $(otherTextBox).val() == '')
     {
        source.innerHTML = otherIndustryErrorMessage;
        validatorControl.errormessage = otherIndustryErrorMessage;
     }
     else
     {
        isValid = true;
     }
     arguments.IsValid =  isValid;
}

/*  This class handles Visibility True or False for 'Other' fields    */
//checkBoxListPanelId                 -   Id of the container (works with Div) which holds Checkbox list(Table render format) and other text box.
CreateToggleOnClickCheckBox = function(checkBoxListPanelId)
{

    var otherCheckBoxItem = $(checkBoxListPanelId + ' table td label:contains("Other")').prev();
    if(otherCheckBoxItem.length == 0)
    {
        otherCheckBoxItem = $(checkBoxListPanelId + ' table td li:contains("Other") input');
    }
    var otherItem = $(checkBoxListPanelId + ' div.list-hold div')[1];
    
    if(typeof otherItem == "undefined")
    {
         otherItem = $(checkBoxListPanelId +' div')[1];
    }
    
    //Default settings

    if(!($(otherCheckBoxItem).attr("checked")))
    {
        if(typeof otherItem != "undefined")
        {
            $(otherItem).css({display:"none"});
        }
    } 
    
    var otherTextBox = $(checkBoxListPanelId + ' div label:contains("Other")').next();
    
    $(otherCheckBoxItem).bind('click', function()
    {
        if(this.checked)
        {                    
            $(otherTextBox).val("");
            $(otherItem).css({display:"block"}); 
        }
        else
        {
            $(otherItem).css({display:"none"}); 
        }      
    });
}

CreateToggleOnClickAll = function(selectAllApproxId, repeaterCheckItem, submitButton, errorMessage){
    $('input[@id*="'+ selectAllApproxId +'"]').bind('click', function(){
        if(this.checked)
        {
            $('input[@id*='+ repeaterCheckItem +']').attr("checked", function() { 
            return true; 
            });
        }
        else
        {
            $('input[@id*='+ repeaterCheckItem +']').attr("checked", function() { 
            return false; 
            });
        }
    });
    
    $('input[@id*='+ repeaterCheckItem +']').bind('click', function(){
        if(!this.checked)
        {
           $('input[@id*="'+ selectAllApproxId +'"]').attr("checked", function() { 
                return false; 
            });
        }
    });
    
    $('input[@id*="'+ submitButton +'"]').bind('click', function(){
        var isChecked = false;
        $('input[@id*='+ repeaterCheckItem +']').each(function(){
            if(this.checked){
                isChecked = true;
            }
        });
        if(!isChecked){
            alert(errorMessage);
            return false;
        }
    });
};

//Used to check the cover letter titles for duplicate
CheckCoverLetterTitle = function(buttonId, validationGroup, coverLetterTitleId, coverLetterBodyId, dropDownId, coverLetterTitleRequiredId){
    coverLetterBodyId = coverLetterBodyId + "_uxEditor";
    var submit = $('input#' + buttonId)[0];
    var coverLetterTitle = $('input#' + coverLetterTitleId)[0];
    var coverLetterBody = $('input#' + coverLetterBodyId)[0];
	var dropDown = $('select#' + dropDownId)[0];
	var coverLetterTitleRequired = $('span#' + coverLetterTitleRequiredId)[0];
	var isValid = true;
    $(submit).click(function(){
       if(Trim(coverLetterTitle.value) != "")
       {
            //ValidatorEnable(coverLetterTitleRequired, false);
            for( var index = 0 ; index < dropDown.options.length ; index ++ ){
                if(IsCoverLetterTitleExist(Trim(dropDown.options[index].text.toLowerCase()),Trim(coverLetterTitle.value.toLowerCase()))){
                    if(confirm('This title already exist.Do you wants to continue.') != 0){
                        return true;
                    }else{
                        return false;
                    }
                }
            }
        }
	});
};

//Used to get the cover letter body by making ajax call
GetCoverLetterBody = function(dropDownId, panelId , headingId, textAreaId, coverLetterTitleRequiredId, coverLetterBodyRequiredId){
    textAreaId = textAreaId + "_uxEditor";
    var dropDown = $("select#" + dropDownId)[0];
    var divPanel = $("div#" + panelId)[0];
    var headId = $("h2#" + headingId)[0];
    var textArea = $("input#" + textAreaId)[0];
    var fckEditor = $("iframe#" + textAreaId + "___Frame")[0];

    var coverLetterTitleRequired = $('span#' + coverLetterTitleRequiredId)[0];
    //var coverLetterBodyRequired = $('span#' + coverLetterBodyRequiredId)[0];
    var mandatoryTitle = $('#uxCoverLetterPanel span[@class="mandatory"]')[0];
    //Initial setup
    if(dropDown.selectedIndex == 0)
    {
        //$(mandatoryTitle).css({display:"block"}); 
    }
    $(dropDown).change(function(){
        if($(coverLetterTitleRequired)[0].style.display == 'inline')
        {
            //$(coverLetterTitleRequired).css({display:"none"}); 
        }
//        if($(coverLetterBodyRequired)[0].style.display == 'inline')
//        {
//            $(coverLetterBodyRequired).css({display:"none"}); 
//        }

		if(dropDown.selectedIndex > 0){
		    $(divPanel).css({display:"none"});
		    $(headId).css({display:"none"});
		    //$(mandatoryTitle).css({display:"none"}); 
		    $.ajax({
                type:"GET",
                url:"GetCoverLetterBody.ashx?cid=" + Trim(dropDown.value),
                success: function(request){
                    var response = null;
	                response = eval('(' + request + ')');
	                $(textArea)[0].value = response.CoverLetterBody;
	                fckEditor.src = fckEditor.src;
                },
                error: function(){
                    alert('You have an error.');
                }
            });
        }
        if(dropDown.selectedIndex == 0){
            $(mandatoryTitle).css({display:"block"}); 
            $(divPanel).css({display:"block"});  
            $(headId).css({display:"block"});
            coverLetterBodyEditor = FCKeditorAPI.GetInstance(textAreaId);
            $(textArea)[0].value = '';
            coverLetterBodyEditor.SetHTML('');
            //$(mandatoryTitle).css({display:"block"}); 
        }
	});
};

//Used to get the tooltip making ajax call
BindToolTips = function(){
    $("a.tooltip").each(function(){
        var toolTipAnchor = $(this)[0];
        var toopTipKey = $(this)[0].id;
        
        $(toolTipAnchor).bind('click',function(){
            $("#tool-tip").remove();
            var sourceArgs = this;
            
            $.ajax({
                type:"GET",
                url:"GetToolTip.ashx?tid=" + Trim(toopTipKey),
                success: function(request){
                    var response = null;
	                response = eval('(' + request + ')');
	                var toolTipHeading = response.ToolTipHead;
	                var toolTipContent = response.ToolTipText;
	                
	                var toolTipContainer = ($(sourceArgs)[0].parentNode).parentNode;
                    var toolTipContentStr = "<div class='tool-tip-content'>";
                    toolTipContentStr += "<p>" + toolTipContent + "</p>";
                    toolTipContentStr += "</div>";
                    
                    var toolTipHeadingStr = "<div class='tool-tip-hold'>";
                    toolTipHeadingStr += "<h6>" + toolTipHeading + "</h6>";            
                    toolTipHeadingStr += "</div>";
                    
                    var toolTipHeadingElement = $(toolTipHeadingStr);
                    
                    var toolTipCloseStr = "<a href='' class='tt-close'>Close</a>";
                    var toolTipCloseElement = $(toolTipCloseStr);
                    $(toolTipCloseElement).bind('click', function() {
                        $("#tool-tip").remove();
                        return false;
                    });
                    $(toolTipHeadingElement).append(toolTipCloseElement).append(toolTipContentStr);
                    
                    var toolTipHtmlStr = "<div class='tool-tip' id='tool-tip'>";
                    toolTipHtmlStr += "</div>";
                    
                    var toolTipHtml = $(toolTipHtmlStr);
                    $(toolTipHtml).append(toolTipHeadingElement);
                    
                    $(toolTipContainer).append(toolTipHtml);
	                
                },
                error: function(){}
            });
            return false;
        });
    });
}


//Used to match the cover letter title from cover letter title list
function IsCoverLetterTitleExist(dropDownTitle, title)
{
    if(!(/([%&()])/i.test(title)))
    {
        var strRegex = "((^" + title + "$)|(^" + title + "[(](\\d{1}|\\d{2}|\\d{3})[)]$))";
        var myRegex = new RegExp(strRegex);
        var rMatches = myRegex.exec(dropDownTitle);
        if(rMatches){
            return true;
        }else{
            return false;
        }
    }    	
}

//Used to trim the particular text
function Trim(TRIM_VALUE)
{  
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="") {
		return "";
	} else {
		return TRIM_VALUE;
	}
}

//Used to right trim the particular text
function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		
		}else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	}
	return strTemp;

} 

//Used to left trim the particular text
function LTrim(VALUE) 
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

/*  This class handles Visibility True or False for 'Login' fields (Default page)   */

CreateToggleOnClick = function(loginPanelId, longinDiv, cancelLoginLink, bgBlack)
{ 
    var loginButton = $(longinDiv + ' a')[0];
    var loginPanel = $(loginPanelId + ' div')[0];
    var closeButton = $(loginPanelId + ' a')[0];
    var cancelLogin = $(cancelLoginLink + ' a')[0];
    var bodyBg = $(bgBlack + ' img')[0];
    
    if (loginButton != undefined )
    {
        $(loginButton).bind('click',function(){
        $(loginPanel).css({display:"block"}); 
         $(bodyBg).css({display:"block"});    
            $(".validate").css({display:"none"});
            $(".text").val("");     
            return false;
        });
        
        $(closeButton).bind('click',function(){
        $(loginPanel).css({display:"none"}); 
         $(bodyBg).css({display:"none"});          
            return false;
        });
        
        $(cancelLogin).bind('click',function(){
        $(loginPanel).css({display:"none"}); 
         $(bodyBg).css({display:"none"});           
            return false;
        });
    }
}


/*  This class handles Visibility True or False for 'Upload Image' (Update Freelancer Details page)   */
CreateUploadToggleOnClick = function(uploadPanelId, uploadDiv)
{ 
    var uploadButton = $(uploadDiv + ' input')[0];
    var uploadPanel = $(uploadPanelId);
    var closeButton = $(uploadPanelId + ' a')[0];    
    
    if (uploadButton != undefined )
    {
        $(uploadButton).bind('click',function(){
        $(uploadPanel).css({display:"block"}); 
            return false;
        });
        
        $(closeButton).bind('click',function(){
        $(uploadPanel).css({display:"none"}); 
            return false;
        });
    }
}

// This class is for Client side custom validation - ManualEmailConfirm page -
function ClientValidate(txtInput1, txtInput2, txtInput3, txtInput4, txtInput5)
{  
     var numCheck = new RegExp(/^[0-9][0-9][0-9]$/);  //Create regular expression object.
     if(!numCheck.test($('#' + txtInput1).val()) || !numCheck.test($('#' + txtInput2).val()) || 
     !numCheck.test($('#' + txtInput3).val())|| !numCheck.test($('#' + txtInput4).val()) || 
     !numCheck.test($('#' + txtInput5).val()))
     {  
        return false;
    }
     else
     {
        return true;
     }      
}

//This function is to validate the client side validation for send to job alerts.
function validateSendJobAlertToList(source, arguments, jobAlertsListControl, minSelect, maxSelect, minErrorMessage, maxErrorMessage)
{
     var isValid = false;
     var totalSelectedJobAlertsCtr = $(jobAlertsListControl + " td > input")[0];
     var totalSelectedJobAlerts = $(jobAlertsListControl + " td > input[@checked]").length;
     totalSelectedJobAlertsCtr.focus();
     var validatorControl = $('#' + source.id)[0];
     if( totalSelectedJobAlerts < minSelect)
     {
        source.innerHTML = minErrorMessage;
        validatorControl.errormessage = minErrorMessage;
        totalSelectedJobAlertsCtr.focus();
     }
     else if(totalSelectedJobAlerts > maxSelect)
     {
        source.innerHTML = maxErrorMessage;
        validatorControl.errormessage = maxErrorMessage;
         totalSelectedJobAlertsCtr.focus();
     }
     else
     {
        isValid = true;
     }
     arguments.IsValid =  isValid;
}

//This function is to validate the work area list.
function validateWorkAreaList(source, arguments, workAreasListControlApproxId, otherTextBoxApproxId, regionErrorMessage, otherRegionErrorMessage)
{
     isValid = false;
     totalSelectedWorkAreas = $('table[@id*= '+ workAreasListControlApproxId +'] td > input[@checked]').length;
     selectedOtherWorkArea = $('table[@id*= '+ workAreasListControlApproxId +'] td label:contains("Other")').prev();
     otherTextBox = $('input[@id*=' + otherTextBoxApproxId + ']');
     var validatorControl = $('#' + source.id)[0];
     if( totalSelectedWorkAreas == 0)
     {
        source.innerHTML = regionErrorMessage;
        validatorControl.errormessage = regionErrorMessage;
        $('table[@id*= '+ workAreasListControlApproxId +'] td > input')[0].focus();
     }
     else if($(selectedOtherWorkArea).attr("checked") && $(otherTextBox).val() == '')
     {
        source.innerHTML = otherRegionErrorMessage;
        validatorControl.errormessage = otherRegionErrorMessage;
     }
     else
     {
        isValid = true;
     }
     arguments.IsValid =  isValid;
}

//This function is to validate the client side validation for FCK editor Max length and Min Length.
function ValidateFCKEditorRequired(source, arguments, MaxErrorMessage, RequiredErrorMessage)
{  
    var isValid = false;
    var editorInstance = FCKeditorAPI.GetInstance(source.controltovalidate);
    var maxLength = editorInstance.Config['MaxLength'];
    var visibleCharactersLeft = editorInstance.CharsLeft;
    
    if (visibleCharactersLeft != "undefined")
    {
        if (visibleCharactersLeft >= 0 && visibleCharactersLeft < maxLength)
        {
            isValid = true;
        }
        else if (visibleCharactersLeft < 0)
        {
            source.errormessage = MaxErrorMessage;
            source.innerHTML = MaxErrorMessage;
        }
        else
        {
            source.errormessage = RequiredErrorMessage;
            source.innerHTML = RequiredErrorMessage;
        }
    }
    
    arguments.IsValid =  isValid;
 }
 
//This function is to validate the client side validation for FCK editor only Max length.
function ValidateFCKEditor(source, arguments, MaxErrorMessage)
{  
    var isValid = false;
    var editorInstance = FCKeditorAPI.GetInstance(source.controltovalidate);
    var visibleCharactersLeft = editorInstance.CharsLeft;
    
    if (visibleCharactersLeft != "undefined")
    {
        if (visibleCharactersLeft >= 0)
        {
            isValid = true;
        }
        else
        {
            source.errormessage = MaxErrorMessage;
            source.innerHTML = MaxErrorMessage;
        }
    }
    arguments.IsValid =  isValid;
 }
 
    
HandleToggleItems = function(expandGroupClass, selectedGroupsItem)
{  
    var theInitialToggleObject = this;
    this.prevExpandedItem = 0;
    this.selectedGroupsItem = $(selectedGroupsItem);
    this.selectedIDs = new Array();
    this.groups = new Array();
    
    this.selectedIDs  = this.selectedGroupsItem[0].value.split(",");
    
    this.singleItems = function(){
       $('.'+expandGroupClass).each(function(){
           var expandGroup = $(this)[0];
           var headItem = $($(this)[0]).children(0)[0];
           var dataItem = $($(this)[0]).children(0)[1];
           
           theInitialToggleObject.groups.push($(expandGroup)[0].id);
           
           var expanded = false;           
           jQuery.each(theInitialToggleObject.selectedIDs, function(index, value) {
                if ( value == $(expandGroup)[0].id) 
                {
                    expanded = true;
                }
           });            
           if (!expanded) 
           {
                $(dataItem).hide();
                $('div#1a .expand-item').slideDown(500);               
                $('div#1a').removeClass("expand-group").addClass("expand-group selected");           
				
           }    
           else 
           {
                $(expandGroup).removeClass("expand-group").addClass("expand-group selected");              
           }       
           $(headItem).bind('click',function(){
                 if($(expandGroup)[0].className.indexOf('selected') == -1)
                 {
                    $(expandGroup).removeClass("expand-group").addClass("expand-group selected");
                    $(dataItem).slideDown();
                    var tabSetFocus = $('.' + dataItem.className + ' IFRAME')[0];
                    if (typeof tabSetFocus != "undefined")
                    {
                        tabSetFocus.contentWindow.focus();
                    }
                    theInitialToggleObject.Push($(expandGroup)[0].id);
                  }
                  else
                  {
                    $(expandGroup).removeClass("expand-group selected").addClass("expand-group");
                    $(dataItem).slideUp();
                    theInitialToggleObject.Pop($(expandGroup)[0].id);
                  }
            });         
        });     
    } 
     this.Push = function(item){
        var expanded = false;
        if(theInitialToggleObject.selectedIDs != null)
		{
            jQuery.each(theInitialToggleObject.selectedIDs, function(index, value) {
                if ( value == item) 
                {
                    expanded = true;
                }
            });
        }
        if (!expanded)
        {
			if(theInitialToggleObject.selectedIDs != null)
			{
				theInitialToggleObject.selectedIDs.push(item);
			}
            theInitialToggleObject.selectedGroupsItem[0].value = theInitialToggleObject.selectedIDs;
        }
    }
    
    this.Pop = function(item){
        theInitialToggleObject.selectedGroupsItem[0].value = "";
        jQuery.each(theInitialToggleObject.selectedIDs, function(index, value) {
            if ( value == item) 
            {
                theInitialToggleObject.selectedIDs.splice(index, 1);
            }
        });
        theInitialToggleObject.selectedGroupsItem[0].value = theInitialToggleObject.selectedIDs;
    }
    
     this.singleItemsTrasition = function(transitionSpeed){
       var theInitialObject = this; 
       this.transitionSpeed = transitionSpeed;
       theInitialToggleObject.prevExpandedItem = 0;
       $('.'+expandGroupClass).each(function(){
           var expandGroup = $(this)[0];
           var headItem = $($(this)[0]).children(0)[0];
           var dataItem = $($(this)[0]).children(0)[1];
           //$(dataItem).slideUp("normal");
           //$(expandGroup).removeClass("expand-group").addClass("expand-group selected");
           $(headItem).bind('click',function(){
                 if ( theInitialToggleObject.prevExpandedItem != $(expandGroup)[0].id || theInitialToggleObject.prevExpandedItem == 0)
                 {
                     $('.'+expandGroupClass + ' .expand-item').hide();
                     $('.'+expandGroupClass).removeClass("expand-group selected").addClass("expand-group");
                     theInitialToggleObject.prevExpandedItem = $(expandGroup)[0].id;
                 }
                 
                 if($(expandGroup)[0].className.indexOf('selected') == -1)
                 {
                    $(expandGroup).removeClass("expand-group").addClass("expand-group selected");
                    $(dataItem).slideDown(theInitialObject.transitionSpeed);
                  }
                 else
                  {
                    $(expandGroup).removeClass("expand-group selected").addClass("expand-group");
                    $(dataItem).slideUp(theInitialObject.transitionSpeed);
                  }
            });         
        });     
    } 
    this.maintainNamingAnchors = function(){
       // All the internal anchors which refer other section should have className in the format "int-[expand-group-id]"
       $('a[@class^=int-]').each(function(){
            $(this).bind('click',function(){
                var cName = this.className;
                var targetGroup = cName.substr(4);
                var dataItem = $($('#' + targetGroup)).children(0)[1];
                
                $('.'+expandGroupClass + ' .expand-item').hide();
                $('.'+expandGroupClass).removeClass("expand-group selected").addClass("expand-group");
                theInitialToggleObject.prevExpandedItem = targetGroup;
                 
                 if($("#" + targetGroup)[0].className.indexOf('selected') == -1)
                 {
                    $("#" + targetGroup).removeClass("expand-group").addClass("expand-group selected");
                    $(dataItem).show();
                  }
                 else
                  {
                    $("#" + targetGroup).removeClass("expand-group selected").addClass("expand-group");
                    $(dataItem).hide();
                  }
            });
        });     
    } 
    
    this.bindClickForToggleAllItems = function(expandCollapseDiv) {
        var expandCollapseItem = $('.' + expandCollapseDiv + ' a');
        var dataItem = $('.expand-group div.expand-item');
        //$(expandCollapseItem).text("- collapse all");
        $(expandCollapseItem).bind('click',function(){           
           
            var txt = $(this).text();
            if(txt.indexOf('+') != -1)
            {
                $('.' + expandGroupClass).removeClass("expand-group").addClass("expand-group selected");
                $(this).text("- collapse all");
                $(dataItem).show();
                theInitialToggleObject.selectedIDs = null;
                theInitialToggleObject.selectedIDs = theInitialToggleObject.groups;
            }
            else 
            {
                $('.' + expandGroupClass).removeClass("expand-group selected").addClass("expand-group");
                $(this).text("+ expand all");
                $(dataItem).hide();
                theInitialToggleObject.selectedIDs = null;
            }
        });
    }
}

/* ----------------------- Spell Checking ------------------- */

SpellChecker = function(spellCheckButton, editor){
    var i;
    editor = editor + "_uxEditor";
    i = editor;
    $(spellCheckButton).bind('click',function(){
        var descriptionBodyEditor = FCKeditorAPI.GetInstance(editor);

        var descriptionBody = descriptionBodyEditor.GetHTML();

        document.getElementById(editor).value = descriptionBody;
        if(Trim(descriptionBody) == "")
        {
            alert("Please Enter Some Text in Cover letter");
            return false;
        }
        else
        {        
           var newWindow = window.open('/SpellChecker.aspx?cnt=' + editor, "SpellChecker", "height=475,width=466,scrollbars=no,resizable=no,toolbars=no,status=no,menubar=no,location=center");     
           return false;              
        }
    });
}


function setEditorValue( instanceName, text )
{
    // Get the editor instance that we want to interact with.
    var oEditor = FCKeditorAPI.GetInstance( instanceName ) ;

    // Set the editor contents.
    oEditor.SetHTML( text ) ;
}

function popitup(url, name, options) {
	newwindow=window.open(url,name,options);
	if (window.focus) {newwindow.focus()}
	return false;
}





function preparePrevresults() {
    $(".previousPoll").hide();
    $(".open-prepoll").bind("click", function() {
        $(".previousPoll").animate({ opacity: "show" }, "slow");
    });

    $(".close-prepoll").bind("click", function() {
        $(".previousPoll").animate({ opacity: "hide" }, "slow");
    });
}

function HasAlreadyReceivedPopup(description) {
    return document.cookie.indexOf(description) > -1;
}
function ReceivedPopup(description, lifetime) {
    var date = new Date();
    date.setDate(date.getDate() + lifetime);
    document.cookie = description + "=true;expires=" + date.toUTCString() + ";path=/";
}
function DestroyPopup() {
    $("#sliding_popup").hide();
}