// Default vars

function hasStyle(objId){
	var output = false;
	var target = document.getElementById(objId);
	if(target && target.currentStyle){
		output = true;
	}
	else if(window.getComputedStyle){
		output = true;
	}
	return(output);
}
function getStyle(objId,styleName,IEstyleProp,MOZstyleProp){
	var target = getObj(objId);
	var style = "";
	if(target.currentStyle){
		styleProp = IEstyleProp;
		style = target.currentStyle[styleProp];
	}
	else if(window.getComputedStyle){
		styleProp = (MOZstyleProp)?MOZstyleProp:IEstyleProp;
		style = document.defaultView.getComputedStyle(target,null).getPropertyValue(styleProp);
	}
	else if(document.styleSheets && document.styleSheets[0]){
		style = null;
		// TODO: Verifiy this version for Opera browsers //
		/*if(document.styleSheets[0].cssRules && document.styleSheets[0].cssRules[0]){
			for(var s=0; s<document.styleSheets[0].cssRules.length; s++){
				if(document.styleSheets[0].cssRules[s].selectorText == styleName){
					styleProp = (MOZstyleProp)?MOZstyleProp:IEstyleProp;
					style = document.styleSheets[0].cssRules[s].style[styleProp];
					break;	
				}
			}
		}*/
	}
	return style;
}
function initFlashTitles(){
	var divs = document.getElementsByTagName("CITE");
	for(var d=0; d<divs.length; d++){
		var titleObj = divs[d];
		var titleId = "title_" + d;
		if(divs[d].innerHTML != ""){
			try{
				
				titleObj.setAttribute("id",titleId);
				var titleClass = null;
				
				var titleBgColor = getStyle(titleId,titleClass,"backgroundColor","background-color");
				var titleTxtColor = getStyle(titleId,titleClass,"color");
				var titleTxtSize = getStyle(titleId,titleClass,"fontSize","font-size");

				if(titleTxtSize){
					titleTxtSize = (titleTxtSize != "")?parseInt(titleTxtSize)+2:17;
					titleObj.style.fontSize = titleTxtSize + "px";
				}
				
				if(titleObj.offsetWidth)
					var titleWidth = parseInt(titleObj.offsetWidth)+ parseInt((divs[d].innerHTML.length * 1.5) - divs[d].innerHTML.length);
				else
					var titleWidth = getStyle(titleId,titleClass,"max-width");
				
				var titleHeight = getStyle(titleId,titleClass,"height");

				var titlePaddingLeft = getStyle(titleId,titleClass,"paddingLeft","padding-left");
				var titlePaddingBottom = getStyle(titleId,titleClass,"paddingBottom","padding-bottom");
				var titlePaddingRight = getStyle(titleId,titleClass,"paddingRight","padding-right");
				var titlePaddingTop = getStyle(titleId,titleClass,"paddingTop","padding-top");

				flashWidth = (titleWidth != "")?parseInt(titleWidth):100;
				flashHeight = (titleHeight != "")?parseInt(titleHeight):20;
				flashBgcolor = (titleBgColor != "")?getHex(titleBgColor):"#ffffff";
				flashTxtColor = (titleTxtColor != "")?getHex(titleTxtColor):"#000000";
				flashTxtSize = titleTxtSize;
				flashTxt =  "<font color='" + flashTxtColor + "'>" + titleObj.innerHTML + "</font>";

				if(titleWidth){
					flashObj = new SWFObject("/images/titles/title.swf?v=3", "titleObj_" + d, flashWidth, flashHeight, "7.0.14", flashBgcolor);
					flashObj.addVariable("bgalpha",100);
					flashObj.addVariable("bgcolor",flashBgcolor);
					flashObj.addVariable("fontsize",flashTxtSize);
					flashObj.addVariable("textcolor",flashTxtColor);
					flashObj.addVariable("txt", flashTxt);
					if(titlePaddingLeft != "")
						flashObj.addVariable("paddingLeft",parseInt(titlePaddingLeft)); 
					else
						flashObj.addVariable("paddingLeft",0); 
					if(titlePaddingBottom != ""){ flashObj.addVariable("paddingBottom",parseInt(titlePaddingBottom)); }
					if(titlePaddingRight != ""){ flashObj.addVariable("paddingRight",parseInt(titlePaddingRight)); }
					if(titlePaddingTop != ""){ flashObj.addVariable("paddingTop",parseInt(titlePaddingTop)); }
					flashObj.write("title_" + d);
				}
				titleObj.style.width = flashWidth + "px";
				
			}
			catch(e){
				if(divs[d].offsetWidth)
					divs[d].style.width = parseInt(divs[d].offsetWidth)+6 + "px";
			}
		}
		divs[d].style.visibility = "visible";
	}
}
function initRating(itemtype,itemid){
	$("#rating-wrapper").stars({ 
		split: 2, 
		cancelShow: false,
		callback: function(ui, type, value){
			$.getJSON(domain + 'ajax.cfm?module=community&language=' + session.language + '&action=rate&itemtype=' + itemtype + '&itemid=' + itemid + '&rating=' + value, function(data) {
				if(data.status == "success" && data.message){
					$("#rating-caption").text(data.message).stop().css("opacity", 1).fadeIn(30);
					setTimeout(function(){
						$("#rating-caption").fadeOut(1000);
						$("#rating-wrapper").stars("select", Math.round(data.stats.ratingavg));
					}, 4000);
				}
				else if(data.status == "success"){
					setTimeout(function(){
						$("#rating-wrapper").stars("select", Math.round(data.stats.ratingavg));
					}, 4000);	
				}
			});
			$("#rating-wrapper").stars("select", value);
		}
	});	
}
function community_jobsearch(formObj){
	if (formObj.keywords.value != ""){
		formObj.action = formObj.formaction.value;
		if(arguments[1])
			formObj.submit();
		else
			return true;
	}
	else{
		return false;
	}
}
function community_selectlist(formObj){
	var check = formObj.email.value.match(mailre);
	if(check != null){
		formObj.action = formObj.formaction.value;
		if(arguments[1])
			formObj.submit();
		else
			return true;
	}
	else{
		alert(messages.ALERT_provide_valid_email);
		return false;
	}
}
function community_subscribe(formObj){
	var check = formObj.email.value.match(mailre);
	if(check != null && formObj.list && hasCheckbox(formObj,'list')){
		formObj.action = formObj.formaction.value;
		if(arguments[1])
			formObj.submit();
		else
			return true;
	}
	else{
		if(check == null)
			alert(messages.ALERT_provide_valid_email);
		else
			alert(messages.ALERT_subscription_select_list);
		return false;
	}
}
function community_unsubscribe(formObj){
	var check = formObj.email.value.match(mailre);
	if (check != null){
		formObj.action = formObj.formaction.value;
		if(arguments[1])
			formObj.submit();
		else
			return true;
	}
	else{
		return false;
	}
}
function community_addcomment(formObj){
	var check1 = formObj.email.value.match(mailre);
	if(check1 != null && formObj.message.value != "" && formObj.signature.value != ""){
		formObj.action = formObj.formaction.value;
		if(arguments[1])
			formObj.submit();
		else
			return true;
	}
	else{
		if(check1 == null)
			alert(messages.ALERT_invalid_sender_email);
		else if(formObj.message.value == "" || formObj.signature.value == "")
			alert(messages.ALERT_fill_mandatory_fields);
		return false;
	}
}
function community_share(formObj){
	var check1 = formObj.email.value.match(mailre);
	var check2 = formObj.recipientemail.value.match(mailre);
	if(check1 != null && check2 != null){
		formObj.action = formObj.formaction.value;
		if(arguments[1])
			formObj.submit();
		else
			return true;
	}
	else{
		if(check1 == null)
			alert(messages.ALERT_invalid_sender_email);
		else if(check2 == null)
			alert(messages.ALERT_invalid_recipient_email);
		return false;
	}
}
function community_addcareer(formObj){
	if(formObj.sector.selectedIndex > 0 && formObj.firstname.value != "" && formObj.lastname.value != "" && formObj.company.value != ""){
		formObj.action = formObj.formaction.value;
		if(arguments[1])
			formObj.submit();
		else
			return true;
	}
	else{
		alert(messages.ALERT_fill_mandatory_fields);
		return false;
	}
}
function community_addpicture(formObj){
	var check = getFileExt(formObj.filedata.value).toLowerCase();
	if(check == "jpg"){
		formObj.action = formObj.formaction.value;
		if(arguments[1])
			formObj.submit();
		else
			return true;
	}
	else{
		alert(messages.PROFILE_career_picturetype);
		return false;
	}
}
function community_selectpicture(formObj){
	var width = 730;
	var height = 490;
	var url = "/popup.cfm?module=community&action=selectpicture";
	var keyin = "";
	var keyout = "";
	var check = 0;
	var lastchr = 0;
	
	if(formObj.firstname.value != "" && formObj.lastname.value != ""){
		keyin = fulllcase(formObj.firstname.value) + fulllcase(formObj.lastname.value);
		for(var i=0; i< keyin.length; i++){
			check = keyin.charCodeAt(i);
			if((check >=48 && check <= 57) || (check >=97 && check <= 122)){
				keyout += keyin.substr(i,1);
				lastchr = check;
			}
		}
		url += "&file=" + keyout + ".jpg";
		wizard = window.open(url, "wizard", "width=" + width + ", height=" + height + ", resizable=0");
		wizard.focus();
	}
	else{
		alert(messages.PROFILE_career_fillfullname);
	}
}
function community_setpicture(file,x1,y1,x2,y2,w,h){
	document.theform["picture"].value = file;
	if((x1 + y1 + x2 + y2) > 0){
		document.theform["crop.hascrop"].value = 1;
		document.theform["crop.x"].value = x1;
		document.theform["crop.y"].value = y1;
		document.theform["crop.w"].value = w;
		document.theform["crop.h"].value = h;
	}
	else{
		document.theform["crop.hascrop"].value = 0;
		document.theform["crop.x"].value = 0;
		document.theform["crop.y"].value = 0;
		document.theform["crop.w"].value = 0;
		document.theform["crop.h"].value = 0;
	}
	document.getElementById("picturename").innerHTML = file;
}
function hrminfo_showcat(cn, id){
	url = partners.hrminfo.caturl + "&cntry=" + cn + "&type=rub&val=" + id;
	window.open(url, "hrmdirectory","width=560, height=550, scrollbars=1");
}

