if (top.location != location) top.location.href = location.href;

var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined'); 
var ie = (typeof window.ActiveXObject != 'undefined');

var lang_array = [ ["HUN","magyar"],["ENG","angol"],["GER","német"],["FRA","francia"],["RUS","orosz"],["ITA","olasz"],
							 	 	 ["SPA","spanyol"],["POR","portugál"],["ELL","görög"],["ARA","arab"],["CHI","kínai"],["JPN","japán"],["FAS","perzsa"],
									 ["HIN","hindi"],["CES","cseh"],["SLK","szlovák"],["RON","román"],["POL","lengyel"],["EPO","eszperanto"],
									 ["FIN","finn"],["SWE","svéd"],["NOR","norvég"],["NLA","holland"]
							 	 ];		
var personal_array = ["FIRSTNAME","LASTNAME","BIRTH","NATIONALITY","MOTHERTONGUE","IMAGE","COUNTRY","CITY","POSTALCODE","STREET","EMAIL","WEB","PHONE","MOBILE"];
								 
var educations = 0;
var works = 0;
var languages = 0;
var personalskills = 0;
var otherskills = 0;

// Education & Work
function addRow(type){
 
if(type == 'E'){
 elem1 = 'ORGANIZATION';
 elem2 = 'TITLE';
 elem3 = 'SUBJECT'
 title1 = 'Iskola/Szervezet';
 title2 = 'Végzettség';
 title3 = 'Megszerzett ismeretek';
 educations += 1;
 elemnum = educations;
 ol = "E";
} else if (type == 'W'){
 elem1 = 'EMPLOYER';
 elem2 = 'POSITION';
 elem3 = 'ACTIVITIES'
 title1 = 'Munkahely';
 title2 = 'Pozíció';
 title3 = 'Tevékenység';
 works += 1;
 elemnum = works;
 ol = "W";
}

var li = document.createElement("li");
li.setAttribute("id", type + "_" + elemnum);

var div = document.createElement("div");
div.className = "r";

var button = document.createElement("input");
button.setAttribute("type", "button");
button.setAttribute("value"," - ");
button.setAttribute("title","Adat törlése");
button.setAttribute("id", "R" + type +"_" + elemnum);
button.className = "button";
addEvent(button,"click",delRow);

div.appendChild(button);

var div0 = document.createElement("div");
var div1 = document.createElement("div");
var div2 = document.createElement("div");
var div3 = document.createElement("div");
div0.className = "r";
div1.className = "r";
div2.className = "r";
div3.className = "r";

var label0 = document.createElement("label");
var label1 = document.createElement("label");
var label2 = document.createElement("label");
var label3 = document.createElement("label");

label0.className = "lol";
label1.className = "lol";
label2.className = "lol";
label3.className = "lol";
label0.innerHTML  = "Mett&#337;l / Meddig";
label1.innerHTML = title1;
label2.innerHTML = title2;
label3.innerHTML = title3;


div0.appendChild(label0);
div1.appendChild(label1);
div2.appendChild(label2);
div3.appendChild(label3);


var input_from = document.createElement("input");
var input_to = document.createElement("input");
input_from.setAttribute("type", "text");
input_to.setAttribute("type", "text");

input_from.setAttribute("id",type + "_" + elemnum + "_FROM");
input_from.setAttribute("name",type + "_" + elemnum + "_FROM");
input_to.setAttribute("id",type + "_" + elemnum + "_TO");
input_to.setAttribute("name",type + "_" + elemnum + "_TO");

input_from.className="half";
input_to.className="half";

div0.appendChild(input_from);
div0.appendChild(document.createTextNode(" "));
div0.appendChild(input_to);


var input1 = document.createElement("input");
input1.setAttribute("type", "text");
input1.setAttribute("id",type + "_" + elemnum + "_" + elem1);
input1.setAttribute("name",type + "_" + elemnum + "_" + elem1);
div1.appendChild(input1);

var input2 = document.createElement("input");
input2.setAttribute("type", "text");
input2.setAttribute("id", type + "_" + elemnum + "_" + elem2);
input2.setAttribute("name", type + "_" + elemnum + "_" + elem2);
div2.appendChild(input2);

var input3 = document.createElement("textarea");
input3.setAttribute("cols", "40");
input3.setAttribute("rows", "5");
input3.setAttribute("id", type + "_" + elemnum + "_" + elem3);
input3.setAttribute("name", type + "_" + elemnum + "_" + elem3);
div3.appendChild(input3);

div.appendChild(div0);
div.appendChild(div1);
div.appendChild(div2);
div.appendChild(div3);

li.appendChild(div);
var ol = document.getElementById(type);
ol.appendChild(li);

}

function delAll(type){
		ol = document.getElementById(type);
		while(ol.hasChildNodes()){
			ol.removeChild(ol.firstChild);
		}
}

