function preloadImages() {
 if (document.images) {
  var imgFiles = preloadImages.arguments;
   if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
     with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!='#'){
       preloadArray[i] = new Image;
         preloadArray[i++].src = imgFiles[j];
	  } }
	  }
	  
	  
function openbignewgoodwindow (path_im,image_src, image_width, image_height, title_date, image_text) {
  image_id = 1;
  //alert(image_id);
  image_var = "<img src='"+ path_im + image_src + "' width='" + image_width + "' height='" + image_height + "' alt='" + image_text +"' title='" + image_text +"' border='0'>";
  var myWin, my_left;
  my_left=(screen.width/2);
//  if(image_text!=''){ image_height=parseInt(image_height) + 15*parseInt(Math.ceil(image_text.length*7/image_width)); }
  open_window_string = "myWin = open('','"+ image_id +"','width="+image_width+",height="+image_height+",directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no,top=10,left=10');";
  eval(open_window_string);
  myWin.document.open();
  myWin.document.write("<HTML>\n<HEAD>\n<TITLE>");
  myWin.document.write(title_date);
  myWin.document.write("</TITLE>\n");
  myWin.document.write("<META name='other.language' content='ukrainian,russian,english'>\n");
  myWin.document.write("<META http-equiv='content-type' content='text/html; charset=windows-1251'>\n\n");
  myWin.document.write("<link rel='stylesheet' type='text/css' href='css/glamain.css'>\n");
  myWin.document.write("</HEAD>\n");
  myWin.document.write("<body onLoad='focus();' bgcolor='#FFFFFF' text='#4F4F4F' link='#000000' vlink='#000000' alink='#000000' leftmargin='0' topmargin='0' rightmargin='0' bottommargin='0' marginwidth='0' marginheight='0'>\n\n");
  myWin.document.write("<table border=0 cellpadding=0 cellspacing=0 width=100% >\n");
  myWin.document.write("<tr><td align=middle valign=top onclick='window.close();'>\n");
  myWin.status="SINGLE CLICK - CLOSE WINDOW";
  myWin.document.write(image_var);
//  myWin.document.write("<br>"+image_text);
  myWin.document.write("</td></tr>");
  if (navigator.appName=="Microsoft Internet Explorer") {
    myWin.document.write("<tr><td align=middle class=mainsm valign=center>\n");
    myWin.document.write("\n");
    myWin.document.write("</td></tr>\n");
  }
  myWin.document.write("</table>\n</body>\n</html>\n");
  myWin.document.close();
}

function changecurr(curr) {
changecss('.uah', 'display', 'none');
changecss('.usd', 'display', 'none');
changecss('.eur', 'display', 'none');
changecss('.rur', 'display', 'none');

if (document.getElementById('uah') != null) document.getElementById('uah').className='aslink';
if (document.getElementById('usd') != null) document.getElementById('usd').className='aslink';
if (document.getElementById('eur') != null) document.getElementById('eur').className='aslink';
if (document.getElementById('rur') != null) document.getElementById('rur').className='aslink';

if (document.getElementById('uahc') != null) document.getElementById('uahc').className='aslink';
if (document.getElementById('usdc') != null) document.getElementById('usdc').className='aslink';
if (document.getElementById('eurc') != null) document.getElementById('eurc').className='aslink';
if (document.getElementById('rurc') != null) document.getElementById('rurc').className='aslink';

changecss('.'+curr, 'display', 'inline');
if (document.getElementById(curr) != null) document.getElementById(curr).className='asnolink';
if (document.getElementById(curr+'c') != null) document.getElementById(curr+'c').className='asnolink';
}

function changecss(theClass,element,value) {
//Last Updated on May 21, 2008
//documentation for this script at
//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
 var cssRules;
 if (document.all) {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }
 var added = false;
 for (var S = 0; S < document.styleSheets.length; S++){
  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
    if(document.styleSheets[S][cssRules][R].style[element]){
    document.styleSheets[S][cssRules][R].style[element] = value;
    added=true;
	break;
    }
   }
  }

  if(!added){
  if(document.styleSheets[S].insertRule){
		  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
		} else if (document.styleSheets[S].addRule) {
			document.styleSheets[S].addRule(theClass,element+': '+value+';');
		}
  }
 }
}
function AddHDD() {
  vendorSelect = document.forms['vendor'].vs;
  vendorName = vendorSelect.options[vendorSelect.selectedIndex].value;
//  calc = 'calc_' + vendorName;

  HDD2 = document.getElementById('hdd2_'+vendorName);
//  HDD2 = document.forms[calc].HDD2;

  qHDD = document.forms[calc].qHDD;
  qHDD2 = document.forms[calc].qHDD2;


  if (qHDD2.value=="0") {
    qHDD2.value="1";
    if (document.all)
      HDD2.style.display="block";
    else
      HDD2.style.display="table-row";
    document.getElementById('addhdd2').title="Убрать дополнительный HDD";
    document.getElementById('addhdd2').innerHTML="-";
  } else {
    qHDD2.value="0";
    HDD2.style.display="none";
    document.getElementById('addhdd2').title="Добавить дополнительный HDD";
    document.getElementById('addhdd2').innerHTML="+";
  }
  checkCompatibility();
}

