$(document).ready(function() {
	$("#btnBigSignUp").click(function(e) {
		$("#divLargeButtons").slideUp("slow");
		$("#frmSignUp").slideDown("slow");
		e.preventDefault();
	});
	$("#lnkBigSignUp").click(function(e) {
		$("#frmSignIn").slideUp("slow");
		$("#frmSignUp").slideDown("slow");
		e.preventDefault();
	});
	$("#btnBigSignIn").click(function(e) {
		$("#divLargeButtons").slideUp("slow");
		$("#frmSignIn").slideDown("slow");
		e.preventDefault();
	});
	$("#lnkBigSignIn").click(function(e) {
		$("#frmSignUp").slideUp("slow");
		$("#frmSignIn").slideDown("slow");
		e.preventDefault();
	});
	$("a.commentsExpandLink").click(function(e) {
		if ($(this).parents("em").siblings(".profileCommentsList").is(':visible')) {
			$(this).parents("em").siblings(".profileCommentsList").slideUp("fast");
		} else {
			$(this).parents("em").siblings(".profileCommentsList").slideDown("fast");
		}
		e.preventDefault();
	});
	$("a.hideBlogComments").click(function(e) {
		$(this).parents("div.profileCommentsList").slideUp("fast");
		e.preventDefault();
	});
	$("a.leftLinkRemove").click(function(e) {
		thisLink = $(this);
		if (confirm("Sigur doriti stergerea acestei pagini recomandate?")) {
			$.ajax({
				type: "POST",
				url: "http://keypeople.dailybusiness.ro/bin/deleteleftlink.php",
				data: "linkid=" + $(this).attr("id"),
				success: function(msg) {
					if (msg != "failed") {
						$(thisLink).parents("div.leftColumnSmallItem").slideUp("slow", function() {
							$(thisLink).parents("div.leftColumnSmallItem").remove();
						});
					}
				}
			});
		}
		e.preventDefault();
	});
	$("a.deleteCommentItem").click(function(e) {
		thisLink = $(this);
		if (confirm("Sigur doriti stergerea acestui mesaj?")) {
			$.ajax({
				type: "POST",
				url: "http://keypeople.dailybusiness.ro/bin/deleteblogcomment.php",
				data: "commentid=" + $(this).attr("id"),
				success: function(msg) {
					if (msg != "failed") {
						$(thisLink).parents("div.commentItem").slideUp("fast", function() {
							newCommentsNumber = parseInt($(thisLink).parents("li").find("span.commentsNumber").text()) - 1;
							$(thisLink).parents("li").find("span.commentsNumber").html(newCommentsNumber);
							$(thisLink).parents("div.commentItem").remove();
						});
					}
				}
			});
		}
		e.preventDefault();
	});
	$("a.deleteBlogMessage").click(function(e) {
		thisLink = $(this);
		if (confirm("Sigur doriti stergerea acestui mesaj?")) {
			$.ajax({
				type: "POST",
				url: "http://keypeople.dailybusiness.ro/bin/deleteblogentry.php",
				data: "messageid=" + $(this).attr("id"),
				success: function(msg) {
					if (msg != "failed") {
						$(thisLink).parents("li").slideUp("fast", function() {
							$(thisLink).parents("li").next().css('color',$(thisLink).parents("li").find("font").css("color"));
							$(thisLink).parents("li").next().css('font-size',$(thisLink).parents("li").find("font").css("font-size"));
							$(thisLink).parents("li").next().css('font-family',$(thisLink).parents("li").find("font").css("font-family"));
							$(thisLink).parents("li").remove();
						});
					}
				}
			});
		}
		e.preventDefault();
	});
	$("#addLinkButton").click(function(e) {
		if ($("#newLinkTitle").val() != "" && $("#newLinkURL").val() != "") {
			$.ajax({
				type: "POST",
				url: "http://keypeople.dailybusiness.ro/bin/addprofilelink.php",
				data: "title=" + encodeURIComponent($("#newLinkTitle").val()) + "&url=" + encodeURIComponent($("#newLinkURL").val()),
				success: function(msg) {
					if (msg != 'failed') {
						$("#newLinkTitle").val("titlul paginii");
						$("#newLinkURL").val("link-ul paginii");
						if ($("#leftLinksContainer").is(":visible")) {
							$("#leftLinksContainer").append(msg);
						} else {
							$("#leftLinksContainer").append(msg);
							$("#leftLinksContainer").slideDown("fast");
						}
					} else {
						alert("Pagina propusa nu a putut fi adaugata.");
					}
				}
			});
		}
		e.preventDefault();
	});
	mySelectedAnchor = self.document.location.hash;
	if (mySelectedAnchor.indexOf('profileComment') != -1) {
		mySelectedAnchor = mySelectedAnchor + " > div.profileCommentsList";
		//$(mySelectedAnchor).slideDown("fast");
		$(mySelectedAnchor).slideDown("fast");
	}
});

