var timeout	= 300;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(menuNo)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById("topMenuBoxSubmenu" + menuNo);
	if(ddmenuitem) ddmenuitem.style.visibility = 'visible';
	for (i = 0; i < 4; i++) {
		if (i != menuActive) {
			document.getElementById("topMenuBox" + i).style.background="#d8d83c";
		}
	}
	if (menuActive != menuNo) {
		document.getElementById("topMenuBox" + menuNo).style.background="#0079ba";
		menuShow = menuNo;
	}

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	for (i = 0; i < 4; i++) {
		if (i != menuActive) {
			document.getElementById("topMenuBox" + i).style.background="#d8d83c";
		}
	}
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 

function home(address)
{
	window.location.href = address;
}

function verifyEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false;
	 }

	 if (str.indexOf(" ")!=-1){
		return false;
	 }

	 return true;
}

function CCSubmit(obj, languageId) {

	if ((obj.fullName.value != "") && (obj.street.value != "") && (obj.no.value != "") && (obj.company.value != "") && (obj.city.value != "") && (obj.county.value != "") && (obj.quantity.selectedIndex != 0) && ((obj.packageType1.checked == true) || (obj.packageType2.checked == true) || (obj.packageType3.checked == true))) {
			    xmlhttp=null;
			    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
				    xmlhttp=new XMLHttpRequest();
			    } else {// for IE5, IE6
				    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			    }

			    var url = "procCC.jsp";
			    var params = "";

			    params += "&language=" + languageId;
			    params += "&fullName=" + obj.fullName.value;
			    params += "&phone=" + obj.phone.value;
			    params += "&company=" + obj.company.value;
			    params += "&city=" + obj.city.value;
			    params += "&county=" + obj.county.value;
			    params += "&street=" + obj.street.value;
			    params += "&no=" + obj.no.value;
			    params += "&building=" + obj.building.value;
			    params += "&entrance=" + obj.entrance.value;
			    params += "&floor=" + obj.floor.value;
			    params += "&ap=" + obj.ap.value;
			    params += "&fax=" + obj.fax.value;
			    params += "&email=" + obj.email.value;
			    params += "&packageType1=" + obj.packageType1.checked;
			    params += "&packageType2=" + obj.packageType2.checked;
			    params += "&packageType3=" + obj.packageType3.checked;
			    params += "&iWant=" + obj.iWant.selectedIndex;
			    params += "&quantity=" + obj.quantity.selectedIndex;

			    xmlhttp.open("POST", url, true);

			    //Send the proper header information along with the request
			    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			    xmlhttp.setRequestHeader("Content-length", params.length);
			    xmlhttp.setRequestHeader("Connection", "close");

			    xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
				    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					    document.getElementById("ccForm").innerHTML = xmlhttp.responseText;
				    }
			    }
			    xmlhttp.send(params);
	} else {
	    var message = "Va rugam sa completati toate campurile!";
	    if (languageId == 2) {
		message = "Please fill in all fields!";
	    }
	    if (languageId == 3) {
		message = "!";
	    }
	    alert(message);
	}
}

function popupWindow(URL, width, height)
{
    var name = "Name";
    var prop;
    var w = 650;
    var h = 525;
    if (width != null) w = width;
    if (height != null) h = height;
    prop = 'directories=0,';
    prop += 'dependent=0,';
    prop += 'height='+h+',';
    prop += 'location=0,';
    prop += 'menubar=0,';
    prop += 'resizable=0,';
    prop += 'scrollbars=0,';
    prop += 'status=0,';
    prop += 'width='+w+',';
    prop += 'screenX='+parseInt((screen.availWidth-w)/2)+',';
    prop += 'screenY='+(parseInt((screen.availHeight-h)/2)-20)+',';
    prop += 'top='+(parseInt((screen.availHeight-h)/2)-20)+',';
    prop += 'left='+parseInt((screen.availWidth-w)/2)+',';
    prop += 'toolbar=0';
    window.open(URL, (name + width), prop);
}

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-5031840-22']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
