function changeTab(index) {
	for (i = 1; i <= 40; i++) {
		content = document.getElementById("tab" + i + "content");
		tab = document.getElementById("tab" + i);
		field = document.getElementById( "prod_q_" + i );
		
		if ( content ) {
		
			if (i == index  ) {
				//content.style.display = "inline";
				if ( content.style.display == "inline" ) {
					content.style.display = "none";
				} else {
					content.style.display = "inline";
					field.focus();
				}
			} else {
				content.style.display = "none";
			}
			
		}
	}
}
function changeTabIndex(index) {
	for (i = 1; i <= 40; i++) {
		content = document.getElementById("indextab" + i + "content");
		tab = document.getElementById("indextab" + i);
		
		
		if ( content ) {
		
			if (i == index  ) {
				//content.style.display = "inline";
				if ( content.style.display == "inline" ) {
					content.style.display = "none";
				} else {
					content.style.display = "inline";
				}
			} else {
				content.style.display = "none";
			}
			
		}
	}
}



function popup(link,name,x,y,res,scroll,tool) {

window.open(link,name,'width='+x+',height='+y+',resizable='+res+',status=0,scrollbars='+scroll+',top=0,left=0,toolbar='+tool);

}


function ConfirmChoice(message,new_url) {

	answer = confirm(message)
	if (answer !=0) {
		location = new_url
	}
}







var http_request = false;
function makePOSTRequest(url, parameters, mode) { // mode: alert, site, menu
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  if ( mode == 'alert' ) {
	  http_request.onreadystatechange = alertContents;
  }
  if ( mode == 'site' ) {
	  http_request.onreadystatechange = siteContents;
  }
  if ( mode == 'menu' ) {
	  http_request.onreadystatechange = menuContents;
  }
  if ( mode == 'tcb' ) {
	  http_request.onreadystatechange = tcbContents;
  }
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}



function alertContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		alert(result);
		changeTab(0);            
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}


function siteContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		document.getElementById('sitecontent').innerHTML = result;            
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}


function menuContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		document.getElementById('menucontent').innerHTML = result;            
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}


function tcbContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		document.getElementById('topcolorbox').innerHTML = result;            
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}







function fillCont(vars, cont) {
  makePOSTRequest('process.php', vars, cont);
}

function languageChange() {
  var poststr = "&s=settings" +
  "&action=setlanguage" +
  "&newcurrency=" + encodeURI( document.getElementById( 'languageChoose' ).value );
  makePOSTRequest('process.php', poststr, 'alert');
}

function submitReg(step) {
  if ( step == 1) {
    var poststr = "&s=reg" +
    "&action=2step2" +
    "&email=" + encodeURI( document.getElementById( 'email' ).value ) +
    "&login=" + encodeURI( document.getElementById( 'login' ).value ) +
    "&chapta=" + encodeURI( document.getElementById( 'chapta' ).value );
  }
  
  if ( step == 2) {
    var poststr = "&s=reg" +
    "&action=2step3" +
    "&pass1=" + encodeURI( document.getElementById( 'pass1' ).value ) +
    "&pass2=" + encodeURI( document.getElementById( 'pass2' ).value );
  }
  
  makePOSTRequest('process.php', poststr, 'tcb');
}

function submitLogin() {
  var poststr = "&s=loginbox" +
  "&login=" + encodeURI( document.getElementById( 'login' ).value ) +
  "&password=" + encodeURI( document.getElementById( 'password' ).value );
  
  makePOSTRequest('process.php', poststr, 'tcb');
}

function submitLogout() {
	var poststr = "&s=logout";
  	makePOSTRequest('process.php', poststr, 'tcb');
}