function checkCompatibility(form) {
  vendorSelect = document.forms['vendor'].vs;
  vendorName = vendorSelect.options[vendorSelect.selectedIndex].value;
  calc = 'calc_' + vendorName;
  alert(calc);
  
  CPU = form.CPU;
  RAM = document.forms[calc].RAM;

  qRAM = document.forms[calc].qRAM.value == "" ? 0 : parseInt(document.forms[calc].qRAM.value);
  qCPU = document.forms[calc].qCPU.value == "" ? 0 : parseInt(document.forms[calc].qCPU.value);

  cpu_class  = CPU.options[CPU.selectedIndex].className;
  ram_class  = RAM.options[RAM.selectedIndex].className;

  qhdd1 = document.forms[calc].qHDD.value == "" ? 0 : parseInt(document.forms[calc].qHDD.value);
  qhdd2 = document.forms[calc].qHDD2.value == "" ? 0 : parseInt(document.forms[calc].qHDD2.value);

// больше 4 дисков нельзя
  if (qhdd1+qhdd2 > 4) {
    if (qhdd2 != 0) {
      AddHDD();
    } 
    qhdd1 = document.forms[calc].qHDD.value = 1;
    qhdd2 = document.forms[calc].qHDD2.value = 0;
    alert('Если вам необходим сервер с большим к-вом дисков (больше 4) - свяжитесь с нашим менеджером для заказа: +380 (44) 360-23-03, sales@data-xata.com');
    return false;
  }
//для десктопной системы выбирать 1 CPU
  if (cpu_class!="x2cpu") {
    document.forms[calc].qCPU.value = 1;
  }  
//для двухпроцессорной системы выбирать соответствующую память
  if (ram_class!="x2cpu" && cpu_class=="x2cpu") {
    RAM.selectedIndex++;
	checkCompatibility();
  }

//для серверной системы не позволять выбирать память для двухпроц.систем
  if (cpu_class=="x1cpu_s" && ram_class=="x2cpu") {
    RAM.selectedIndex--;
	checkCompatibility();
  }
//для десктопной системы выбирать соответствующую память
  if (cpu_class=="x1cpu_d" && ram_class!="x1cpu_d") {
    RAM.selectedIndex--;
	checkCompatibility();
  }

//для однопроцессорных систем не давать выбрать более 4 слотов памяти
  if (qRAM > 4) {
    document.forms[calc].qRAM.value=4;
    alert("Если вам необходим сервер с большим к-вом памяти (больше 16Гб) - свяжитесь с нашим менеджером для заказа: +380 (44) 360-23-03, sales@data-xata.com");
  }
  if (document.forms[calc].qCPU.value > 2)
    document.forms[calc].qCPU.value=2;
  if (document.forms[calc].qCPU.value=="" || document.forms[calc].qCPU.value==0)
    document.forms[calc].qCPU.value=1;
  if (document.forms[calc].qRAM.value=="" || document.forms[calc].qRAM.value==0)
    document.forms[calc].qRAM.value=1;
  if (document.forms[calc].qHDD.value=="" || document.forms[calc].qHDD.value==0)
    document.forms[calc].qHDD.value=1;

  return true;

}
function changeVendor() {
  vendorSelect = document.forms['vendor'].vs;
  vendorName = vendorSelect.options[vendorSelect.selectedIndex].value;
  calc = 'calc_' + vendorName;

  document.getElementById('table_hv').style.display="none";
  document.getElementById('table_xs').style.display="none";
  document.getElementById('table_sm').style.display="none";
  document.getElementById('table_hp').style.display="none";
  
  document.getElementById('table_'+vendorName).style.display="block";
}

function showq(q) {
  if (document.getElementById(q).style.display=="none") {
    document.getElementById(q).style.display="block";
  } else {
    document.getElementById(q).style.display="none";
  }
}
