var activeSub=0;
var SubNum=0;
function reDo(){ window.location.reload(); }
window.onresize = reDo;
//Define global variables
var timerID = null;
var timerOn = false;
var timecount = 1000;
var newbrowser = true;
var check = false;
function init(){
	//  alert ("Running Init");
	what = whatBrowser_test();
	window.status='status bar text to go here';
	check = true;
}
function whatBrowser_test (){
	var what="none";
	if (document.layers) {
		//  alert ("Running Netscape 4");
        layerRef="document.layers";
        styleSwitch="";
        visibleVar="show";
		//screenSize = window.innerWidth;
		what ="ns4";
	} else if (document.all) {
		//  alert ("Running IE");
        layerRef="document.all";
        styleSwitch=".style";
        visibleVar="visible";
		//screenSize = expression(document.body.clientWidth + 18);
		what ="ie";
	} else if (document.getElementById) {
		//  alert ("Running Netscape 6");
        layerRef="document.getElementByID";
        styleSwitch=".style";
        visibleVar="visible";
		what="moz";
	} else {
	  	//alert("Older than 4.0 browser.");
		what="none";
		newbrowser = false;
	}	
	return what;
}
// get position
function getPositionX( oElement ){
	var iReturnValue = 0;
	var element = document.getElementById(oElement);
	
	while( element != null ) {
		iReturnValue += element.offsetLeft;
		 element = element.offsetParent;
	}
	return iReturnValue;
}
function getPositionY( oElement ){
	var iReturnValue = 0;
	var element = document.getElementById(oElement);
	
	while( element != null ) {
		iReturnValue += element.offsetTop;
		 element = element.offsetParent;
	}
	return iReturnValue;
}

// move layer image
function moveImage(layerName,position_v,position_h,layer_visibility){
	var position_sbmenu = 0;
	var position_sbmenu_v = 0;
	var posx = 0;
	var posy = 0;
	var posH = 0;
	var posV = 0;
	
	if(check){
		<!-- alert(what +' '+layerName+'  '+position_h+'px'); -->
		if (what =="none"){
			return;
		} else if (what == "moz"){
			this.element = document.getElementById(layerName);
			this.onmouseover = dataXY;
			posH = getPositionX('content_center');
			posV = getPositionY('content_center');
			position_h = this.dataX - posH - 120;
			position_v = this.dataY - posV - 120;
			document.getElementById(layerName).style.visibility=layer_visibility;
			document.getElementById(layerName).style.position= "absolute";
			document.getElementById(layerName).style.left= position_h+"px";
			document.getElementById(layerName).style.top= position_v+"px";
			document.getElementById(layerName).style.width= '120px';
   		} else {
			var e = window.event;
			if (e.pageX || e.pageY)	{
				posx = e.pageX;
				posy = e.pageY;
			} else if (e.clientX || e.clientY){
				posx = e.clientX + document.body.scrollLeft;
				posy = e.clientY + document.body.scrollTop;
			}
			posH = getPositionX('content_center');
			posV = getPositionY('content_center');
			position_sbmenu = posx - posH - 120;
			//alert( "POSH: "+posH+" POSV: "+posV+" posx: "+posx+" result: "+position_sbmenu);
			position_sbmenu_v = posy - posV - 120;
            eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layer_visibility+'"');
            eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.left="'+ position_sbmenu+'"');	
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.top="'+ position_sbmenu_v+'"');	
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.width="120px"');	
        }
 	} else {
 		// alert ("Please wait for the page to finish loading.");
		return;
	}
}
	
// Turns the layers on and off
function showLayer(layerName,position_v,position_h,layer_visibility){
	var vertical = 'H';
	showLayer_HV(vertical,layerName,layer_visibility);
	return;
}
function showLayerV(layerName,position_v,position_h,layer_visibility){
	var vertical = 'V';
	showLayer_HV(vertical,layerName,layer_visibility);
	return;
}
function showLayer_HV(vertical,layerName,layer_visibility){
	var posm = 0;
	var posH = 0;
	var posV = 0;
	var position_v = 0;
	var position_h = 0;
	var menu_x;
	
	if(check){
		if (what =="none"){
			return;
		} else if (what == "moz"){
			this.element = document.getElementById(layerName);
			posm = getPositionX('col_center');
			menu_x = 'menu_'+layerName;
			if ( vertical == 'V' ) menu_x = 'menuv_'+layerName;			
			posH = getPositionX(menu_x);
			posV = getPositionY(menu_x);
			position_h = posH - posm;
			if ( vertical == 'V' ) position_h = position_h +120;
			position_v = posV+40;
			if ( vertical == 'V' ) position_v = posV;
			document.getElementById(layerName).style.visibility=layer_visibility;
			document.getElementById(layerName).style.position= "absolute";
			document.getElementById(layerName).style.left= position_h+"px";
			document.getElementById(layerName).style.top= position_v+"px";
			if (layerName != "popup" ) document.getElementById(layerName).style.width= '120px';
   		} else {
			posm = getPositionX('col_center');
			menu_x = 'menu_'+layerName;
			if ( vertical == 'V' ) menu_x = 'menuv_'+layerName;
			posH = getPositionX(menu_x);
			posV = getPositionY(menu_x);
			position_h = posH - posm;
			if ( vertical == 'V' ) position_h = position_h +120;
			position_v = posV +20;
			if ( vertical == 'V' )position_v = posV;			
            eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layer_visibility+'"');
            eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.left="'+ position_h+'"');	
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.top="'+ position_v+'"');	
			if (layerName != "popup" ) eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.width="120px"');	
        }
 	} else {
 		// alert ("Please wait for the page to finish loading.");
		return;
	}	
}
function dataXY(e){
	if (e.pageX || e.pageY)	{
		this.dataX = e.pageX-(screen.width-1000)/2;
		this.dataY = e.pageY;
	} else if (e.clientX || e.clientY){
		this.dataX = e.clientX -(screen.width-1000)/2+100;
		this.dataY = e.clientY + document.body.scrollTop;
	}
	return;
}
	