//var documentRoot = 'http://192.168.1.19/keyPeopleNew/';

function viewUsersInDomain(whichDomain) {
	location.href = documentRoot + "profile/search/n-/c-/l-/d-" + whichDomain + "/a-";
}

function limitCharacters(whichField, maxChars, displayRemaining) {
	if (whichField.value.length > maxChars) {
		whichField.value = whichField.value.substring(0, maxChars);
	} else {
		document.getElementById(displayRemaining).innerHTML = parseInt(maxChars - whichField.value.length);
	}
}

function showHide(which) {
	if (which.style.display == "none") {
		which.style.display = "block";
	} else {
		which.style.display = "none";
	}
}

function loadArrdep (which, page, maxpage) {
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.open("GET", documentRoot + "bin/load_arrdep.php?type=" + which + "&page=" + page, true);
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4) {
			var arrdep = new Array();
			var arrdepFinal = new Array();
			//alert(xmlHttp.responseText);
			arrdep = xmlHttp.responseText.split(" || "); 
			for(i=0; i < arrdep.length; i++) {
				row = arrdep[i].split(" | "); 
				var rowItem = new Array();
				for(k=0; k < row.length; k++) {
					values = row[k].split("=");
					rowItem[k]=values[1];
				}
				//rowItem contains: 0->id, 1->title, 2->link, 3->img, 4->brief, 5->tags, 6->regitered
				arrdepFinal[i] = rowItem;
			}
			for(i=0; i < arrdepFinal.length; i++) {
				var divElem = which + '_' + i;
				var linkElem = documentRoot+"sosiri-plecari/articol/"+arrdepFinal[i][2];
				var img = documentRoot+arrdepFinal[i][3];
				var replaceDiv = "<div class=\"img\"><a href=\""+linkElem+"\" target=\"_top\" rel=\"bookmark\" title=\""+arrdepFinal[i][1]+"\"><img src=\""+img+"\" border=0 alt=\""+arrdepFinal[i][5]+"\"></a></div><h3 ><a href=\""+linkElem+"\" target=\"_top\" rel=\"bookmark\" title=\""+arrdepFinal[i][1]+"\">"+arrdepFinal[i][1]+"</a><font class=\"showora\"> ("+arrdepFinal[i][6]+")</font></h3><div class=\"brief\">"+arrdepFinal[i][4]+"</div>";
				document.getElementById(which + '_' + i).innerHTML = replaceDiv;
			}
			if (arrdepFinal.length < 5){
				for(i=0; i < 3-arrdepFinal.length; i++) {
					pos = 3 - (3-arrdepFinal.length);
					document.getElementById(which + '_' + pos).innerHTML = '';
				}
			}

		}
		var start = page - 1;
		if (start > 1) {
			document.getElementById(which + '_prev').href = "javascript:loadArrdep('"+which+"', "+start+", "+maxpage+");";
			document.getElementById(which + '_prev').style.display = "inline";
		}else{
			document.getElementById(which + '_prev').style.display = "none";
		}
		stopPag = start + 3 - 1;
		k=0;
		if (page <= maxpage){
			for (i = start; i <= stopPag; i++) {
				if (start == 0) pag = i+1; 
				else pag = i;
				if ((start ==0 && i==0) || (stopPag > maxpage && i==maxpage)) {
					document.getElementById(which + '_pag_' + k).style.display = "none";
					document.getElementById(which + '_strong_' + k).innerHTML = pag;
					document.getElementById(which + '_strong_' + k).style.display = "inline";
				}else if (((stopPag - i) == k) && (start > 0) && (i < maxpage)) {
					document.getElementById(which + '_pag_' + k).style.display = "none";
					document.getElementById(which + '_strong_' + k).innerHTML = pag;
					document.getElementById(which + '_strong_' + k).style.display = "inline";
				} else {
					if (i <= maxpage) {
						document.getElementById(which + '_strong_' + k).style.display = "none";
						document.getElementById(which + '_pag_' + k).innerHTML = pag;
						//document.getElementById(which + '_pag_' + k).setAttribute ("onclick", "javascript:loadArrdep('"+which+"', "+pag+", "+maxpage+");");
						document.getElementById(which + '_pag_' + k).href = "javascript:loadArrdep('"+which+"', "+pag+", "+maxpage+");";
						document.getElementById(which + '_pag_' + k).style.display = "inline";
					} else {
						document.getElementById(which + '_strong_' + k).style.display = "none";
						document.getElementById(which + '_pag_' + k).style.display = "none";
					}
				}
				k++;
			}
		}
		if (stopPag < maxpage) {
			var next = stopPag++;
			//document.getElementById(which + '_next').setAttribute ("onclick", "javascript:loadArrdep('"+which+"', "+next+", "+maxpage+");");
			document.getElementById(which + '_next').href="javascript:loadArrdep('"+which+"', "+next+", "+maxpage+");";
			document.getElementById(which + '_next').style.display = "inline";
		} else {
			document.getElementById(which + '_next').style.display = "none";
		}

	}
	xmlHttp.send(null);
}

