$(document).ready(function(){
	$(".nav").children("li").each(function() {
			var current = "nav current-" + ($(this).attr("class"));
			var parentClass = $(".nav").attr("class");
			if (parentClass != current) {
				$(this).children("a").css({backgroundImage:"none"});
			}
		});
		
	attachNavEvents(".nav", "home");
	attachNavEvents(".nav", "lockbee");
	attachNavEvents(".nav", "support");
	attachNavEvents(".nav", "about");
	attachNavEvents(".nav", "reseller");
	attachNavEvents(".nav", "orderMenu");
	attachNavEvents(".nav", "download");
	
	$('.priceTable tr:even').addClass('even');
	$('.priceTable tr:odd').addClass('odd');
	
//	var o = '<img src=\"gfx/error_small.png\" alt=\"Fyll i fältet korrekt!\" title=\"Fyll i fältet korrekt!\" />';
	
//	$('.foretag').append(o);

});

function attachNavEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				$(this).append('<div class="nav-' + myClass + '"></div>');
				$("div.nav-" + myClass).css({display:"none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.nav-" + myClass).fadeOut(120, function() {
					$(this).remove();
				});
			}).mousedown(function() {
				$("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
			}).mouseup(function() {
				$("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
			});
		}

function SendForm() {
	var args = SendForm.arguments;
	var myForm = args[0];
	var location = args[1];
	var str = $(myForm).serialize();
//	alert(str);
//	var str = $(this).serialize(); 

	$.ajax({  
			type: "POST",  
			url: "validateSerialNr.php",  
			data: str,
			dataType: 'html',			
			error: function(){
				alert('Error loading XML document');
			},
			success: function(xml){
			//	alert(xml);
				var stringValue = String(xml);
				//alert(stringValue);
				if( stringValue=="ok" ) {
				//	alert("hej");
					window.open(location, '_self');
				//	OpenWindowWithPost(location, "blabla", "reset", "true");
				} else {
					alert(stringValue);
				} 
				//$('#content').html(xml);
			}
	}); 
}

function RegisterTestLicense() {
	var args = RegisterTestLicense.arguments;
	var myForm = args[0];
	var location = args[1];
	var str = $('#' + myForm).serialize();
	
	$.showprogress('Registrerar testlicens','Processar data...','<img src="facebox/loading.gif"/>');

	$.ajax({  
			type: "POST",  
			url: "registerTest.php",  
			data: str,
			dataType: 'html',			
			error: function(){
				$.hideprogress();
				alert('Kunde inte ansluta till servern...');
			},
			success: function(xml){
				$.hideprogress();
			//	alert(xml);
				var stringValue = String(xml);
			//	alert(stringValue);
				stringValue = stringValue.replace("<br />", "");
				if( stringValue=="ok" ) {
				//	alert("hej");
					window.open(location, '_self');
				//	OpenWindowWithPost(location, "blabla", "reset", "true");
				} else {
	//				window.open(location, '_self');
					alert(stringValue.replace("<br />", ""));
				} 
			
			}
	}); 
}

function OpenWindowWithPost(url,name,keys,values)
{
	var newWindow = window.open(url, name);
	if (!newWindow) return false;
	var html = "";
	html += "<html><head></head><body><form id='formid' method='post' action='" + url + "'>";
	if (keys && values && (keys.length == values.length))
	for (var i=0; i < keys.length; i++)
	html += "<input type='hidden' name='" + keys[i] + "' value='" + values[i] + "'/>";
	html += "</form><script type='text/javascript'>document.getElementById(\"formid\").submit()</script></body></html>";
	newWindow.document.write(html);
	return newWindow;
}

function SubmitThisForm() {
	var args = SubmitThisForm.arguments;
//	alert(args[0]);
      $(args[0]).submit();
}

function PopUp() {
	var args = PopUp.arguments;
	
	var w = args[0];
	var h = args[1];
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	
	settings = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=no,toolbar=no';
	my_window = window.open("", "mywindow1", settings);
	
//	my_window = window.open ("", "mywindow1","status=1,width=350,height=150,top=\'wint\',left=\'winl\',resizable=0");
	
	if (window.focus) {my_window.focus()};
	
/*
	my_window.document.write('<html>');
	my_window.document.write('<head>');
	my_window.document.write('<title>Lockbee Order Information</title>');
	my_window.document.write('<style type=\'text/css\' media=\'screen\'>@import \'css/main.css\';</style>');
	my_window.document.write('</head>');
	
	my_window.document.write('<body>');
	
	my_window.document.write("<div id=\'textMargin\' >");
	my_window.document.write(args[2]);
	my_window.document.write('<br />'); 
	my_window.document.write('</div>'); 
	my_window.document.write('</body>'); 
	my_window.document.write('</html>'); 
	*/
	my_window.document.close();
				
}


function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }
 
 