function openRefineBox()
{
	var div = document.getElementById('refine_industry');
	var img = document.getElementById('arrowimg'); 
	if (div.style.display == 'block') {
		div.style.display  = 'none';
		img.src = 'http://www.arabianbusiness.com/pictures/jobs/arrow_white_down.gif'; 
	} else {
		div.style.display  = 'block';
		img.src = 'http://www.arabianbusiness.com/pictures/jobs/arrow_white_up.gif'; 
	}
}

function validate ()
{
	if (document.getElementById('UserUresume').value == "" &&
		document.getElementById('UserResume').value == "") {
		alert('You must upload your resume or paste it in the designated area');
		return false;
	}
	return true;
}

function changeBasket(id)
{
	var link = document.getElementById(id);
	if (link.innerHTML.match('[+]') == null) {
		link.innerHTML = '+&nbsp;Add to shortlist';		
	} else {
		link.innerHTML = '-&nbsp;Remove from shortlist';	
	}
}


function isEditView(id)
{   
    return $(id).hasClassName('ontop');
}

function changeResumeView(view)
{   var id = 'resume';
    var className = 'ontop';
    
    $(id).immediateDescendants().each( function(obj) {
            if(obj.tagName == 'DIV') 
            {
                if(view=='edit')
                    obj.addClassName(className);
                else if(view=='full')
                {   if(obj.hasClassName(className)) 
                        obj.removeClassName(className);
                    
                    deactivateForm(obj.id); 
                    
                }
            } 
        } 
    );
    
    
    //Arrange labels
    $('buildcv_header').descendants().each( function(obj) {
            
            if(obj.tagName == 'A')
            {   
                if(obj.href.substr(-1,1) == '#')
                {   var text = obj.firstChild.data; // .text didn't work with IE
                    var label = text.toLowerCase().gsub(/\s+/,"_");
                    obj.href = obj.href.gsub(/#$/,"#" + label);
                }
                else
                    obj.href = '#';
            }
        }
    );
}


function activateResumeSection(id)
{   
    var curr_obj = $(id);
    var activeClass = 'active';
    
    //remove the active class from other divs 
    curr_obj.siblings().each( function(obj) {
            obj.removeClassName(activeClass);
        } 
     );
     
    //enable active class for this div
    curr_obj.addClassName(activeClass);
    
   
    if( isEditView(id) )
    {    
        activateForm(id);
    }
    
}

function deactivateForm(container_id)
{   
    var activeClass = 'active';
    
    //disable all the other active input fields
    $A($(container_id).getElementsByTagName('form')).each(function(form) {
        form.getElements().each(function(element) {
            element.removeClassName(activeClass);
            element.blur();
            element.disabled = 'true';
      });
    });
    
}

function activateForm(id)
{   
    if(!isEditView(id))
        return;
        
    var curr_obj = $(id);
    var activeClass = 'active';
 
    //enable the input fields for the current div if it's the edit view
    deactivateForm('resume');
        
    $A($(id).getElementsByTagName('form')).each(function(form) {
        
        form.getElements().each( function(element) { 
            element.addClassName(activeClass);
            element.disabled = '';
        });
    });
        
}

function editResume(id) 
{   
    var activeClass = 'active';
    var curr_obj = $(id);
    
    changeResumeView('edit');
   // $('save_' + id).display = 'block';
    
    activateForm(id);
    activateResumeSection(id);
}

function resumeSaveStatus(id,check,str)
{   
    var resume = $('resume_status');
    var response = $('resume_section_id').firstChild.data;
     
    //first form
    var form = $A($(id).getElementsByTagName('form'))[0]; 
 
    if(response == 'Error')
    {    
        resume.update(response);
    }        
    
    else if(check==0)
    {
        str = 'Saving ' + str + '...';
        resume.className = 'saving';
        form.disable();
        resume.update(str);
    }
    else
    {   str = 'Saved ' + str;
        resume.className = 'saved';
        resume.update(str);
        
        var input = '';
        //check for Id hidden field
        form.getInputs('hidden').each( function(element) {
            if(element.id.substr((element.id.length-2),2) == 'Id' )
            {   input = element;
                return;
            }
        });
        
        input.value = response;

        changeResumeView('full');
    }
}


function resumeDateSet(obj, targetId)
{   
    var targetObj = $(targetId);
  
    var _list = Array('Year','Month','Day');
    
    //change current target value 
    var targetDate = targetObj.value.split('-');
    
    for(var i=0,lim=_list.length; i<lim; i++)
    {   if(obj.id == targetId + _list[i])
            targetDate[i] = obj.value; 
    }    
    
    targetObj.value = targetDate.join('-');
    
    return;
    
}

function submitBasketForm()
{
	if (validateForm(document.basketForm)) {
		document.basketForm.submit();
	}
}

//=====================================================================
//  DOM Image Rollover v3 (hover)
//
//  Demo: http://chrispoole.com/scripts/dom_image_rollover_hover
//  Script featured on: Dynamic Drive (http://www.dynamicdrive.com)
//=====================================================================
//  copyright Chris Poole
//  http://chrispoole.com
//  This software is licensed under the MIT License 
//  <http://opensource.org/licenses/mit-license.php>
//=====================================================================

function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}