function loadProfileComments (which, page, maxpage, totalComm, toate)  {
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.open("GET", documentRoot + "bin/load_profile_comentarii.php?profilid=" + which + "&page=" + page + "&toate=" + toate , true);
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState == 4) {
			var maxListNo = 5;
			var comments = new Array();
			var commentsFinal = new Array();
			//alert(xmlHttp.responseText);
			comments = xmlHttp.responseText.split(" || "); 
			for(i=0; i < comments.length; i++) {
				row = comments[i].split(" | "); 
				var rowItem = new Array();
				for(k=0; k < row.length; k++) {
					values = row[k].split("=");
					rowItem[k]=values[1];
				}
				//rowItem contains: 0->name, 1->comments, 2->data, 3->link
				commentsFinal[i] = rowItem;
			}
			for(i=0; i < commentsFinal.length; i++) {
				var liElem = 'comment_' + i;
				var replaceLi = "<small>"+commentsFinal[i][0]+"</small><br>"+commentsFinal[i][1]+"<br><em>"+commentsFinal[i][2]+"</em>";
				document.getElementById(liElem).innerHTML = replaceLi;
				document.getElementById(liElem).style.display = "";
			}
			if(toate == 1) {
				document.getElementById('com_pag_toate').style.display = "none";
				document.getElementById('com_strong_toate').style.display = "inline";
			} else {
				if (document.getElementById('com_pag_toate').style.display == "none") {
					document.getElementById('com_pag_toate').href = "javascript:loadProfileComments("+which+", 1, "+maxpage+", "+totalComm+", 1);";
					document.getElementById('com_pag_toate').style.display = "inline";
					document.getElementById('com_strong_toate').style.display = "none";
				}
			}
			if (totalComm > 0) {
				// where listed all comments
				for(i=0; i < totalComm-commentsFinal.length; i++) {
					pos = commentsFinal.length + i;
					document.getElementById('comment_' + pos).style.display = "none";
				}
			} else {
				if (commentsFinal.length < maxListNo){
					for(i=0; i < maxListNo-commentsFinal.length; i++) {
						pos = commentsFinal.length + i;
						document.getElementById('comment_' + pos).style.display = "none";
					}
				}
			}

		}
		var start = page - 1;
		if (start > 1) {
			document.getElementById('com_prev').href = "javascript:loadProfileComments("+which+", "+start+", "+maxpage+", "+totalComm+", 0);";
			document.getElementById('com_prev').style.display = "inline";
		}else{
			document.getElementById('com_prev').style.display = "none";
		}
		stopPag = start + maxListNo - 1;
		k=0;
		if (page <= maxpage){
			for (i = start; i <= stopPag; i++) {
				if (start == 0) pag = i+1; 
				else pag = i;
				if ((start ==0 && i==0) && (toate == 0) || (stopPag > maxpage && i==maxpage) ) {
					document.getElementById('com_pag_' + k).style.display = "none";
					document.getElementById('com_strong_' + k).innerHTML = pag;
					document.getElementById('com_strong_' + k).style.display = "inline";
				}else if (((stopPag - i) == k) && (start > 0) && (i < maxpage) && (toate == 0)) {
					document.getElementById('com_pag_' + k).style.display = "none";
					document.getElementById('com_strong_' + k).innerHTML = pag;
					document.getElementById('com_strong_' + k).style.display = "inline";
				} else {
					if (i <= maxpage) {
						document.getElementById('com_strong_' + k).style.display = "none";
						document.getElementById('com_pag_' + k).innerHTML = pag;
						document.getElementById('com_pag_' + k).href = "javascript:loadProfileComments("+which+", "+pag+", "+maxpage+", "+totalComm+", 0);";
						document.getElementById('com_pag_' + k).style.display = "inline";
					} else {
						document.getElementById('com_strong_' + k).style.display = "none";
						document.getElementById('com_pag_' + k).style.display = "none";
					}
				}
				k++;
			}
		}
		if (stopPag < maxpage) {
			var next = stopPag++;
			document.getElementById('com_next').href="javascript:loadProfileComments("+which+", "+next+", "+maxpage+", "+totalComm+", 0);";
			document.getElementById('com_next').style.display = "inline";
		} else {
			document.getElementById('com_next').style.display = "none";
		}
	}
	
	
	xmlHttp.send(null);
	}