function doQuickSearch(){
	if(document.quicksearch.query.value != document.quicksearch.query.alt && document.quicksearch.query.value != ""){
		switch(document.quicksearch.type.value){
			case "internet":
				window.open("http://www.google.be/search?q=" + document.quicksearch.query.value + "&hl=" + session.language);
				document.quicksearch.query.value = "";
				document.quicksearch.query.blur();
				setFieldDefault(document.quicksearch,'query','off','field');
				return false;
				break;
			case "links":
				document.quicksearch.action = partners.linkcity.searchurl;
				document.quicksearch.q.value = document.quicksearch.query.value;
				document.quicksearch.query.value = "";
				setFieldDefault(document.quicksearch,'query','off','field');
				return true;
				break;
			default:
				document.quicksearch.action = domain + "articles/search/";
				document.quicksearch.target = "_self";
				return true;
				break;
		}
	}
	else{
		alert(messages.ALERT_quicksearch_setquery);
	}
	return false;
}

function checkKey(){
	var keyin = fulllcase(document.theform.key.value);
	var keyout = "";
	var check = 0;
	var lastchr = 0;
	for(var i=0; i< keyin.length; i++){
		check = keyin.charCodeAt(i);
		if((check >=48 && check <= 57) || (check >=97 && check <= 122) || (check == 32 && i > 0 && i < keyin.length-1 && lastchr != 32)){
			keyout += keyin.substr(i,1);
			lastchr = check;
		}
		if(check == 45 && i > 0 && i < keyin.length-1){
			keyout += " ";
		}
	}
	if(keyout.charCodeAt(keyout.length-1) == 32)
		keyout = keyout.substr(0,keyout.length-1);
	document.theform.key.value = keyout;
}
function setKey(){
	var keystr = fulllcase(document.theform.company.value) + ' ' + fulllcase(document.theform.firstname.value) + ' ' + fulllcase(document.theform.lastname.value);
	document.theform.key.value = keystr;
	checkKey();
}

