var user_js=1;
var group=0;
var TimeOutID;

var skill_label; //A place on skill table for a label

//var skilllevels=[]; We do this in index.php so we can initialise it with current settings
//var customlevels=[];//The custom skill levels
//var customtexts=[]; //The custom skill free texts
//var resource_selector_number=0;
if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function(val, fromIndex) {
		if (typeof(fromIndex) != 'number') fromIndex = 0;
		for (var index = fromIndex,len = this.length; index < len; index++)
			if (this[index] == val) return index;
		return -1;
	}
}



function timedCount()
{
//index.php flag: 								mainfile=1
//skill_english_28_1.js generated by gen.php: 	skillfile=1
//this script:									user_js=1
if (typeof(mainfile) == "undefined"||typeof(skillfile) == "undefined"||typeof(user_js) == "undefined")
	{
	TimeOutID=setTimeout("timedCount()",10); //set TimeOutID so we can clearTimeout(TimeOutID);
	}
	else
	{
	clearTimeout(TimeOutID);		
	display_skillgroup();	
	redisplay_custom();
	}
}



function build_table(tableid,rows,tabletype)
{ 
if (tableid.nextSibling)
{
var ns = tableid.nextSibling; //fb text.getNextSibling();
//alert( ns+" Tag="+ns.tagName);
if (ns.tagName == 'TABLE') //fb ns.getTagName()
	{ 
	ns.parentNode.removeChild(ns); //fb ns.getParentNode()
	} 
}

var table = document.createElement('table'); 	
//table.style.border="1px solid #f5f5f5";
var tbody = document.createElement('tbody'); 

table.appendChild(tbody);

	var zeb1="#ffffff"; var zeb2="#f5f5f5";var colr=zeb1; 
	for (var i = 0; i < rows.length; i++) 
		{ 
		//Build the Header
		if(i==0) 
		{
		var row = document.createElement('tr'); 
			if (tabletype=="customskills" )
				{
				
				var cell = document.createElement('td');cell.innerHTML="Skill Name"; 
				cell.className="answer";
				row.appendChild(cell);
				var cell = document.createElement('td');cell.innerHTML="Experience"; 
				cell.className="answer";
				row.appendChild(cell);
				}
				else
				{
				
				var cell = document.createElement('td');cell.innerHTML=skill_label;
				cell.className="answerbold";
				row.appendChild(cell); 
				var cell = document.createElement('td');cell.innerHTML="Click";
				cell.className="answerbold";
				row.appendChild(cell); 
				}
		
		tbody.appendChild(row); 
		}
		
		var cols = rows[i].split('|'); 
		var row = document.createElement('tr'); 
				if (i % 2==0) 
				colr=zeb1; 
				else 
				colr=zeb2;
		for (var j = 0; j < cols.length; j++) 
			{ 
			var cell = document.createElement('td'); 
			//cell.style=('border', '1px solid black'); //cell.setStyle('border', '1px solid black'); 
			cell.style.border="1px solid #e5e5e5";
			cell.style.background=colr;
			cell.innerHTML=cols[j]; //fb setTextValue cell.innerText(cols[j])
			row.appendChild(cell); 
			} 
			//alert(i+" "+j);
		tbody.appendChild(row); 
		} 
	//alert(tbody);
	tableid.parentNode.insertBefore(table, tableid.nextSibling); //fb getParentNode getNextSibling
	//alert(ns.parentNode);	
} 
function display_skillgroup(chr)
{
if (chr==undefined) skillgroup=r[group];
else if (chr=='+')
{
if (group+1>=r.length) 
	group=0;
	else
	group++;
skillgroup=r[group];
}
else if (chr=='-')
{
if (group-1<0) 
	group=r.length-1;
	else
	group--;
skillgroup=r[group];
}
//jsinfo("skillgroup="+skillgroup+" max="+r.length+",group="+group);
jsinfo(s[r[group]]);
/*
if (chr=='+')
	skillgroup=r[group++];
if (chr=='-')
	skillgroup=r[group--];
*/
//alert(skillgroup+" "+u[skillgroup].length);
var row; out=[];
for (row = 0; row < u[skillgroup].length; row++)
{
if (t[skillgroup]==0) 
type="<a class='keys' id='"+u[skillgroup][row]+"' href='javascript:skillme("+u[skillgroup][row]+","+t[skillgroup]+");'>"+lookupskill(u[skillgroup][row],t[skillgroup])+"</a>";
else
type="<a class='keys' id='"+u[skillgroup][row]+"' href='javascript:skillme("+u[skillgroup][row]+","+t[skillgroup]+");'>"+lookupskill(u[skillgroup][row],t[skillgroup])+"</a>";

out[row]=v[skillgroup][row]+"|"+type;
}
var tableid=document.getElementById('table');
build_table(tableid,out,"skillgroup");
}
/*
function display_resources()
{
var myselect=document.getElementById("resource_selector");
for (row = 0; row < w.length; row++)
	{
	optadd=new Option(x[row], w[row]);
	myselect.add(optadd, null);
	if (w[row]==RESOURCE_ID) optadd.selected=true;
	}
}
*/
function tab1(tab) 
{
//var tab1=document.getElementById('YourSkillEntryTab');
//var tab2=document.getElementById('YourAdTab');
//var tab3=document.getElementById('YourSettingsTab');
//if (tab==1) {tab2.style.display="none";tab3.style.display="none";tab1.style.display="inline";}
//if (tab==2) {tab1.style.display="none";tab3.style.display="none";tab2.style.display="inline";}
//if (tab==3) {tab1.style.display="none";tab2.style.display="none";tab3.style.display="inline";}
if (tab==1) $("#YourSkillEntryTab").toggle();
if (tab==2) $("#YourAdTab").toggle();
if (tab==3) $("#YourSettingsTab").toggle();
}
// ######################################
function resource_change()
{
var localval=document.getElementById('resource_selector');
var localval2=localval.selectedIndex;
var answer = confirm("You will erase all skills");
if (answer) //change
{
//resource_selector_number=localval2;
//skillnames=[];
//skilllevels=[];
//skillcontent=[];
//top.focus();
$("#resourcechange").val(1);
document.form_1.submit();
}
else
	{
	localval.selectedIndex=resource_selector_number;
	top.focus();
	}
}
function jsinfo(msg)
{
//var localval=document.getElementById('jsinfo');
//localval.innerHTML=msg;
skill_label=msg;
}