function toggleSection (which) {
	var elem = document.getElementById(which);
	var elemImg = document.getElementById(which + '_img');
	
	if (elem.style.display == "none") {
		// show div + change img to Restrange	
		elem.style.display = "block";
		elemImg.src = documentRoot + "imgs/restrange.gif";
		elemImg.setAttribute('alt', '[-]');
	} else {
		// hide div + change img to Extinde
		elem.style.display = "none";
		elemImg.src = documentRoot + "imgs/extinde.gif";
		elemImg.setAttribute('alt', '[+]');
	}
	return true;
}

function checkAreaBoxes(className) {
	var divElem = document.getElementById('areasList');
	var allChecks = document.getElementsByTagName('input');
	var disableLocal = false;
	for (i = 0; i < allChecks.length; i++) {
		if (allChecks[i].type == "checkbox") {
			if (allChecks[i].id.indexOf('_all_ro') > 0){
				var labelId = allChecks[i].id.replace('area', 'label');
				var label = document.getElementById(labelId);
				if (allChecks[i].checked){
					disableLocal = true;
					label.setAttribute("class", "element-changed"); // for Mozilla Firefox
					label.setAttribute("className", "element-changed"); // for IE
				} else {
					disableLocal = false;
					label.setAttribute("class", ""); // for Mozilla Firefox
					label.setAttribute("className", ""); // for IE
				}
			} 
		}
	}
	for (i = 0; i <= allChecks.length; i++) {
		if (allChecks[i].type == "checkbox") {
			if (allChecks[i].id.indexOf(className) > 0){
				allChecks[i].disabled = disableLocal;
				var labelId = allChecks[i].id.replace('area', 'label');
				var label = document.getElementById(labelId);
				if (disableLocal == false) {
					label.setAttribute("class", ""); // for Mozilla Firefox
					label.setAttribute("className", ""); // for IE
				} else {
					label.setAttribute("class", "element-gray"); // for Mozilla Firefox
					label.setAttribute("className", "element-gray"); // for IE
				}
			}
		}
	}
}

function checkFillInSet(type, which) {
	var counter = which.split('_');
	if (type == 'job') {
		var company = document.getElementById('company_'+counter[0]);
		var position = document.getElementById('position_'+counter[0]);
		if (company.value == '' || position.value == '')
			return false;
		else
			return true;
	} else if (type == 'studii') {
		var denumire = document.getElementById('name_'+counter[0]+'_studii');
		if (denumire.value == '')
			return false;
		else
			return true;
	}
	
}