function delRow(e){
 if(confirm("Biztos, hogy letörölhetem?")){
 var targ;
 if (!e) var e = window.event;
 if (e.target) targ = e.target;
 else if (e.srcElement) targ = e.srcElement;

elem = targ.id.substring(1);
p_elem = elem.substring(0,1);

li = document.getElementById(elem);
ol = document.getElementById(p_elem);
ol.removeChild(li);
}
}

function addLanguage(){
languages += 1;
var li = document.createElement("li");
li.setAttribute("id", "L_" + languages);
li.setAttribute("name", "L_" + languages);

var div = document.createElement("div");
div.className = "r";

var button = document.createElement("input");
button.setAttribute("type", "button");
button.setAttribute("value"," - ");
button.setAttribute("title","Adat törlése");
button.setAttribute("id", "RL_" + languages);

button.className = "button";
addEvent(button,"click",delRow);

div.appendChild(button);

var select_lang = document.createElement("select");
select_lang.className = "lang";
select_lang.setAttribute("id", "L_" + languages + "_LANG");
select_lang.setAttribute("name", "L_" + languages + "_LANG");

for(i=0;i<lang_array.length;i++){
 o=document.createElement("option")
 o.innerHTML = lang_array[i][1];
 o.value = lang_array[i][0];
 select_lang.appendChild(o);
 }


var select_reading = document.createElement("select");
select_reading.setAttribute("id", "L_" + languages + "_READING");
select_reading.setAttribute("name", "L_" + languages + "_READING");
var select_writing = document.createElement("select");
select_writing.setAttribute("id", "L_" + languages + "_WRITING");
select_writing.setAttribute("name", "L_" + languages + "_WRITING");
var select_verbal = document.createElement("select");
select_verbal.setAttribute("id", "L_" + languages + "_VERBAL");
select_verbal.setAttribute("name", "L_" + languages + "_VERBAL");

for(i=1;i<6;i++){
 or=document.createElement("option")
 or.innerHTML = i;
 or.setAttribute("value",i);
 
 ow=document.createElement("option")
 ow.innerHTML = i;
 ow.setAttribute("value",i);
 
 ov=document.createElement("option")
 ov.innerHTML = i;
 ov.setAttribute("value",i);

 select_reading.appendChild(or);
 select_writing.appendChild(ow);
 select_verbal.appendChild(ov);
}

div.appendChild(select_lang);
div.appendChild(document.createTextNode("  Olvasás: "));
div.appendChild(select_reading);
div.appendChild(document.createTextNode(" Írás: "));
div.appendChild(select_writing);
div.appendChild(document.createTextNode(" Beszéd: "));
div.appendChild(select_verbal);

li.appendChild(div)
var ol = document.getElementById("L");
ol.appendChild(li);

}

function addSkill(type){
if(type == 'P'){
personalskills += 1;
skill = personalskills;
} else if(type=='O'){
otherskills += 1;
skill = otherskills;
}

var li = document.createElement("li");
li.setAttribute("id", type + "_" + skill);
li.setAttribute("name", type + "_" + skill);

var div = document.createElement("div");
div.className = "r";

var button = document.createElement("input");
button.setAttribute("type", "button");
button.setAttribute("value"," - ");
button.setAttribute("title","Adat törlése");
button.setAttribute("id", "R" + type + "_" + skill);
button.className = "button";
addEvent(button,"click",delRow);

var input;
if(type == 'P'){
input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("id",type + "_" + skill + "_S");
input.setAttribute("name",type + "_" + skill + "_S");
} else if(type=='O'){
input = document.createElement("textarea");
input.setAttribute("cols", "40");
input.setAttribute("rows", "3");
input.setAttribute("id", type + "_" + skill + "_S");
input.setAttribute("name", type + "_" + skill + "_S");
}

div.appendChild(button);
div.appendChild(input)

var a_div = li.appendChild(div);
var ol = document.getElementById(type);
var a_li = ol.appendChild(li);
}


function addEvent(obj, event, handler) { 
 if (obj.addEventListener) 
   obj.addEventListener(event, handler, false); 
 else if (obj.attachEvent) 
   obj.attachEvent("on" + event, handler); 
}

function v(elem){
var e = document.getElementById(elem);
return e.value;
}

function vt(elem){
var e = document.getElementById(elem);
return e.innerHTML;
}


