var menu_selected = 0;
var diplay_status = new Array();
var root_url = "http://whois.to/";

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
var IE67 = "";
var browser = navigator.userAgent.toLowerCase();

//alert(browser);
if(browser.match("msie 6") || browser.match("msie 7"))
{
	var IE67 = true;
}

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

diplay_status["meta_keywords"] = 0;
diplay_status["meta_description"] = 0;
diplay_status["content_type"] = 0;
diplay_status["server_type"] = 0;
diplay_status["response_code"] = 0;

// preload tab images
var preload_images_array = new Array();
preload_images_array[1] = new Image(); preload_images_array[1].src = root_url + "media/images/tab_grey_left.gif";
preload_images_array[2] = new Image(); preload_images_array[2].src = root_url + "media/images/tab_grey_middle.gif";
preload_images_array[3] = new Image(); preload_images_array[3].src = root_url + "media/images/tab_grey_right.gif";
preload_images_array[4] = new Image(); preload_images_array[4].src = root_url + "media/images/tab_darkgreen_left.gif";
preload_images_array[5] = new Image(); preload_images_array[5].src = root_url + "media/images/tab_darkgreen_middle.gif";
preload_images_array[6] = new Image(); preload_images_array[6].src = root_url + "media/images/tab_darkgreen_right.gif";
preload_images_array[7] = new Image(); preload_images_array[7].src = root_url + "media/images/tab_green_left.gif";
preload_images_array[8] = new Image(); preload_images_array[8].src = root_url + "media/images/tab_green_middle.gif";
preload_images_array[9] = new Image(); preload_images_array[9].src = root_url + "media/images/tab_green_right.gif";

function empty_domain_input()
{
	var input_value = "";
	
	input_value = document.forms[0].elements[0].value.toLowerCase();
	
	if(input_value == "ihr-name.de" || input_value == "your-name.com")
	{
		document.forms[0].elements[0].value = "";
	}
}
function select_menu()
{
	document.getElementById("menu_point_selected").style.color = "#fff";
	
	if(document.getElementById("bottom_point_selected"))
	{
		document.getElementById("bottom_point_selected").style.color = "#fff";
	}
}

function display_more(what)
{
	if(diplay_status[what] == 1)
	{
		diplay_status[what] = 0;
		document.getElementById(what).style.display = "none";
	}
	else
	{
		diplay_status[what] = 1;
		document.getElementById(what).style.display = "block";		
	}	
}
function email(name, domain) 
{
	var link_crypted = "";
	link_crypted = "<a href='mailto:" + name + domain + "'>" + name + "</a>";
	
	document.write(link_crypted);
}

function wildcard(what)
{
	switch(what)
	{
		case "whois":
			document.location.href = root_url + "ihr-name";
			break;
		case "sedo":
			document.location.href = root_url + "action/sedo-request/ihr-name";
			break;			
	}
}

function show_infos(what_element)
{
	document.getElementById(what_element).style.display = "block";
	document.getElementById(what_element).style.top = (tempY - 10) + "px";
	document.getElementById(what_element).style.left = (tempX + 10) + "px";
	document.getElementById(what_element).style.zIndex = "10";
	document.getElementById(what_element).style.cursor = "pointer";
	
	
  if (IE) { // grab the x-y pos.s if browser is IE
  	//alert(document.documentElement.scrollTop);
  	
  }	
}

function hide_infos(what_element)
{
	document.getElementById(what_element).style.display = "none";
}
function box_stay_open(what_element)
{
	document.getElementById(what_element).style.display = "block";
}
function box_close(what_element)
{
	document.getElementById(what_element).style.display = "none";
}

function getMouseXY(e) 
{
	if(IE67)
	{
		tempX = event.clientX + document.documentElement.scrollLeft;
		tempY = event.clientY + document.documentElement.scrollTop;
	}
  else if(IE) 
  { // grab the x-y pos.s if browser is IE
  	tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } 
  else 
  {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  // catch possible negative values in NS4
  if(tempX < 0)
  {
  	tempX = 0;
  }
  if(tempY < 0)
  {
  	tempY = 0;
  }  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return true;
}







//formmail functions

/* Trim whitespaces */
function trim(str)
{
	return str.replace(/^\s+|\s+$/g, '')
};



/* Description:	displays a msg to given html-element
 * Inputs: 			id of element to display message, string to display */

function msg(fld, message)
{
  var dispmessage;
  var nbsp = 160;
  var emptyString = /^\s*$/
	var elem = document.getElementById(fld);

  if (emptyString.test(message))
  {
  	dispmessage = String.fromCharCode(nbsp);
 	}
  else
  {
    dispmessage = message;
  }
  
  elem.innerHTML = dispmessage;

};



/* Description:	validates a given email
 * Inputs:			element to validate */

function validateEmail(vfld)
{
	var tfld = trim(vfld.value);
  var email = /^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;


  if(!email.test(tfld))
  {
    vfld.style.backgroundColor = "#ffcccc";
    document.getElementById(vfld.name + "_errorgif").style.visibility = "visible";
    return false;
  }
  else
  {
  	vfld.style.backgroundColor = "#eeeeee";
  	document.getElementById(vfld.name + "_errorgif").style.visibility = "hidden";
	}
};



/* Description:	validates a name-field
 * Inputs:			element to validate, language_key (en, de...) */

function validateUsername(vfld, language_key)
{
	var tfld = trim(vfld.value);
	
	switch(language_key)
	{
		case "de": 
			var username =/^[a-zA-ZäÄöÖüÜß´\-\.\s]*$/; 
		break;
		
  	default: 
  		var username =/^[a-zA-Z´\-\.\s]*$/; 
  	break;
  }

  if(!username.test(tfld))
  {
    vfld.style.backgroundColor = "#ffcccc";
    document.getElementById(vfld.name + "_errorgif").style.visibility = "visible";
    return false;
  }
  else
  {
  	vfld.style.backgroundColor = "#eeeeee";
  	document.getElementById(vfld.name + "_errorgif").style.visibility = "hidden";
	}
};



/* Description:	checks if required form-fields are filled or contain invalid data
 * Inputs:			id of form to check, language key (en, de...)
 * Retrn:				true or false
 *
 * Notes:				- the e-mail field has to be named "email"
 *							- the name fields has to be named "username" */

function checkform(id_form, language_key)
{
	var e = document.getElementById(id_form).elements;
	var x = e.length;
	var no_error = true;		

	for(i=0; i<x; i++)
	{
		if(config["required_fields"].indexOf(e[i].name) != -1 && e[i].value && e[i].name != "")
		{
			e[i].style.backgroundColor = "#eeeeee";
			document.getElementById(e[i].name + "_errorgif").style.visibility = "hidden";
		}

		if(e[i].name == 'username')
		{
			if(validateUsername(e[i], language_key) === false)
			{
				no_error = false;
			}
		}

		if(e[i].name == 'email' && e[i].value)
		{
			if(validateEmail(e[i]) === false)
			{
				no_error = false;
			}
		}

		if(config["required_fields"].indexOf(e[i].name) != -1 && !e[i].value)
		{
			e[i].style.backgroundColor = "#ffcccc";
			document.getElementById(e[i].name + "_errorgif").style.visibility = "visible";			
			no_error = false;
		}
	}
	
	if(no_error == false)
	{
		msg ('error_msg', messages[language_key]["error_message"]); 		
	}
	
	return no_error;
};