function createSet(type, which) {
	var sectionDiv = document.getElementById(which);
	var allDivs = sectionDiv.getElementsByTagName('div');
	var idPattern = type + '_data_set';
	j=0;
	for (i = 0; i < allDivs.length; i++) {
		if (allDivs[i].id !=''){
			if (allDivs[i].id.indexOf(idPattern) > 0){
				counter = allDivs[i].id.split('_');
				if (j <= counter[0]) {
					j = parseInt(counter[0]) + parseInt(1);
				}
				if (checkFillInSet(type, allDivs[i].id) == false)
					return;
			}
		}
	}
	newId = j + '_' + type + '_data_set';
	if (j == 0) deleteBtn = false;
	else deleteBtn = true;
	//if (type == 'job') {
		createDivSet(type,'others_'+type+'_data' ,newId, deleteBtn);
		
	//}
}

function createDivSet(type, which, newId, deleteBtn) {
	var btnRow = '';
	counter = newId.split('_');
	//if (deleteBtn == true) {
		btnRow = '<div class="tr-delete" id="'+type+'_'+counter[0]+'_delete"><a onclick="javascript:deleteSet(\''+type+'\',\''+newId+'\');return false;"><img alt="sterge" src="'+documentRoot+'imgs/sterge.gif"/></a></div>';	
	//}
	var myDiv = document.createElement('DIV');
	myDiv.setAttribute ('id', newId);
	myDiv.setAttribute("class", "data-set"); // for Mozilla Firefox
	myDiv.setAttribute("className", "data-set"); // for IE
	if (type == 'job') {
		var replaceDiv = btnRow+'<div class="tr"> <div class="column"> <strong>Companie:</strong><strong class="required">*</strong><br/> <input class="text" type="text" name="jobcompany_'+counter[0]+'" value="" id="company_'+counter[0]+'"/> </div> <div class="column"> <strong>Pozitie:</strong><strong class="required">*</strong><br/> <input class="text" type="text" name="jobposition_'+counter[0]+'" value="Unknown"  id="position_'+counter[0]+'"/> </div> <div class="column"> <strong>Tip:</strong><strong class="required">*</strong><br/> <select name="jobtype_'+counter[0]+'"> <option value="contract" selected="selected">Contract permanent</option> <option value="temp">Contract temporar</option> <option value="owner">Afacere proprie</option> </select> </div> </div> <div class="tr"> <div class="column"> <strong>Localitate:</strong><br/> <input class="text" type="text" name="joblocation_'+counter[0]+'" value="" /> </div> <div class="column"> <strong>Inceput:</strong><br/> <input class="text" type="text" name="jobstart_date_'+counter[0]+'" value="00.00.0000" /> <br><small>Folositi formatul ZZ.LL.AAAA.</small></div><div class="column"><strong>Sfarsit:</strong><br/><input class="text" type="text" name="jobend_date_'+counter[0]+'" value="00.00.0000" id="end_date_'+counter[0]+'"/><br><input type="checkbox" name="jobstill_going_'+counter[0]+'" value="1" id="still_going_'+counter[0]+'" onclick="enableDisable(\'end_date_'+counter[0]+'\')" class="checkbox" /><label for="still_going_'+counter[0]+'" style="line-height:25px; vertical-align:middle;" id="label_end_date_'+counter[0]+'">Inca in curs</label><br><small>Folositi formatul ZZ.LL.AAAA.</small></div></div><div class="tr" style="padding-bottom:10px;"><div class="column"><strong>Prioritate la afisare:</strong><br/><input type="checkbox" name="jobmost_current_'+counter[0]+'" value="1" id="most_current_'+counter[0]+'" class="checkbox" /><label for="most_current_'+counter[0]+'" >preferat</label><br><small>Chiar daca nu este cea mai recenta, aceasta pozitie va fi afisata prima.</small></div><div class="column" style="width:450px;"><strong>Detalii:</strong><br/><textarea class="text" name="jobdetails_'+counter[0]+'" ></textarea></div></div>';
	} else if (type == 'studii') {
		var replaceDiv = btnRow+'<div class="tr"> <div class="column"> <strong>Denumire institutie/curs:</strong><strong class="required">*</strong><br/> <input class="text" type="text" name="name_'+counter[0]+'" value="" id="name_'+counter[0]+'_'+type+'"/> </div> <div class="column"> <strong>Tip:</strong><strong class="required">*</strong><br/> <select name="type_'+counter[0]+'"><option value="liceu" >Liceu</option><option value="facultate" selected="selected" >Facultate</option><option value="master" >Master</option><option value="doctorat" >Doctorat</option><option value="curs">Curs de perfectionare</option></select></div><div class="column"><strong>Localitate:</strong><br/><input class="text" type="text" name="location_'+counter[0]+'" value="" id="location_'+counter[0]+'_'+type+'"/></div></div><div class="tr"><div class="column"><strong>Inceput:</strong><br/><input class="text" type="text" name="start_date_'+counter[0]+'" value="00.00.0000" /><br><small>Folositi formatul ZZ.LL.AAAA.</small></div><div class="column"><strong>Sfarsit:</strong><br/><input type="text" name="end_date_'+counter[0]+'" value="00.00.0000" id="end_date_'+counter[0]+'_'+type+'" class="text"/><br><input type="checkbox" name="still_going_'+counter[0]+'" value="1" id="still_going_'+counter[0]+'_'+type+'" onchange="enableDisable(\'end_date_'+counter[0]+'_'+type+'\')" class="checkbox" /><label for="still_going_'+counter[0]+'_'+type+'" id="label_end_date_'+counter[0]+'_'+type+'">Inca in curs</label><br><small>Folositi formatul ZZ.LL.AAAA.</small></div><div class="column">&nbsp;</div></div><div class="tr" style="padding-bottom:10px;"><div class="column" style="width:450px;"><strong>Detalii:</strong><br/><textarea class="text" name="details_'+counter[0]+'" ></textarea></div></div>';
	}
	//alert(replaceDiv);
	//document.getElementById(which).innerHTML = replaceDiv;
	myDiv.innerHTML = replaceDiv;
	document.getElementById(which).appendChild(myDiv);
	return true;
}

