function winWid(){
	//define browser
	var ns4 = (document.layers) ? 1 : 0;
	var ie4 = (document.all) ? 1 : 0;
	var ns6 = (document.getElementById && !document.all) ? 1 : 0;
   return (ns4||ns6) ? window.innerWidth : document.body.clientWidth;
}

function winHei(){
//define browser
	var ns4 = (document.layers) ? 1 : 0;
	var ie4 = (document.all) ? 1 : 0;
	var ns6 = (document.getElementById && !document.all) ? 1 : 0;
   return (ns4||ns6) ? window.innerHeight : document.body.clientHeight;
}

function openwin(filename, width, height) {
	winWidth = winWid();
	winHeight = winHei();
	topPos = (parseInt(winHeight)-parseInt(height))/2;
	topPos = (topPos<0) ? 5:topPos;
	leftPos = (parseInt(winWidth)-parseInt(width))/2;
	leftPos = (leftPos<0) ? 5:leftPos;
	params='width='+width+',height='+height+',left='+leftPos+',top='+topPos+',toolbar=no,scrollbars=yes,resizable=no, status=no';
	newWin = window.open(filename, 'nextstep', params);
	newWin.focus();
}

function setCheckboxes(the_form, do_check, elementname) {
    var items_to_delete			= document.forms[the_form].elements[elementname+'[]'];
    var items_to_delete_num  = items_to_delete.length;

    for (var i = 0; i < items_to_delete_num; i++) {
        items_to_delete[i].checked = do_check;
    } // end for

    return true;
} // end of the 'setCheckboxes()' function

function operateCheckBoxes(e, the_form, elementname) {
//	alert(document.forms[the_form].elements[obj].checked);
//	alert(obj);
	if (e.checked) {
		setCheckboxes(the_form, true, elementname); 
		return false;
	} else {
		setCheckboxes(the_form, false, elementname);
		return false;
	}
}

//begin 8.10.2007 Pavlina
//AJAX Functions - use jquery-1.1.3.1.js
function GetLocations() 
{
	if (document.getElementById("region").value!="")
	{
		var url="index.php";		
		jsreg=toLat(document.getElementById("region").value);
		if (document.getElementsByName("region_type")[0].checked==true)
		{
			jsreg_type=document.getElementsByName("region_type")[0].value;
		}
		else
		{
			jsreg_type=document.getElementsByName("region_type")[1].value;
		}
		document.getElementById("location").style.display = 'block';
		document.getElementById("location").innerHTML = '';
		$.get(url, {ajax: 'get', jsregion: jsreg, jsregion_type: jsreg_type},
				  function(data)
				  {
					 var xmlDoc=data.documentElement;
					 var length = xmlDoc.getElementsByTagName("name").length;
					 var id;
					 var name;
					 var html = '';
					 for (var i=0; i<length; i++)
					 {
						 id = xmlDoc.getElementsByTagName("id")[i].childNodes[0].nodeValue;
						 name = xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue;					
						 html += '<input id="location_'+id+'" name="location[]" value="'+name+'" type="checkbox"> <label for="location_'+id+'">'+name+'</label><br />';
					 }
					 document.getElementById("location").innerHTML = html;
				  }
			 );
	}
	else
	{
		document.getElementById("location").style.display = 'none';
		document.getElementById("location").innerHTML = '';
	}	
}

function toLat(cyr) {
	C=new Array(
  'À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î',
  'Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù','Ú','Ü','Þ','ß',
  'à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î',
  'ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','ü','þ', 'ÿ');

	L=new Array(
  'A','B','V','G','D','E','Zh','Z','I','J','K','L','M','N','O',
  'P','R','S','T','U','F','H','C','Ch','Sh','Sht','Y','J','Ju','Q',
  'a','b','v','g','d','e','zh','z','i','j','k','l','m','n','o',
  'p','r','s','t','u','f','h','c','ch','sh','sht','y','j','ju', 'q');

	Lat=new Array();
	for (q=0;q<60;q++) Lat[C[q]]=L[q];

  lat=''
  for (q=0;q<cyr.length;q++) {
    ch=cyr.charAt(q)

    if (Lat[ch]) {
      lat+=Lat[ch]

      chL=Lat[ch].toLowerCase()
      nxt=cyr.charAt(q+1)
      if ((chL=='z' || chL=='s') && Lat[nxt]) {
        if (Lat[nxt]=='h') {lat+='x'; q++}
        else if (Lat[nxt]=='H') {lat+='X'; q++}
      }

    }
    else if (ch==unescape('%FF')) lat+='ja'
    else lat+=ch
  }
  return lat
}
//end 8.10.2007 Pavlina

//begin 7.11.2007 Pavlina
function ShowTab(tab)
{
	//var all_tabs_ids = new Array('description', 'similar', 'payment_delivery', 'inquiry', 'order');
	var all_tabs_ids = new Array('tab1', 'tab2', 'tab3','tab4');	
	for (i=0;i<all_tabs_ids.length;i++)
	{
		if (all_tabs_ids[i] != tab)
		{
			document.getElementById(all_tabs_ids[i]).style.display = 'none';
		}
	}
	document.getElementById(tab).style.display = 'block';
}
//end 7.11.2007 Pavlina
