/**
* Java Script functions
* (c)2008 Martin Tomsik - Bite A Bit Ltd. [ http://www.biteabit.net ]
*/

/* Image buttons */
function buttHover(buttName,step) {
	if(step==1)
		document.getElementById(buttName).src='images/'+buttName+'-2.png';
	else if(step==0)
		document.getElementById(buttName).src='images/'+buttName+'.png';
	return true;
}

/* Confirming URL */
function confirmUrl(msg,url){
	var answer = confirm(msg);
	if(answer){
		window.location=url;
	}else{
		return false; 
	}
}

/* Form submit confirmation */
function confirmFormSubmit(msg,formName) {
	var answer = confirm(msg);
	if(answer){
		document.forms[formName].submit();
	}else{
		return false; 
	}
}

/**!
Shows an inner HTML on mouse over event in the specified element (id, resp.)
*/
function menuDescPopup(id,text){
	document.getElementById(id).innerHTML=text + '<!--&nbsp;&nbsp;<span style="cursor:pointer;font-size:9px;color:red;float:right;" onclick="javascript:document.getElementById(\''+id+'\').style.display=\'none\'">x</span>-->';
	document.getElementById(id).style.display = 'block';
}
function menuDescPopout(id,milliseconds){
	// setTimeout("document.getElementById(\'"+id+"\').style.display='none'", milliseconds);
}


/****************************** Form check *********************************/
function formCheck(formName,fieldName,fieldNameDesc,minLenght,maxLenght,dataType) {
	
	var e = document.getElementById(fieldName);
	
	/* Checking data type [any, integer, character, email, telephone, url] */
	switch(dataType){
	case "integer": 
	  if( typeof(e.value) != "integer"  ) { 
		//window.alert(fieldNameDesc + ' may only be a number!');
		//e.focus();
		//return false;
	  }
	  break;    
	case "character":
	  
	  break;
	case "email":
	  if(e.value.indexOf("@")>0){ 
		return true;
	  }else{
		window.alert("The email address is not correct!");
		return false;
	  }
	  break;
	case "telephone":
	  
	  break;
	case "url":
	  
	  break;
	default:
	  // do nothing
	}
  
  
	/* Checking length */
	if(e.value.length < minLenght   ||   e.value.length > maxLenght) { 
		window.alert(fieldNameDesc+' may be '+minLenght+' - '+maxLenght+' characters long.' );
		e.focus();
		return false;
	}else{
		return true;
	}
}

function formCheckHighlightError(formName,fieldName,minLenght,maxLenght,colorError,colorNormal){

	if(navigator.appName.indexOf("Netscape") != -1 || navigator.appName.indexOf("Opera") != -1){
		// ok
	}else{
		return(false);
	}

	if(document.getElementById){
		var e = document.getElementById(fieldName);
		var e_errMsg = document.getElementById('msg_'+fieldName);
	}else if (document.all){
		var e = document.all[fieldName];
		var e_errMsg = document.all['msg_'+fieldName];
	}
	//alert('msg_'+fieldName);
	if(e.value.length>maxLenght || e.value.length<minLenght){
		e.style.color=colorError;
		popErrorMessage('msg_'+fieldName,1);
		e_errMsg.innerHTML=' '+minLenght+' - '+maxLenght+' characters';
		return true;
	}else if(e.value.length<=maxLenght && e.value.length>=minLenght){
		e.style.color=colorNormal;
		popErrorMessage('msg_'+fieldName,0);
		return false;
	}
}

function popErrorMessage(id,show) {
	if(document.getElementById){
		var e = document.getElementById(id);
	}else if (document.all){
		var e = document.all[id];
	}

	if(show==0){
		//e.style.visibility = "hidden";
		e.style.display = "none";
	}else{
		//e.style.visibility = "visible";
		e.style.display = "block";
	}
}

/****************************** / Form check *********************************/


/* Pop-up layers */
function popShow(object) {
    if(document.getElementById){
		document.getElementById(object).style.visibility="visible";
	}
	else if (document.all){
        document.all[object].style.visibility="visible";
	}
}
function popHide(object) {
  if (document.getElementById)
		document.getElementById(object).style.visibility="hidden";
	else if (document.all)
        document.all[object].style.visibility="hidden";
}

function popShowHtml(id,imgFile) {
  document.writeln('<div id="'+ id +'" class="popupScreenshot" style="visibility:hidden;">');
  document.writeln('<img src="'+ imgFile +'" alt=" " />');
  document.writeln('</div>');
}