function deleteSet(type, which) {
	var sectionDiv = document.getElementById(type+'_activities');
	var allDivs = sectionDiv.getElementsByTagName('div');
	var idPattern = type + '_data_set';
	j=0;
	for (i = 0; i < allDivs.length; i++) {
		if (allDivs[i].id !=''){
			if (allDivs[i].id.indexOf(idPattern) > 0){
				j++;
			}
		}
	}
	if (j==1) {
		alert ('Nu puteti sterge acest set de date pentru ca trebuie sa aveti cel putin un astfel de set de date!');
		return false;
	} else {
		 var agree = confirm ('Sunteti sigur ca vreti sa eliminati definitiv acest set de date?');
		 if (agree) {
			 var data_set = document.getElementById(which);
			 data_set.parentNode.removeChild(data_set);
			 return true;
		 } else {
			return false;	 
		}
	}
}

function enableDisable (which) {
	var elem = document.getElementById(which);
	var label = document.getElementById('label_'+which);
	if (elem.disabled == true) {
		elem.disabled = false;
		elem.setAttribute("class", "text"); // for Mozilla Firefox
		elem.setAttribute("className", "text"); // for IE
		label.setAttribute("class", ""); // for Mozilla Firefox
		label.setAttribute("className", ""); // for IE
	}
	else {
		elem.disabled = true;
		elem.setAttribute("class", "input-gray"); // for Mozilla Firefox
		elem.setAttribute("className", "input-gray"); // for IE
		label.setAttribute("class", "element-changed"); // for Mozilla Firefox
		label.setAttribute("className", "element-changed"); // for IE
	}
}

function findSectionToggle() {
	var myURL = String(window.location);
	var splitURL = myURL.split('#');
	
	//toggleSection('section_'+splitURL[1]);
	var optionLink = splitURL[1].split('-');
	toggleSection('section_'+optionLink[0]);
	if (optionLink[1] != '') {
		var elem = document.getElementById('title_'+optionLink[1]);
		elem.style.color = '#FF0000';
	}
}



