// for firefox, which doesn't find the document object sometimes...
if(!document)
{
    window.location.reload();
}


/**
* begin iframe resizing code
* The following is adapted from rasquis' posting at 10 March 05, 10:45am on
* http://www.geekforum.com/forum/forum_posts.asp?TID=347&PN=1&get=last
*/
function autoResizeIframe(iframe_obj)
{
    iframe_obj.scrolling = "no";
    
    /*
    var new_height;
    if (!window.opera && !document.mimeType && document.all && document.getElementById)
    {
        new_height = iframe_obj.contentWindow.document.body.offsetHeight;
    }
    else if(document.getElementById)
    {
        new_height = iframe_obj.contentWindow.document.body.scrollHeight;
    }
    */
    var new_height = iframe_obj.contentWindow.document.body.scrollHeight;
    
    iframe_obj.height = (new_height + 30) + "px";
}
/* end iframe resizing code */



/**
* Functions for moving data between the iframe and regular page
*/

// mode is either "add" or "edit"
function doActionOnRelatedIdInMainFrame(typesfield_id, record_id, mode)
{
    mode_input = document.getElementById('mode_'+typesfield_id);
    id_input = document.getElementById('id_'+typesfield_id);
    
    mode_input.value = mode;
    id_input.value = record_id;
    
    mode_input.form.action += "#rel_experience";
    mode_input.form.submit();
}


// changes from display to add or edit iframe
function changeDisplayToIframe(iframe_container_id, normal_content_id, url, clear_button_text)
{
    normal_content = document.getElementById(normal_content_id);
    normal_content.style.display = 'none';
    
    iframe_container = document.getElementById(iframe_container_id);
    iframe_container.style.display = 'block';
    iframe_container.innerHTML = '<iframe src="'+url+'" onload="autoResizeIframe(this)" width="100%" height="350" frameborder="0"></iframe> <input type="button" value="'+clear_button_text+'" onclick="clearIframeDisplay(\''+iframe_container_id+'\', \''+normal_content_id+'\')" />';
}


function clearIframeDisplay(iframe_container_id, normal_content_id)
{
    iframe_container = document.getElementById(iframe_container_id);
    iframe_container.style.display = 'none';
    
    normal_content = document.getElementById(normal_content_id);
    normal_content.style.display = 'block';
}


function deleteExperience(typesfield_id, record_id)
{
    if (confirm('¿Desea eliminar esta experiencia?'))
    {
        doActionOnRelatedIdInMainFrame(typesfield_id, record_id, 'delete');
    }
}



