
function $(id){
	return document.getElementById(id);
}

function href(link) {

	document.location.href = link;

}

function displayPopup(url, width, height) {

	var Win = window.open(url,"displayPopup",'width=' + width + ',height=' + height + ',resizable=no,scrollbars=yes,menubar=no');

}

function ownForum(){
	month = 600;
	forum = 100;

	if($('ownForum_cb').checked == true){
		$('total_a_ad').innerHTML = month+forum;
		$('vat_ad').innerHTML = Math.round(((month+forum)*0.175)*100)/100+'0' ;
		$('total_ad').innerHTML = ((month+forum)*0.175)+(month+forum)+'0';
		$('total_ad2').value = ((month+forum)*0.175)+(month+forum);
	}else{
		$('total_a_ad').innerHTML = month;
		$('vat_ad').innerHTML = ((month)*0.175)+'.00';
		$('total_ad').innerHTML = ((month)*0.175)+(month)+'.00';
		$('total_ad2').value = ((month)*0.175)+(month);
	}
}

function val_tc(){

	if($('tc_cb').checked == true){
		$('tc').disabled = false;
	}else{
		$('tc').disabled = true;
	}

}

function cloudShow(oLink, id){
	if( oLink.offsetParent ) {
		for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
			posX += oLink.offsetLeft;
			posY += oLink.offsetTop;
		}
		$(id).style.top = (posY-70)+'px';
		$(id).style.left = (posX-50)+'px';		
	} else {
			$(id).style.top  = (oLink.y-70)+'px';
			$(id).style.left = (oLink.x-50)+'px';
	}
		$(id).style.display = 'block';
}

function cloudHide(id){

		$(id).style.display = 'none';

}

function AJAX_Username(o){
	if(o.value.length > 2){
		
	advAJAX.get({
		url: "http://www.gtr.co.uk/plugs/ajax.php?getU_name="+o.value,
		onSuccess : function(obj) { 
			if(obj.responseText != ''){
				$('UserName_ajax').innerHTML = obj.responseText
				$('UserName_ajax').style.display = 'block';
			}
		}
		

	});

	}else{
		$('UserName_ajax').style.display = 'none';
	}
}

function put_username(u) {

	$('UserName_ajax').style.display = 'none';
	$('username').value = u;

}

function valPhone(obj){
	val = obj.value;
	id = obj.id;
	check = $(id).value.substr(($(id).value.length)-1,1);
	if(check!= '+' && check!= '(' && check!= ' ' && check!= ')' && isNaN(check)){
		$(id).value = $(id).value.substr(0, ($(id).value.length)-1);
	}
}

function valNo(obj){
	val = obj.value;
	id = obj.id;
	check = $(id).value.substr(($(id).value.length)-1,1);
	if(isNaN(check)){
		$(id).value = $(id).value.substr(0, ($(id).value.length)-1);
	}
}

function clean(obj){

	obj.value='';
	obj.style.background = '#fff';
	obj.style.color = '#000';
}



function setInner(layer, url_to, message){
	
	advAJAX.setDefaultParameters({
	onInitialization : function(obj) { document.getElementById(obj.tag).innerHTML = message; },
	onLoading : function(obj) { document.getElementById(obj.tag).innerHTML = message; },
	onSuccess : function(obj) { document.getElementById(obj.tag).innerHTML = obj.responseText; },
	onError : function(obj) { document.getElementById(obj.tag).innerHTML = "error: Please press F5 "; }
	});
	advAJAX.get({ tag: layer, url: url_to });

}

function setCont(id,cont){
	$(id).innerHTML = cont;
}

function setVal(id,cont){
	$(id).value = cont;
}

function selectSubCat(id){

	setInner('subCat', 'http://www.gtr.co.uk/plugs/ajax.php?getSubCat='+id, '<select name="subCat" disabled="disabled" ><option>Loading ...</option></select>');
	$('subCat').disabled=false;
	$('subSubCat').innerHTML = '<select name="subSubCat" id="subSubCat_select" disabled="disabled" ><option>Select text ...</option></select>';
	$('subSubCat').disabled = true;

}