function alertToggle() {
	var myURL = String(window.location);
	var splitURL = myURL.split('#');
	if (splitURL[1] == "autentificareRetea" || splitURL[1] == "contNeaprobat") {
		ToggleForbidden(splitURL[1]);
	}
}

function ToggleForbidden(alertType) {
	var AlertMsg = "";
	if (alertType == "notLoggedIn") {
		AlertMsg = 'Aceasta optiune este disponibila numai utilizatorilor inregistrati.<br />Daca ai un cont <a href="'+documentRoot+'login" onfocus="this.blur();" title="autentificare"  class="bluelink">te poti autentifica</a>, daca nu ai un cont <a href="'+documentRoot+'inregistrare" onfocus="this.blur();" title="creaza un cont nou"  class="bluelink">iti poti crea unul nou</a>.';
	} else if (alertType == "selfInvite") {
		AlertMsg = 'Aceasta optiune este disponibila numai pentru a contacta alti utilizatori, nu pe tine.';
	} else if (alertType == "userPending") {
		AlertMsg = 'Aceasta optiune este disponibila numai pentru utilizatorii aprobati. Contul tau Key People nu a fost aprobat inca.<br />Pentru mai multe informatii, te rugam sa <a href="mailto:keypeople@dailybusiness.ro" class="bluelink" onfocus="this.blur">ne contactezi</a>.';
	} else if (alertType == "autentificareRetea") {
		AlertMsg = 'Pentru a-ti crea propria retea de parteneri trebuie sa fii autentificat.<br />Daca ai un cont <a href="'+documentRoot+'login" onfocus="this.blur();" title="autentificare"  class="bluelink">te poti autentifica</a>, daca nu ai un cont <a href="'+documentRoot+'inregistrare" onfocus="this.blur();" title="creaza un cont nou"  class="bluelink">iti poti crea unul nou</a>.';
	} else if (alertType == "contNeaprobat") {
		AlertMsg = 'Pentru a-ti crea propria retea de parteneri trebuie sa ai contul aprobat.<br />Pentru mai multe informatii, te rugam sa <a href="mailto:keypeople@dailybusiness.ro" class="bluelink" onfocus="this.blur">ne contactezi</a>.';
	}
	document.getElementById("forbiddenAlert").style.display = "block";
	document.getElementById("forbiddenAlertMsg").innerHTML = AlertMsg;
}

function ToggleUserName(userID, userNameInfo, userInfo, type) {
	document.getElementById("destinatarID").value = userID;
	//document.getElementById("userName").value = userNameInfo;
	document.frmReteaInvite.userNameDestinatar.value = userNameInfo;
	var listUser = document.getElementById("listUser");
	listUser.style.display = "none";
	document.getElementById("formMessage").style.width = "63%";
	
	//document.getElementById("destinatarInfo").style.display = "";
	userInfoTmp = userInfo.split(" | "); 
	var rowItem = new Array();
	for(i=0; i < userInfoTmp.length; i++) {
		//alert(userInfoTmp[i]);
		values = userInfoTmp[i].split("=");
		rowItem[i]=values[1];
	}
	//rowItem contains: 0->id, 1->fullname, 2->link, 3->img, 4->tags, 5->position, 6->company
	var img = documentRoot+'imgs/'+rowItem[3];
	//alert(img);
	var fillDiv = "<div class=\"kphome\"><div class=\"img\"><a href=\""+documentRoot+"profile/"+rowItem[2]+"\" target=\"_blank\" rel=\"bookmark\" title=\""+rowItem[4]+"\"><img src=\""+img+"\" border=0 alt=\""+rowItem[4]+"\"></a></div><h3 ><a href=\""+documentRoot+"profile/"+rowItem[2]+"\" target=\"_blank\" rel=\"bookmark\" title=\""+rowItem[4]+"\">"+rowItem[1]+"</a></h3><div class=\"hline\"></div><div class=\"brief\"><small>Functie:</small> <strong>"+rowItem[5]+"</strong>, "+rowItem[6]+"</div></div>";
	//alert(fillDiv);
	document.getElementById("destinatarInfo").innerHTML = fillDiv;
	document.getElementById("destinatarInfo").style.display = "";
	document.getElementById("buttonTrimite").style.display = "";
	//alert(document.getElementById("buttonTrimite").style.display);
	
	if (type == "pm") {
		var trimiteLink = "<ul id=\"forumPostForm\"><li class=\"title\"><a href=\""+documentRoot+"?section=retea&subsection=mesaje&action=trimite&type=invite&userid="+rowItem[0]+"\" onfocus=\"this.blur();\" class=\"bluelink\">Invita pe "+rowItem[1]+" in reteaua ta de parteneri</a></li></ul>";
	} else if (type == "invite") {
		var trimiteLink = "<ul id=\"forumPostForm\"><li class=\"title\"><div style=\"float:left; width:350px; padding-left:10px;\"><a href=\""+documentRoot+"?section=retea&subsection=mesaje&action=trimite&type=pm&userid="+rowItem[0]+"\" onfocus=\"this.blur();\" class=\"bluelink\">Trimite un mesaj privat pentru "+rowItem[1]+"</a></div><div style=\"float:right; width:350px; text-align:right; padding-right:10px;\"><a href=\""+documentRoot+"invitatie-prieten\" onfocus=\"this.blur();\" class=\"bluelink\">Invita pe cineva care inca nu este membru KP</a></div></li></ul>";
	}
	//alert(trimiteLink);
	document.getElementById("trimiteLink").innerHTML = trimiteLink;
	

}


