var openMenuInt;
var subMenuCount=new Array();
var curSmc;
var dispMethod;
var curSubMenu;

function checkEmail(str) {
///// function for validating email address
		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
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true
 		}
}

function setSmInt(divID)
{
	curSmc=0;
	dispMethod=(document.getElementById("subMenu_"+divID+"_main").style.display=="none")?"inline":"inline";
	if (dispMethod=="inline")
		document.getElementById("subMenu_"+divID+"_main").style.display=dispMethod;

	curSubMenu=divID;
	openMenuInt=setInterval("openSubMenu()",15);
}

function openSubMenu()
{
	if (curSmc < subMenuCount[curSubMenu]){
		document.getElementById("subMenu_"+curSubMenu+"_"+curSmc).style.display=dispMethod;
		curSmc++;
	} else {
		clearInterval(openMenuInt);
		if (dispMethod=="none")
			document.getElementById("subMenu_"+curSubMenu+"_main").style.display=dispMethod;
	}
}

function openCntForm()
{
	if (document.getElementById('contactFormDiv').style.display!="block"){
		document.getElementById('contactFormDiv').style.display="block";
		document.getElementById('wwDiv').style.display="none";
		document.getElementById('mailDistr').style.display = "none";
		document.getElementById('openCntForm_href').firstChild.nodeValue=nogaTpl_closeCntForm;
		document.getElementById('openWW_href').firstChild.nodeValue=nogaTpl_openWW;
	} else {
		document.getElementById('contactFormDiv').style.display="none";
		document.getElementById('openCntForm_href').firstChild.nodeValue=nogaTpl_openCntForm;
	}
}

function openWWmap(){
	if (document.getElementById('wwDiv').style.display!="block")
	{
		document.getElementById('contactFormDiv').style.display="none";
		document.getElementById('wwDiv').style.display="block";
		document.getElementById('mailDistr')	.style.display = "none";
		document.getElementById('openCntForm_href').firstChild.nodeValue=nogaTpl_openCntForm;
		document.getElementById('openWW_href').firstChild.nodeValue=nogaTpl_closeWW;
	} else {
		document.getElementById('wwDiv').style.display="none";
		document.getElementById('openWW_href').firstChild.nodeValue=nogaTpl_openWW;
	}
}

function showDist(curContinent){
	document.getElementById("distFrame").src='showDist.php?curContinent='+curContinent;
}

function checkContactSub()
{
	// fucntion for submitting contact form
	// check for mendatory fields (fullName, email, note)
	if (document.contactForm.fullName.value=="")
	{
		alert (contErr_fullName);
		document.contactForm.fullName.focus();
		return false;
	}
	else if (document.contactForm.email.value=="")
	{
		alert (contErr_email);
		document.contactForm.email.focus();
		return false;
	}
	else if (!checkEmail(document.contactForm.email.value))
	{
		alert (contErr_email);
		document.contactForm.email.focus();
		return false;
	}
	else if (document.contactForm.country.value=="")
	{
		alert (contErr_country);
		document.contactForm.country.focus();
		return false;
	}
	else if (document.contactForm.company.value=="")
	{
		alert (contErr_company);
		document.contactForm.company.focus();
		return false;
	}
	else if (document.contactForm.industry.value=="")
	{
		alert (contErr_industry);
		document.contactForm.industry.focus();
		return false;
	}
	else if (document.contactForm.note.value=="")
	{
		alert (contErr_note);
		document.contactForm.note.focus();
		return false;
	}
	else if (document.contactForm.security_code.value=="")
	{
		alert ("Please type in the text shown in the security image");
		document.contactForm.security_code.focus();
		return false;
	}
	else
	{
		return confirm(contErr_confirm);
	}
}

function checkFeedbackSub()
{
	// fucntion for submitting feedback form
	// check for mendatory fields (fullName, company,country)
	if (document.feedbackForm.fullName.value=="")
	{
		alert (contErr_fullName);
		document.feedbackForm.fullName.focus();
		return false;
	}
	else if (document.feedbackForm.company.value=="")
	{
		alert (contErr_company);
		document.feedbackForm.company.focus();
		return false;
	}
	else if (document.feedbackForm.country.value=="")
	{
		alert (contErr_country);
		document.feedbackForm.country.focus();
		return false;
	}
	else
	{
		// check for feedback answers
		for (i=1; i<=6; i++)
		{
			isChecked=false;
			curQ = document.feedbackForm['q_'+i];
			for (c=0; c<curQ.length; c++)
				if (curQ[c].checked == true)
					isChecked=true;
			if (!isChecked)
			{
				alert (contErr_feedback)
				return false;
			}
		}
		return confirm(contErr_confirm);
	}
}

function showTopic(topicID){
	// close all topics
	nextOpen=(document.getElementById('topic_'+topicID).style.display=="none")?true:false;
	for (i=0;i < totalTopics; i++){
		document.getElementById('topic_'+i).style.display="none";
		document.getElementById('oTopicLink_'+i).firstChild.nodeValue=nogaTpl_viewTopic;
	}
	if (nextOpen){
		document.getElementById('topic_'+topicID).style.display="inline";
		document.getElementById('oTopicLink_'+topicID).firstChild.nodeValue=nogaTpl_hideTopic;
	}
}

function sendDistMail(email_dist)
{

	parent.document.getElementById('openCntForm_href').firstChild.nodeValue = nogaTpl_closeCntForm;
	parent.document.getElementById('openWW_href').firstChild.nodeValue = nogaTpl_openWW;
	parent.document.getElementById('contactFormDiv').style.display = "inline";
	parent.document.getElementById('wwDiv').style.display = "none";
	var mailDistr = parent.document.getElementById('mailDistr');
	mailDistr.innerHTML = nogaTpl_sendTo + email_dist;
	mailDistr.style.display = 'block';
	parent.document.getElementsByName('dist_email')[0].value = email_dist;

}