function selectSubSubCat(id){

	setInner('subSubCat', 'http://www.gtr.co.uk/plugs/ajax.php?getSubSubCat='+id, '<select name="subCat" disabled="disabled" ><option>Loading ...</option></select>');
	
	$('subSubCat').disabled=false;
	$("buttonSave").disabled=false;
	$("title").disabled=false;
	$("Tparent").value = id;

}

function getRegion(o){

	if(o.value == '0'){
		$('region_city').innerHTML = '<select disabled="disabled" id="region" name="search[region]" style="width:160px;margin-top:4px;margin-bottom:5px;"><option value="0">Please select country ...</option></select>';
	}else{
		setInner('region_city', 'http://www.gtr.co.uk/plugs/ajax.php?getRegion='+o.value, '<select disabled="disabled" id="region" name="search[region]" style="width:160px;margin-top:4px;margin-bottom:5px;"><option value="0">Please wait ...</option></select>');
	}

}

function selectSector(o){

	setInner('SSD', 'http://www.gtr.co.uk/plugs/ajax.php?getSector='+o.value, '<select disabled="disabled" id="Sector_Select" name="sector" style="margin-top:4px;margin-bottom:5px;"><option value="0">Please wait ...</option></select>');
	setCont('JSD','<select disabled="disabled" id="Job_Select" name="job" style="margin-top:4px;margin-bottom:5px;"><option value="0">Please wait ...</option></select>');

}

function deleteJob(id){

	advAJAX.get({
		url: "http://www.gtr.co.uk/plugs/ajax.php?deleteJob="+id,
		onSuccess : function(obj) { void(0); }
	});

	$('JOB_'+id).style.display = 'none';

}

function getJobs(o){

	setInner('JSD', 'http://www.gtr.co.uk/plugs/ajax.php?getJobs='+o.value, '<select disabled="disabled" id="Job_Select" name="job" style="margin-top:4px;margin-bottom:5px;"><option value="0">Please wait ...</option></select>');

}

function loadText(id){

	advAJAX.get({
		url: "http://www.gtr.co.uk/plugs/ajax.php?getText="+id,
		onInitialization : function(obj) {tinyMCE.setContent("Please wait ...");},
		onLoading : function(obj) { tinyMCE.setContent("Please wait ..."); },
		onSuccess : function(obj) { tinyMCE.setContent(obj.responseText); },
		onError : function(obj) { tinyMCE.setContent("error: Please reload page (F5). "); }

	});

	advAJAX.get({
		url: "http://www.gtr.co.uk/plugs/ajax.php?getTitle="+id,
		onInitialization : function(obj) {setVal("title","Please wait ...");},
		onLoading : function(obj) { setVal("title","Please wait ..."); },
		onSuccess : function(obj) { setVal("title",obj.responseText); },
		onError : function(obj) { setVal("title","error: Please reload page (F5). "); }

	});

	advAJAX.get({
		url: "http://www.gtr.co.uk/plugs/ajax.php?getDate="+id,
		onInitialization : function(obj) {setCont("Text_DATE","");},
		onLoading : function(obj) { setCont("Text_DATE","..."); },
		onSuccess : function(obj) { setCont("Text_DATE",obj.responseText); },
		onError : function(obj) { setCont("Text_DATE","error: Please reload page (F5). "); }

	});


	$("saveAs").value = id;
	$("Text_ID").innerHTML = id;
	$("save_info").style.display = 'none';

}

function short_SUB(o){

	if(o.value != 0){
		selectSubSubCat(o.value);
		selectSubCat(o.value);
	}
	
		
	

}

function findPosition( oLink, xORy) {
	if( oLink.offsetParent ) {
		for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
			posX += oLink.offsetLeft;
			posY += oLink.offsetTop;
		}
		if(xORy == 'x'){
			return posX;
		}else{
			return posY;
		}
	} else {
		if(xORy == 'x'){
			return oLink.x;
		}else{
			return oLink.y;
		}
	}
}