function TogglePreviewPost() {
	//alert('intra in fct');
	var myURL = String(window.location);
	document.getElementById('enforcer').value='previewPost';
	//alert(document.getElementById('enforcer').value);
	document.forms['frmForumPost'].submit();
}

function GoToTopPost () {
	var myURL = String(window.location);
	var splitURL = myURL.split('|');
	var action = splitURL[1].split('#');
	//alert(splitURL[0]+'#start');
	//alert(document.getElementById('frmForumPost').action);
	document.getElementById('frmForumPost').action = splitURL[0]+'|'+action[0]+'#start';
	//alert(document.getElementById('frmForumPost').action);
	document.getElementById('enforcer').value='';
	document.forms['frmForumPost'].submit();
}
	
function findPos(obj) {
	try {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	} catch(e) {
	}
}
	
function setDIVPos (dest,src1,ofsx,ofsy) {
	try {
		var pos=findPos(document.getElementById(dest)); 
		var b=document.getElementById(src1); 
		b.style.left=(pos[0]+ofsx)+'px';
		b.style.top=(pos[1]+ofsy)+'px'; 
	} catch(e) {
	}
}

var IE=false;
if (navigator.appVersion.indexOf("MSIE")!=-1){
	IE=true;
}
window.onresize = function() {
	 var today = new Date();
	 var day = today.getDate();
	 var month = today.getMonth();
	 var year = today.getFullYear();
	//if (screen.width>1200 && screen.width<1390) document.getElementById("body").style.paddingRight="100px";
	if (screen.width>1200 && screen.width<1390) document.getElementById("body").style.paddingRight="10px";
	var expireDate=new Date();
	expireDate.setFullYear(2009,7,13);
	
	var screenWidth = screen.width;
	var siteWidth = 990;
	var bannerRightWidth = 180;
	
	var winW = 630, winH = 460;
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth-16;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth-20;
	 }
	}
	var diffW = 0;
	diffW = winW-siteWidth;

	try {
		setDIVPos('top_zone','topbanner',40,10);
		setDIVPos('top_center_zone','topcenterbanner',15,0);
		setDIVPos('right_zone','rightbanner',0,0);
		setDIVPos('left_zone','leftbanner',0,0);
	} catch (e) {
	}


	
	/*setDIVPos('remptybanner','rightbanner',2,5);
	setDIVPos('remptybanner2','rightbanner2',2,5);*/
	/*setDIVPos('right_zone','rightbanner',0,0);
	setDIVPos('top_center_zone','topcenterbanner',20,0);*/
}

function searchKeyPress(e) {
	// look for window.event in case event isn't passed in
	if (window.event) { e = window.event; }
	if (e.keyCode == 13) {
			document.getElementById('btnSearchUser').click();
	}
}