function lookupskill(id,sgtype)
{
//Lookup skilllevels and display the setting for a skill eg YN,SE etc
if (skilllevels== undefined) return;
	if (sgtype==0)
	{
		if (skilllevels[id] == undefined || skilllevels[id] == 0)
		{
		return "No";
		}
		else
		{
		return "Ys";
		}
	}
	else
	{
	if (skilllevels[id]==undefined || skilllevels[id]==0)
		{
		skilllevels[id]=0;
		return "No";		
		}
		else if(skilllevels[id]==1)
		{
		return "SE";
		}
		else if(skilllevels[id]==2)
		{
		return "CE";
		}	
		else if(skilllevels[id]==3)
		{
		return "EE";
		}	
	}
}

function skillme(id,sgtype)
{
if (sgtype==0)
{
//alert(skilllevels[id]);
if (skilllevels[id] == undefined || skilllevels[id] == 0)
	{
	//alert("its "+skilllevels[id]+document.getElementById(id).innerHTML);
	skilllevels[id]=1;
	document.getElementById(id).innerHTML="Ys";
	}
	else
	{
	skilllevels[id]=0;
	document.getElementById(id).innerHTML="No";
	}
}
else
{
if (skilllevels[id]==undefined || skilllevels[id]==0)
	{
	skilllevels[id]=1;
	document.getElementById(id).innerHTML="SE";
	}
	else if(skilllevels[id]==1)
	{
	skilllevels[id]=2;
	document.getElementById(id).innerHTML="CE";
	}
	else if(skilllevels[id]==2)
	{
	skilllevels[id]=3;
	document.getElementById(id).innerHTML="EE";
	}	
	else if(skilllevels[id]==3)
	{
	skilllevels[id]=0;
	document.getElementById(id).innerHTML="No";
	}	
}
}
function save()
{
if (document.getElementById("jobtitle").value=="")
	{
	alert(CANT_SAVE_NOJOBITILE);
	return;
	}
else if (document.getElementById("keywords").value=="")
	{
	alert(CANT_SAVE_NOKEYWORDS);
	return;
	}
else if (document.getElementById("profilecontent").value=="")
	{
	alert(CANT_SAVE_NOABOUT);
	return;
	}
//Go Ahead
var output=[];
if (skilllevels.length>0)
			{
			;	
			count=0;
			for (var i=0; i<skilllevels.length; i++) 
				{
				if (skilllevels[i]>0)
				output[count++]=i+'='+skilllevels[i]+'';
				}
			document.getElementById("allyourskills").value=output.join(",")
			}	
var output2=[];			
if (customlevels.length>0)
			{
			;	
			count=0;
			for (var i=0; i<customlevels.length; i++) 
				{
				if (customlevels[i]>=0 && customtexts[i]!="")
				output2[count++]=customtexts[i]+'='+customlevels[i]+'';
				}
			document.getElementById("allyourcustomskills").value=output2.join("|")
			}						
document.form_1.submit();			
}
function page(pagenumber)
{
if (pagenumber==1)
	{
	document.getElementById("YourSkillEntryTab").style.display="none";//Hide Welcome
	document.getElementById("EditToolBar").style.display="none";//Hide Welcome	
	document.getElementById('YourAdTab').style.display="none";//Hide Welcome	
	document.getElementById('YourSettingsTab').style.display="none";//Hide Welcome	
	document.getElementById("WelcomeTab").style.display="inline";
	document.getElementById("savebutton").style.display="none";//Hide Welcome
	}
else if (pagenumber==2)
	{
	document.getElementById("WelcomeTab").style.display="none";//Hide Welcome
	document.getElementById('YourAdTab').style.display="none";//Hide Welcome	
	document.getElementById('YourSettingsTab').style.display="none";//Hide Welcome	
	document.getElementById("YourSkillEntryTab").style.display="none";//Hide Welcome
	document.getElementById("EditToolBar").style.display="inline";//Hide Welcome
	document.getElementById("savebutton").style.display="inline";//Hide Welcome
	}
}
function apply_skill_changes()
{
var output=[];
			if (skillnames.length>0)
			{
			for (var i=0; i<skillnames.length; i++) 
				{
				skill_pk=skillnames[i].split("_",2);//s 12345
				//output+="<input type=text name="+skill_pk[1]+" value="+skilllevels[i]+">";
				output[i]=skill_pk[1]+'='+skilllevels[i]+'';
				}
			}	
			
			if (output.length>0)
					{
					addme='template=ee_signup_body.tpl&action=configure_job_details&subform=3&RIsubmit=RIsubmit&searchskillchange=1&';
					//output="<tr><td><input type=text name=RIsubmit value=RIsubmit><input type=text name=searchskillchange value=1>"+output+"</td></tr>";
					foutput=""+addme+output.join("&")+"";
					//$("#tableforsubmit tbody").append(output);
					//document.form_dynamicform.submit();
					//foutput='first_name=Tarcila&last_name=Broder';
					 $.post("ri5iee_skilldisplay.php",
					       foutput,
					       function(returned_data)
					         {
					        // alert(returned_data);
							 		if (returned_data!="")
									{			$("#myTableSkills").hide();
												$("tr.dataskill").remove();	
												$("#myTableSkills tbody").append(returned_data);
												$("#myTableSkills tbody").trigger("update"); 
												$("#myTableSkills").tablesorter({widgets: ['zebra']}); 
												$("#myTableSkills").show();	
									}
					         });							
					}
}	
function add()
{
//Adds a custom skill
//var customlevels=[];//The custom skill levels
//var customtexts=[]; //The custom skill free texts
txt=document.getElementById("skilldesc_custom").value;
txt=txt.replace("|", "");
if (txt.replace(/^\s*/, "").replace(/\s*$/, "")!="")
{
var index = customtexts.indexOf(txt);
 for( i = 0; i < document.form_1.newcustomskill.length; i++ )
 {
 if( document.form_1.newcustomskill[i].checked == true )
 val = document.form_1.newcustomskill[i].value;
 }

if (index!=-1) //Modify
	{
	customlevels[index]=val;
	}
else //Add
	{
	customtexts[customtexts.length]=txt;
	customlevels[customlevels.length]=val;
	}
//Redisplay the Custom Skills
document.getElementById("skilldesc_custom").value="";
redisplay_custom();
}
}
function redisplay_custom()
{
var output=[];
if (customlevels.length>0)
			{
			;	
			count=0;
			for (var i=0; i<customlevels.length; i++) 
				{
				if (customtexts[i]!="" && customlevels[i]>=0)
				output[count++]='<a href="javascript:editcustom('+i+');">'+customtexts[i]+'</a>|'+translate(customlevels[i])+'';
				}
			//document.getElementById("customlist").innerHTML=output.join("<br>");
			var tableid=document.getElementById('customlist');
			build_table(tableid,output,"customskills");
			}



}