function menuShow(id,a) {

	$(id).style.display = 'block';
	$(id).style.left = findPosition(a, 'x')+"px";
	$(id).style.top = (findPosition(a, 'y')+23)+"px";

}

function menuHide(id) {

	$(id).style.display = 'none';

}

function valid_CB(t) {

	if($('perm').checked == true && $('inter').checked == true){
		
		$('inter_select').disabled = true;
		$('inter_div').style.display = 'none';
		$('perm_select').disabled = false;
		$('perm_select').options[0].selected = true;
		$('perm_div').style.display = 'block';

	}
	
	if($('perm').checked == true && $('inter').checked == false){
		
		$('inter_select').disabled = true;
		$('inter_div').style.display = 'none';
		$('perm_select').disabled = false;
		$('perm_select').options[0].selected = true;
		$('perm_div').style.display = 'block';

	}

	if($('perm').checked == false && $('inter').checked == true){

		$('inter_select').disabled = false;
		$('inter_select').options[0].selected = true;
		$('inter_div').style.display = 'block';
		$('perm_select').disabled = true;
		$('perm_div').style.display = 'none';

	}

	if($('perm').checked == false && $('inter').checked == false){

		$('inter_select').disabled = true;
		$('inter_div').style.display = 'none';
		$('perm_select').disabled = true;
		$('perm_select').options[0].selected = true;
		$('perm_div').style.display = 'block';

	}

}

function bg(O, C){

	O.style.background = C;

}

function changeBox(a) {

	if(a == 'Tab_S'){
	
		$('Tab_I').style.background = 'url(tpl/Images/box/industry_c.png) top left';
		$('Tab_I').style.width = '70px';
		$('JobCat').style.display = 'none';
		

		$('Tab_S').style.background = 'url(tpl/Images/box/search_a.png) top left';
		$('Tab_S').style.width = '131px';
		$('searchTab_BOX').style.display = 'block';

	}

	if(a == 'Tab_I'){
	
		$('Tab_I').style.background = 'url(tpl/Images/box/industry_a.png) top left';
		$('Tab_I').style.width = '80px';
		$('JobCat').style.display = 'block';
		

		$('Tab_S').style.background = 'url(tpl/Images/box/search_c.png) top left';
		$('Tab_S').style.width = '121px';
		$('searchTab_BOX').style.display = 'none';

	}

								
}

function DDDM_show(a,b){
	$('DDDM_'+a).style.top = b+'px';
	$('DDDM_'+a).style.display = 'block';
}

function DDDM_hide(a){

	$('DDDM_'+a).style.display = 'none';
	$('parent_of_'+a).className = '';
}

function DDDM_show_OWN(a) {

	$('DDDM_'+a).style.display = 'block';
	$('parent_of_'+a).className = 'DDDM_hover';
	

}

function load(what) {
	
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("G_map"));
		map.addControl(new GSmallMapControl());
		
		if(what == ''){
			what = 'london';
		}
			if(what == 'brighton'){
			map.setCenter(new GLatLng(50.820713,-0.138788), 16);
			$('CITY_MAP').innerHTML = 'Brighton Map';
		}
			if(what == 'london'){
			map.setCenter(new GLatLng(51.515179,-0.081185), 16);
			$('CITY_MAP').innerHTML = 'London Map';
		}
		if(what == 'munchen'){
			map.setCenter(new GLatLng(48.137311,11.577358), 16);
			$('CITY_MAP').innerHTML = 'M&uuml;nchen Map';
		}
			map.addOverlay(new GMarker(map.getCenter()));
		var marker = new GMarker(map.getCenter());
		map.addOverlay(marker);
		
		}
}

function checkSelect(what, name) {

	if(what.value == 0){
		$(name).disabled = false;
	}else{
		$(name).disabled = true;
	}

}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external"){
			anchor.target = "_blank";
		}
	}
}
window.onload = externalLinks;
