var isIE = false;
var isIE6 = false;
var fname='';

var oldonload = window.onload;

if (typeof window.onload != 'function') { 
 window.onload = myOnload; 
}
else { 
  window.onload = function() {oldonload(); myOnload(); }
}



function myOnload() {

// reduce image flicker in IE6
 if (isIE6) {
   try {
     document.execCommand('BackgroundImageCache', false, true);
   } 
   catch(e) {}; // ignore it
 }

 isIE = isIE || (document.all && !window.opera);
}

function shadow(onOff,id) {

 var objLayer = document.getElementById("background"); if(!objLayer) return;
 var objTarget= document.getElementById(id); //if(!objTarget) return;
 if (isIE) objLayer.style.height = document.body.clientHeight;
 objLayer.style.display=(onOff ? "block":"none");
 objTarget.style.display=(onOff ? "block":"none");

 objTarget.style.left = (document.body.clientWidth - objTarget.clientWidth) / 2 + 'px'; //

}

function show_me(idA){
 if(!idA) return; 
 var objA = document.getElementById(idA); if (!objA) return;
 var objTD = objA.parentNode; if (objTD.className=='active') return;
   objA = objTD.parentNode; /* tr, ul */
   var objD=null;
   for(j=0;j<objA.childNodes.length;j++) {
    objD =objA.childNodes[j];
    if (objD.tagName=='TD' || objD.tagName=='LI') {
      objD.className='item'; // td, li
      objD = document.getElementById(objD.childNodes[0].id+'t');
      if(objD) objD.style.display='none';
    }
  }

 objTD.className='active'; 
 objA = document.getElementById(idA+'t'); if(!objA) return;
 objA.style.display='block';
 
}

/* 17.03.09 */
function show_brandinfo(objB, idHideBox) {
 if(!objB) return; 
var objD = document.getElementById(idHideBox);  if(!objD) return;
var strF=(objD.style.display=='none' ? '_off' :'_on'), strR=(strF=='_on' ? '_off' :'_on');
    objD.style.display=(objD.style.display=='none' ? '' :'none');
    objB.parentNode.className = objB.parentNode.className.replace(strF, strR);
}

var xDiv = document.createElement('DIV');
xDiv.className = 'vars_box';
var firstModel='', firstLoading=false;
var maxIdx=5;

function shiftLeftRight(idList, dirLeftRight){
	
$("a[rel^='prettyPhoto']").prettyPhoto({ animationSpeed: 'normal', padding: 40, opacity: 0.35, showTitle: true, allowresize: true, counter_separator_label: '/', theme: 'light_rounded', callback: function(){} });
	
 var list = document.getElementById(idList);
 if(!list) return; 


 if(!firstLoading) {
  for(i=0; i<list.childNodes.length; i++){
   if(list.childNodes[i].nodeName!='DIV' || list.childNodes[i].style.display=='none') { list.removeChild(list.childNodes[i]); i--;}
  } 
  try { firstLoading=true; firstModel=list.childNodes[0].getElementsByTagName('a')[0].id;}
  catch(e) {}
 }

try {

 var N =list.childNodes.length-1;
 if(N<maxIdx) return; // scroll need only for 6..N models

 if(dirLeftRight){ // left = true

  if(list.childNodes[0].getElementsByTagName('a')[0].id==firstModel) return;

  xDiv.innerHTML = list.childNodes[N].innerHTML; 

  for(i =N; i>0; i--){
   list.childNodes[i].innerHTML = list.childNodes[i-1].innerHTML;
  }
  list.childNodes[0].innerHTML = xDiv.innerHTML; 

 } else {

  if(list.childNodes[maxIdx].getElementsByTagName('a')[0].id==firstModel) return;

 xDiv.innerHTML = list.childNodes[0].innerHTML;
 for(i =0; i<N; i++){
   list.childNodes[i].innerHTML = list.childNodes[i+1].innerHTML;
 }
 list.childNodes[N].innerHTML = xDiv.innerHTML;
 }

} catch(e) {}

} 

function clean(a, id, idfocus){
 if (!id) { var p=a.previousSibling; } 
 else { var p = document.getElementById(id);}
 if(p){ 
   p.style.top="-9999px";
   a.onblur=function(){ if(!a.value){ p.style.top=""; } };
 }
 if (idfocus) {
  p1=document.getElementById(idfocus);
  if(p1) p1.focus();
 }
}