function del()
{
txt=document.getElementById("skilldesc_custom").value;
if (txt.replace(/^\s*/, "").replace(/\s*$/, "")!="")
{
var index = customtexts.indexOf(txt);
if (index!=-1) //Modify
	{
	customlevels[index]="";
	customtexts[index]="";
	document.getElementById("skilldesc_custom").value="";
	}
//Redisplay the Custom Skills
redisplay_custom();	
}
}
function translate(index)
{
if (index==0) return '';
else if (index==1) return SETEXT;
else if (index==2) return CETEXT;
else if (index==3) return EETEXT;
}
function editcustom(index)
{
document.getElementById("skilldesc_custom").value=customtexts[index];
if (customlevels[index]==0) document.form_1.newcustomskill[0].checked = true;
else if (customlevels[index]==1) document.form_1.newcustomskill[1].checked = true;
else if (customlevels[index]==2) document.form_1.newcustomskill[2].checked = true;
else if (customlevels[index]==3) document.form_1.newcustomskill[3].checked = true;
}
function sandinista()
{
if ($("#jobtitle").val()=="")
	{
	msg('Before you Save', CANT_SAVE_NOJOBITILE);
	return;
	}
else if ($("#keywords").val()=="")
	{
	msg('Before you Save', CANT_SAVE_NOKEYWORDS);
	return;
	}
else if ($("#profilecontent").val()=="")
	{
	msg('Before you Save', CANT_SAVE_NOABOUT);
	return;
	}
var output=[];
if (skilllevels.length>0)
			{
			count=0;
			for (var i=0; i<skilllevels.length; i++) 
				{
				if (skilllevels[i]>0)
				output[count++]=i+'='+skilllevels[i]+'';
				}
			$("#allyourskills").val(output.join(","));
			}		
var output2=[];			
if (customlevels.length>0)
			{
			count=0;
			for (var i=0; i<customlevels.length; i++) 
				{
				if (customlevels[i]>=0 && customtexts[i]!="")
				output2[count++]=customtexts[i]+'='+customlevels[i]+'';
				}
			$("#allyourcustomskills").val(output2.join("|"));
			}				
//switch saving logo on - switch off post submit
$("#loadingdisplay").show();	
//page(1);
//$("#submission_feedback").text("Saving Changes...");
//$("#submission_feedback").show();

$("#YourSkillEntryTab").hide();
$("#YourAdTab").hide();
$("#YourSettingsTab").hide();

submitForm(http_start_path+"/submitjs.php", "#savesettings", "#welcomedisplay");

}
function subsave()
{
$("#loadingdisplay").show();	
//document.getElementById('loadingdisplay').setStyle({display: 'inline'});
//page(1);
submitForm(http_start_path+"/submitjs.php", "#signup", "#welcomedisplay");
}
function submitForm(url, form_id, target_id) 
{   
    var params = $(form_id).serialize();   
	$.post(url,
					       params,
					       function(returned_data)
					         {
								$("#loadingdisplay").hide();
							 		if (returned_data!="")
									{			
									$(target_id).html(returned_data);	
									}
					         });	
} 
function msg(title,content)
{
alert(content);
//$("#dialog").text(content);
//$("#dialog").dialog('option', 'title', title);
//$("#dialog").dialog( 'open' );
}