function generate(){
area = document.getElementById("source");

v_language = v("LANG");
v_goal = vt("GOAL"); 
 
area.value = "<?xml version=\"1.0\" encoding=\"ISO-8859-2\"?>\n";
area.value += "<?xml-stylesheet type=\"text/xsl\" href=\"xcv_" + v_language.toLowerCase() +".xsl\"?>\n";
area.value += "<!--\n\n(C) Copyright 2004 - xcv.hu - Az Ön életrajza\n\n";
area.value += " -->\n";
area.value += "<XCV VERSION=\"1.03\" LANGUAGE=\"" + v_language + "\" >\n";
area.value += "\n<PERSONAL>\n";

for(i=0;i<personal_array.length;i++){
	 if(v(personal_array[i]) != "") area.value += " <" + personal_array[i] +">" + v(personal_array[i]) + "</"+personal_array[i]+">\n";
}
area.value += "</PERSONAL>\n";
if(v_goal != "" ) area.value += "\n<GOAL>" + v_goal + "</GOAL>\n";

ol = document.getElementById("W");
if(ol.childNodes.length > 0){
area.value += "\n<WORKS>\n";

for(j=0;j<ol.childNodes.length;j++){
id = ol.childNodes[j].id.substring(2);
area.value += "<WORK>\n";
area.value += " <FROM>"+ v("W_"+id+"_FROM") + "</FROM>\n";
area.value += " <TO>"+ v("W_"+id+"_TO") + "</TO>\n";
area.value += " <EMPLOYER>"+ v("W_"+id+"_EMPLOYER") + "</EMPLOYER>\n";
area.value += " <POSITION>"+ v("W_"+id+"_POSITION") + "</POSITION>\n";
area.value += " <ACTIVITIES>"+ v("W_"+id+"_ACTIVITIES") + "</ACTIVITIES>\n";
area.value += "</WORK>\n";
}
area.value += "</WORKS>\n";
}

ol = document.getElementById("E");
if(ol.childNodes.length > 0){
area.value += "\n<EDUCATIONS>\n";

for(j=0;j<ol.childNodes.length;j++){
id = ol.childNodes[j].id.substring(2);
area.value += "<EDUCATION>\n";
area.value += " <FROM>"+ v("E_"+id+"_FROM") + "</FROM>\n";
area.value += " <TO>"+ v("E_"+id+"_TO") + "</TO>\n";
area.value += " <ORGANIZATION>"+ v("E_"+id+"_ORGANIZATION") + "</ORGANIZATION>\n";
area.value += " <TITLE>"+ v("E_"+id+"_TITLE") + "</TITLE>\n";
area.value += " <SUBJECT>"+ v("E_"+id+"_SUBJECT") + "</SUBJECT>\n";
area.value += "</EDUCATION>\n";
}
area.value += "</EDUCATIONS>\n";
}


ol = document.getElementById("L");
if(ol.childNodes.length > 0){
area.value += "\n<LANGUAGES>\n";

for(j=0;j<ol.childNodes.length;j++){
id = ol.childNodes[j].id.substring(2);
area.value += "<LANGUAGE LANG=\"" + v("L_"+id+"_LANG") +  "\" READING=\"" + v("L_"+id+"_READING") + "\" ";
area.value += "WRITING=\"" + v("L_"+id+"_WRITING") + "\" VERBAL=\"" + v("L_"+id+"_VERBAL") + "\"/>\n";
}
area.value += "</LANGUAGES>\n";
}


ol = document.getElementById("P");
if(ol.childNodes.length > 0){
area.value += "\n<PERSONALSKILLS>\n";
for(j=0;j<ol.childNodes.length;j++){
id = ol.childNodes[j].id.substring(2);
if(v("P_"+id + "_S") != "") area.value += " <SKILL>" + v("P_"+ id + "_S") + "</SKILL>\n";
}
area.value += "</PERSONALSKILLS>\n";
}

ol = document.getElementById("O");
if(ol.childNodes.length > 0){
area.value += "\n<OTHERSKILLS>\n";
for(j=0;j<ol.childNodes.length;j++){
id = ol.childNodes[j].id.substring(2);
if(v("O_"+id + "_S") != "") area.value += " <SKILL>" + v("O_"+id + "_S") + "</SKILL>\n";
}
area.value += "</OTHERSKILLS>\n";
}
area.value += "\n</XCV>\n";
}

function clp(obj){
	obj.focus();
	obj.select();
	if(ie){
		obj.createTextRange().execCommand("Copy");
	}else{
		alert("- Jelölje ki a teljes szöveget.  (Control + A) \n\n- Másolja a vágólapra (Control + C)\n\n- Illessze be egy szövegszerkesztőbe (Control + V)");
	}
}

function xcv_submit(){
var s="";
if(document.getElementById("xcv_format").checked) s = "xcv";
else if(document.getElementById("txt_format").checked) s = "txt";
else if(document.getElementById("html_format").checked) s="html";
else if(document.getElementById("rtf_format").checked) s="rtf";

document.getElementById("select_format").value = s;
document.getElementById("submit_form").action = "generate_" + s + ".php";
document.getElementById("submit_form").submit();
}

