/*
Copyright 2002-2008 Bitmixsoft.com
*/

function cross_network_code(div_reload) {

    code='';
    var code_tmp='';
    if (typeof(div_reload)=='undefined') {
        div_reload=false;
    }

    code+='<!-- gotomyjob latest jobs -->'+'\n';
    code+='<div id="gotomyjob_latest_jobs">'+'\n';
    gotomyjob_latest_nr=document.getElementById('g_latest_nr');
    gotomyjob_latest_bg_color=document.getElementById('g_latest_bg_color');
    gotomyjob_latest_title_color=document.getElementById('g_latest_title_color');
    gotomyjob_latest_location_color=document.getElementById('g_latest_location_color');
    gotomyjob_latest_company_color=document.getElementById('g_latest_company_color');
    gotomyjob_latest_description_color=document.getElementById('g_latest_description_color');
    if (gotomyjob_latest_nr.value!='') {
        //code_tmp+="gotomyjob_latest_nr='"+gotomyjob_latest_nr.value+"';"+"\n"
    }
    if (gotomyjob_latest_bg_color.value!='') {
        code_tmp+="gotomyjob_latest_bg_color='"+gotomyjob_latest_bg_color.value+"';"+"\n"
    }
    if (gotomyjob_latest_title_color.value!='') {
        code_tmp+="gotomyjob_latest_title_color='"+gotomyjob_latest_title_color.value+"';"+"\n"
    }
    if (gotomyjob_latest_location_color.value!='') {
        code_tmp+="gotomyjob_latest_location_color='"+gotomyjob_latest_location_color.value+"';"+"\n"
    }
    if (gotomyjob_latest_company_color.value!='') {
        code_tmp+="gotomyjob_latest_company_color='"+gotomyjob_latest_company_color.value+"';"+"\n"
    }
    if (gotomyjob_latest_description_color.value!='') {
        code_tmp+="gotomyjob_latest_description_color='"+gotomyjob_latest_description_color.value+"';"+"\n"
    }

    if (code_tmp!='') {
        code+='<'+'script language="'+'Javascript">'+'\n'+'<!--'+'\n';
        code+=code_tmp;
        code+='//--'+'>'+'\n'+'<'+'/script>'+'\n';
    }
    //code+='<script type="text/javascript" src="'+http_server+'js/latest_jobs_xml.js"></script>'+'\n';
    if (gotomyjob_latest_nr.value!='') {
        jobs_nr_tmp=gotomyjob_latest_nr.value;
    }else {
        jobs_nr_tmp=30;
    }
    code+='<script type="text/javascript" src="'+http_server+'latest_jobs_xml/'+jobs_nr_tmp+'/js/"></script>'+'\n';
    code+='</div>'+'\n';
    code+='<!-- end gotomyjob latest jobs -->';
    document.getElementById('cross_network_code').value=code;

    code_preview(div_reload);
}

function code_preview(div_reload) {
    var div_id='code_preview1';
    if (div_reload!=true && typeof(new_content_tmp)!='undefined') { //data already loaded and not reload
        new_content_tmp=change_style_preview(new_content_tmp);
        document.getElementById(div_id).innerHTML=new_content_tmp;
    }else{
        var preview_url=http_server+'latest_jobs_xml/'
        if (gotomyjob_latest_nr.value!='') {
            preview_url+=gotomyjob_latest_nr.value+'/'
        }else {
            preview_url+='30/';
        }
        preview_url+=new Date().getTime();//no cache
        ajax_content_preview(preview_url,div_id);
    }
    return;
}

function ajax_content_preview(url, div_id){
    var http_request = false
    if (window.XMLHttpRequest) // Mozilla, Safari etc
        http_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e){
            try{
                http_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e){}
        }
    }
    else
        return false

    http_request.onreadystatechange=function(){
        loadpage_preview(http_request, div_id)
    }
    http_request.open('GET', url, true)
    http_request.send(null)
}

function loadpage_preview(http_request, div_id){
    if (http_request.readyState == 4 && (http_request.status==200 || window.location.href.indexOf("http")==-1)) {
        var new_content=http_request.responseText;
        new_content=http_request.responseText;
        new_content_tmp=new_content;
        new_content=change_style_preview(new_content);
        document.getElementById(div_id).innerHTML=new_content;
    }
}

function change_style_preview(str) {
    if (gotomyjob_latest_bg_color.value!='') {
        str=str.replace(/class="div_xml"/,'class="div_xml" style="background-color:'+gotomyjob_latest_bg_color.value+'"');
    }
    if (gotomyjob_latest_title_color.value!='') {
        //str=str.replace(/class="div_xml_href"/g,'class="div_xml_title" style="color:'+gotomyjob_latest_title_color.value+'"');
        str=str.replace(/class="div_xml_href"/g,'class="div_xml_href" style="color:'+gotomyjob_latest_title_color.value+'"');
    }
    if (gotomyjob_latest_description_color.value!='') {
        str=str.replace(/class="div_xml_description"/g,'class="div_xml_description" style="color:'+gotomyjob_latest_description_color.value+'"');
    }
    if (gotomyjob_latest_company_color.value!='') {
        str=str.replace(/class="div_xml_company"/g,'class="div_xml_company" style="color:'+gotomyjob_latest_company_color.value+'"');
    }
    if (gotomyjob_latest_location_color.value!='') {
        str=str.replace(/class="div_xml_location"/g,'class="div_xml_location" style="color:'+gotomyjob_latest_location_color.value+'"');
    }
    return str;
}