function setSearchText(id,obj_){
 var obj= document.getElementById(id);
 if (!obj) return;
 clean(obj);
 obj.value = obj_.innerHTML;
}



function overOut(obj, isOver){

// if (!isIE6) return;
 while (obj.tagName!='LI' && obj.tagName!='BODY'){
  obj=obj.parentNode;
 }
 if (obj.tagName!='LI') return;

 var liCss = obj.className; //.parentNode.parentNode.className;

 if (isOver) { liCss = liCss.replace('_item', '_over'); }
 else { liCss = liCss.replace('_over', '_item'); }

 obj.className = liCss;
}


 function more_text() {
 var mainId='main_dop', dspl=document.getElementById(mainId).style.display;
   document.getElementById(mainId).style.display=(dspl=='block'?'none':'block'); 
}

function check_form(objForm) {
  var error_message = "JS_ERROR\n";
  var error_found = false;
  var error_field;
  var name = objForm.name.value;
  var phone = objForm.phone.value;
  var email = objForm.email.value;
  var message = objForm.message.value;
                                              //|| ((phone == '') || (phone.length < 1))
  if (((name == '') || (name.length < 1))  || ((message == '') || (message.length < 1)) ||
	((email == '') || (email.length < 6))) {

    error_message = error_message + "* ERROR_AT_LEAST_ONE_INPUT\n";
      if (message.length < 1) error_field = objForm.message;
      if (email.length < 1) error_field = objForm.email;
      if (name.length < 1) error_field = objForm.name;
    error_found = true;
  }

  if (name.length >0 && name.length < 2) {
      error_message = error_message + "* ERROR_NAME_TO_MUST_BE_FILLED\n";
      error_field = objForm.name;
      error_found = true;
  }

  if (phone.length > 0) {
   str = phone.replace(/ /g,'');
   str = str.replace(/-/g,'');
   str = str.replace('(','');
   str = str.replace(') ','');
   phone_int = parseInt(str);
   if (isNaN(phone_int) || String(phone_int).length!=str.length) {
      error_message = error_message + "* ERROR_PHONE_TO_MUST_BE_VALID\n";
      error_field = objForm.phone;
      error_found = true;
   }
  }

  if (email.length > 0) {

    if (!checkEmail(email)) {
      error_message = error_message + "* ERROR_EMAIL_TO_MUST_BE_VALID\n";
      error_field = objForm.email;
      error_found = true;
    }
  }

  if (message.length > 0 && message.length <2) {
      error_message = error_message + "* ERROR_MESSAGE_TO_MUST_BE_FILLED\n";
      error_field = objForm.message;
      error_found = true;
  }


  if (error_found == true) {
    alert(error_message);
    error_field.focus();
    return false;

  } else {

    return true;
  }
}

function checkEmail(checkString)
{
    var newstr = "";
    var at = false;
    var dot = false;

    // DO SOME PRELIMINARY CHECKS ON THE DATA

    // IF EMAIL ADDRESS HAS A '@' CHARACTER
    atPos = checkString.indexOf("@");
    if (atPos > 0 && atPos < checkString.length-4) {
      at = true;
    }
    // IF EMAIL ADDRESS HAS A '.' CHARACTER
    atPos = checkString.lastIndexOf(".");
    if (atPos > 1 && atPos < checkString.length-2) {
      dot = true;
    }
    // PARSE REMAINDER OF STRING
    for (var i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i + 1)
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                newstr += ch;
//                if (ch == "@") { at=true; }
//                if (ch == ".") { dot=true; }
        }
    }

    if ((at == true) && (dot == true)) {
        return true;
    }
    else {
      // DISPLAY ERROR MESSAGE
//      alert ("Please enter a valid email address.");
      return false;
    }
}
function check_login(objForm) {
  var error_message = "";
  var error_field = null;
  var name = objForm.name.value;
  var pass= objForm.pass.value;
                                              
  if ((name == 'ваше имя') || (name.length < 1)) error_field = objForm.name;
  if (error_field==null && ((pass== 'пароль') || (pass.length < 1))) error_field = objForm.pass;

  if (error_field != null) {
    error_message = error_message + "* Все поля для логина необходимо заполнить!\n";

    alert(error_message);
    error_field.focus();
    return false;

  } else {

    return true;
  }
}