var ddtabmenu={
	disabletablinks: false, ////Disable hyperlinks in 1st level tabs with sub contents (true or false)?
	currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/)

	definemenu:function(tabid, dselected){
		this[tabid+"-menuitems"]=null
		this.addEvent(window, function(){ddtabmenu.init(tabid, dselected)}, "load")
	},
	
	showsubmenu:function(tabid, targetitem){
		var menuitems=this[tabid+"-menuitems"]
		
	 for (i=0; i<menuitems.length; i++){
			menuitems[i].className=""
			if (typeof menuitems[i].hasSubContent!="undefined")
				document.getElementById(menuitems[i].getAttribute("rel")).style.display="none"
		}
		targetitem.className="current"
		if (typeof targetitem.hasSubContent!="undefined")
			document.getElementById(targetitem.getAttribute("rel")).style.display="block"
	},
	
	isSelected:function(menuurl){
		var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
		return (ddtabmenu.currentpageurl==menuurl)
	},
	
	addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
		var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
		if (target.addEventListener)
			target.addEventListener(tasktype, functionref, false)
		else if (target.attachEvent)
			target.attachEvent(tasktype, functionref)
	},
	
	init:function(tabid, dselected){
		var menuitems=document.getElementById(tabid).getElementsByTagName("a")
		this[tabid+"-menuitems"]=menuitems
		for (var x=0; x<menuitems.length; x++){
			
			if (menuitems[x].getAttribute("rel")){
				this[tabid+"-menuitems"][x].hasSubContent=true
				if (ddtabmenu.disabletablinks)
					menuitems[x].onclick=function(){return false}
			}
			else //for items without a submenu, add onMouseout effect
				menuitems[x].onmouseout=function(){this.className=""}
			menuitems[x].onmouseover=function(){ddtabmenu.showsubmenu(tabid, this)}
			if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[x].href)){
				ddtabmenu.showsubmenu(tabid, menuitems[x])
				var setalready=true
			}
			else if (parseInt(dselected)==x)
				ddtabmenu.showsubmenu(tabid, menuitems[x])
		}
	}
}