function hideLayer(layerName){
	if(check){
		if (what =="none"){
			return;
		} else if (what == "moz"){
			document.getElementById(layerName).style.visibility="hidden";
		} else {
        	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
		}
	} else {
		// alert ("Please wait for the page to finish loading.");
		return;
	}
}

function hideAll(nb_layer){
	var i=0;
	var layername_tohide= null;
	for(i=1;i<=nb_layer;i++){
		layername_tohide= 'layer'+i;
		hideLayer(layername_tohide);
	}
}

function startTime() {
    if (timerOn == false) {
        timerID=setTimeout( "hideAll(100)" , timecount);
        timerOn = true;
    }
}

function stopTime() {
    if (timerOn) {
        clearTimeout(timerID);
        timerID = null;
        timerOn = false;
    }
}

function onLoad(){
	init();
}
			
function logout_value(){
	
	document.forms["login"].logout.value = 1;
	document.forms["login"].submit();
}

function modify(){
	
	document.forms["edit"].modify_data.value = 1;
	document.forms["edit"].submit();
}

function confirmDelete(text_confirm,url_delete) {
	var answer = confirm(text_confirm);
	if (answer){
		window.location = url_delete;
	}
	return answer;
}

function setCheckboxes_all() {
    //var checkboxes = document.getElementById('edit').getElementsByTagName('input');
	 var checkboxes = document.getElementsByTagName('input');
	 
    for ( var i = 0; i < checkboxes.length; i++ ) {
        if ( checkboxes[i].type == 'checkbox' ) {
            checkboxes[i].checked = true;
        }
    }
    return true;
} 

function unsetCheckboxes_all() {
    //var checkboxes = document.getElementById('edit').getElementsByTagName('input');
	var checkboxes = document.getElementsByTagName('input');
	
    for ( var i = 0; i < checkboxes.length; i++ ) {
        if ( checkboxes[i].type == 'checkbox' ) {
            checkboxes[i].checked = false;
        }
    }
    return true;
}
	
function show_comment_screen(title, title_comment,comment_error,data_log,g_path,work_url) {
	var URL;
	var stats;
	var com;
	var url_url;
	
	if ( work_url == "" ) {
		url_url = "";
	} else {
		url_url = "&work_url="+ work_url;
	}
	URL = g_path+"comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log+""+url_url;

	if ( comment_error == 0 ) {
		URL = g_path+"comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log+""+url_url;
		stats = "height=50, width=400, scrollbars=no, toolbar=no, location=no, status=no";
	} else {
		URL = g_path+"comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log+""+url_url;	
		stats = "height=500, width=400, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	if ( comment_error == 999 ){
		URL = g_path+"comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log+""+url_url;	
		stats = "height=500, width=600, scrollbars=yes, toolbar=no, location=no, status=yes";
	}

	window.open(URL, "comment", stats);
}

function launch_view_image (path_image){
	var URL;
	var stats;
	
	URL = path_image;
	
	stats = "channelmode=no,titlebar=no,height=300, width=300, scrollbars=yes, toolbar=no, location=no, status=no, resizable=yes, menubar=no, directories=no";
	
	window.open(URL, "IMAGE", stats);
}

function launch_view_news(select_news,g_path,work_url,pdf){
	
	var URL;
	var stats;
	var url_url;
	var pdf_pdf;
	var wNews
	
	if ( work_url == "" ) {
		url_url = "";
	} else {
		url_url = "&work_url="+ work_url;
	}		
	
	pdf_pdf = "";
	if ( pdf == "pdf" ) {
		stats = " scrollbars=yes, toolbar=yes, location=yes, status=yes";
		pdf_pdf = "&pdf=pdf";
		wNews = "NEWS_PDF";
	} else {
		stats = "height=300, width=800, scrollbars=yes, toolbar=no, location=no, status=yes";
		wNews = "NEWS";
	}

	URL = g_path+"view_news.php?select_news=" + select_news+""+url_url+pdf_pdf;
	window.open(URL, wNews, stats);
}