timedCount();
/*
$(function() {
		
		var name = $("#name"),
			email = $("#email"),
			password = $("#password"),
			allFields = $([]).add(name).add(email).add(password),
			tips = $("#validateTips");

		function updateTips(t) {
			tips.text(t).effect("highlight",{},1500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("Length of " + n + " must be between "+min+" and "+max+".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		
		$("#dialog2").dialog({
			bgiframe: true,
			autoOpen: false,
			height: 300,
			modal: true,
			buttons: {
				'Create an account': function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(name,"username",3,16);
					bValid = bValid && checkLength(email,"email",6,80);
					bValid = bValid && checkLength(password,"password",5,16);

					bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"Username may consist of a-z, 0-9, underscores, begin with a letter.");
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. ui@jquery.com");
					bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Password field only allow : a-z 0-9");
					
					if (bValid) {
						$('#users tbody').append('<tr>' +
							'<td>' + name.val() + '</td>' + 
							'<td>' + email.val() + '</td>' + 
							'<td>' + password.val() + '</td>' +
							'</tr>'); 
						$(this).dialog('close');
					}
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		
		
		
		$('#create-user').click(function() {
			$('#dialog2').dialog('open');
		})
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		).mousedown(function(){
			$(this).addClass("ui-state-active"); 
		})
		.mouseup(function(){
				$(this).removeClass("ui-state-active");
		});

	});
	*/
var urlAddress = "http://www.skillmountain.com"; 
var pageName = "Skill Mountain - Public Skills with Anonymity"; 
function addToFavorites() { 
if (window.external) { window.external.AddFavorite(urlAddress,pageName)} 
else { alert("Sorry! Your browser doesn't support this feature.");} 
}
function region_change(source_textid,target_textid,whichone)
{
var val = $("#"+source_textid).val() //worklocation_country_id target_text=worklocation_region_list
var target = $("#"+target_textid)
target.html("Loading...");//Replace Select html with Loading
$.post(http_start_path+"/getcc.php",
					       "cc="+val+"&mode="+whichone,
					       function(returned_data)
					         {
					         //alert(returned_data);
							 		if (returned_data!="")									
									{			
									target.html(returned_data);
									}
					         });	


} 