function launch_view_catalogue(select_catalogue,g_path,work_url){
	
	var URL;
	var stats;
	var url_url;
	
	if ( work_url == "" ) {
		url_url = "";
	} else {
		url_url = "&work_url="+ work_url;
	}		
	URL = g_path+"view_catalogue.php?select_catalogue=" + select_catalogue+""+url_url;
	
	stats = "height=600, width=600, scrollbars=yes, toolbar=no, location=no, status=yes";
	
	window.open(URL, "CATALOGUE", stats);
}

function launch_view_conditions(g_path,work_url){
	
	var URL;
	var stats;
	var url_url;
	
	if ( work_url == "" ) {
		url_url = "";
	} else {
		url_url = "&work_url="+ work_url;
	}		
	URL = g_path+"view_conditions.php?"+url_url;
	
	stats = "height=500, width=600, scrollbars=yes, toolbar=no, location=no, status=yes";
	
	window.open(URL, "CONDITIONS", stats);
}

function launch_view_address(address,postcode,town,country,g_path,work_url){
	
	var URL;
	var stats;
	var url_url;
	
	if ( work_url == "" ) {
		url_url = "";
	} else {
		url_url = "&work_url="+ work_url;
	}		
	URL = g_path+"view_address.php?select_address="+address+"&select_postcode="+postcode+"&select_town="+town+"&select_country="+country+""+url_url;
	
	stats = "height=500, width=820, scrollbars=yes, toolbar=no, location=no, status=no";
	
	window.open(URL, "ADDRESS", stats);
}

function launch_view_package(select_package,g_path,work_url){
	
	var URL;
	var stats;
	var url_url;
	
	if ( work_url == "" ) {
		url_url = "";
	} else {
		url_url = "&work_url="+ work_url;
	}			
	URL = g_path+"view_package.php?select_package=" + select_package+""+url_url;
	
	stats = "height=600, width=600, scrollbars=yes, toolbar=no, location=no, status=yes";
	
	window.open(URL, "PACKAGE", stats);
}

function rss_change(){
	document.forms["rss_selection"].modify_rss.value = document.forms["rss_selection"].rss_thema.value;
	document.forms["rss_selection"].submit();
}

function language_change(){
	document.forms["language_selection"].modify_language.value = 1;
	document.forms["language_selection"].submit();
}

function template_change(){
	document.forms["template_selection"].modify_template.value = 1;
	document.forms["template_selection"].submit();
}

function catalogue_change(){
	document.forms["catalogue_selection"].modify_catalogue.value = document.forms["catalogue_selection"].catalogue_thema.value;
	document.forms["catalogue_selection"].submit();
}
function catalogue_change_sub(){
	document.forms["catalogue_selection_sub"].modify_catalogue_sub.value = document.forms["catalogue_selection_sub"].catalogue_thema_sub.value;
	document.forms["catalogue_selection_sub"].submit();
}
function link_change(){
		document.forms["link_selection"].modify_link.value = document.forms["link_selection"].link_unlink.value;
		document.forms["link_selection"].submit();
}
function profile_change(){
		document.forms["profile_selection"].modify_profile.value = document.forms["profile_selection"].profile_thema.value;
		document.forms["profile_selection"].submit();
}
function customer_change(){
		document.forms["customer_selection"].modify_customer.value = document.forms["customer_selection"].customer_thema.value;
		document.forms["customer_selection"].submit();
}
function country_change(){
		document.forms["country_selection"].modify_country.value = document.forms["country_selection"].country_thema.value;
		document.forms["country_selection"].submit();
}
function admin_change(){
		document.forms["admin_selection"].modify_admin.value = document.forms["admin_selection"].admin_thema.value;
		document.forms["admin_selection"].submit();
}
function state_change(){
		document.forms["state_selection"].modify_state.value = document.forms["state_selection"].state_thema.value;
		document.forms["state_selection"].submit();
}
function type_doc_change(){
		document.forms["type_doc_selection"].modify_type_doc.value = document.forms["type_doc_selection"].state_type_doc.value;
		document.forms["type_doc_selection"].submit();
}
function supplier_change(){
		document.forms["supplier_selection"].modify_supplier.value = document.forms["supplier_selection"].state_supplier.value;
		document.forms["supplier_selection"].submit();
}
function content_change(){
		document.forms["content_selection"].modify_content.value = document.forms["content_selection"].content_thema.value;
		document.forms["content_selection"].submit();
}
function payment_change(){
	document.forms["user_selection"].modify_user.value = document.forms["user_selection"].select_user.value;
	document.forms["user_selection"].submit();
}
function payment_change_sup(){
	document.forms["supplier_selection"].modify_supplier.value = document.forms["supplier_selection"].select_supplier.value;
	document.forms["supplier_selection"].submit();
}

function show_invoice_image(connected_user,select_payment,g_path,work_url) {

	var URL;
	var stats;
	var url_url;
	
	if ( work_url == "" ) {
		url_url = "";
	} else {
		url_url = "&work_url="+ work_url;
	}
	URL = g_path+"checkout_invoice.php?select_user=" + connected_user + "&select_payment=" +select_payment+""+url_url;
	stats = "height=600, width=500, scrollbars=yes, toolbar=no, location=no, status=yes, rezisable=yes";
		
	window.open(URL, "invoice", stats);
}