/* 
------------------------------------------
 Flipbox written by CrappoMan
 simonpatterson@dsl.pipex.com
------------------------------------------
*/

//modified by Wooya

//window.onerror=null;


function getClientWidth(){
	 return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;  
}

function getClientHeight(){
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
} 


function getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
	return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function getDocumentHeight()
{
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

function getDocumentWidth()
{
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}

 



function getClientCenterX()
{
	return parseInt(getClientWidth()/2)+getBodyScrollLeft();
}

function getClientCenterY()
{
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}



function getElementPosition(elemId)
{
    var elem = document.getElementById(elemId);
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}


function flipBox(who) {
   var tmp;
   if (document.images['b_' + who].src.indexOf('_on') == -1) {
      tmp = document.images['b_' + who].src.replace('_off', '_on');
      document.getElementById('box_' + who).style.display = 'none';
      if (document.getElementById('box_' + who + '_diff')) {
         document.getElementById('box_' + who + '_diff').style.display = 'block';
      }
      document.images['b_' + who].src = tmp;
      disply = 'none';
      now = new Date();
      now.setTime(now.getTime()+1000*60*60*24*365);
      expire = (now.toGMTString());
      document.cookie = "fusion_box_"+who+"=" + escape(disply) + "; expires="+expire;
   } else {
      tmp = document.images['b_' + who].src.replace('_on', '_off');
      document.getElementById('box_' + who).style.display = 'block';
      if (document.getElementById('box_' + who + '_diff')) {
         document.getElementById('box_' + who + '_diff').style.display = 'none';
      }
      document.images['b_' + who].src = tmp;
      disply = 'block';
      now = new Date();
      now.setTime(now.getTime()+1000*60*60*24*365);
      expire = (now.toGMTString());
      document.cookie = "fusion_box_"+who+"=" + escape(disply) + "; expires="+expire;
   }
}

//modified by wooya
function addText(elname, strFore, strAft, formname) {
   if (formname == undefined) formname = 'inputform';
   if (elname == undefined) elname = 'message';
   element = document.forms[formname].elements[elname];
   element.focus();
   // for IE 
   if (document.selection) {
	   var oRange = document.selection.createRange();
	   var numLen = oRange.text.length;
	   oRange.text = strFore + oRange.text + strAft;
	   return false;
   // for FF and Opera
   } else if (element.setSelectionRange) {
      var selStart = element.selectionStart, selEnd = element.selectionEnd;
			var oldScrollTop = element.scrollTop;
      element.value = element.value.substring(0, selStart) + strFore + element.value.substring(selStart, selEnd) + strAft + element.value.substring(selEnd);
      element.setSelectionRange(selStart + strFore.length, selEnd + strFore.length);
			element.scrollTop = oldScrollTop;      
      element.focus();
   } else {
			var oldScrollTop = element.scrollTop;
      element.value += strFore + strAft;
			element.scrollTop = oldScrollTop;      
      element.focus();
	}
}

//modified by Wooya
function insertText(elname, what, formname) {
   if (formname == undefined) formname = 'inputform';
   if (document.forms[formname].elements[elname].createTextRange) {
       document.forms[formname].elements[elname].focus();
       document.selection.createRange().duplicate().text = what;
   } else if ((typeof document.forms[formname].elements[elname].selectionStart) != 'undefined') {
       // for Mozilla
       var tarea = document.forms[formname].elements[elname];
       var selEnd = tarea.selectionEnd;
       var txtLen = tarea.value.length;
       var txtbefore = tarea.value.substring(0,selEnd);
       var txtafter =  tarea.value.substring(selEnd, txtLen);
       var oldScrollTop = tarea.scrollTop;
       tarea.value = txtbefore + what + txtafter;
       tarea.selectionStart = txtbefore.length + what.length;
       tarea.selectionEnd = txtbefore.length + what.length;
       tarea.scrollTop = oldScrollTop;
       tarea.focus();
   } else {
       document.forms[formname].elements[elname].value += what;
       document.forms[formname].elements[elname].focus();
   }
}

//modified by Wooya to W3C standards
function show_hide(msg_id) {
   document.getElementById(msg_id).style.display = document.getElementById(msg_id).style.display == 'none' ? 'block' : 'none';
}

//modified by Wooya to work properly with Opera
function correctPNG() {
   // correctly handle PNG transparency in Win IE 5.5 or higher.
   if (navigator.appName=="Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera")==-1) {
      for(var i=0; i<document.images.length; i++) {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
            img.outerHTML = strNewHTML;
            i = i-1;
         }
      }
   }
}

function getStyle(el,style)
{
	if(typeof el == "string")
		var element = document.getElementById(el);
	else
		var element = el;
	if (element.currentStyle)
		var value = element.currentStyle[style];
	else if (window.getComputedStyle)
		var value = document.defaultView.getComputedStyle(element,null).getPropertyValue(style);
	return value;
}

/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function getposOffset(overlay, offsettype){
   var totaloffset=(offsettype=='left')? overlay.offsetLeft : overlay.offsetTop;
   var parentEl=overlay.offsetParent;
   while (parentEl!=null) {
      if(getStyle(parentEl, "position") != "relative"){
	     totaloffset=(offsettype=='left')? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
      }
	  parentEl=parentEl.offsetParent;
   }
   return totaloffset;
}
   
function overlay(curobj, subobjstr, opt_position){
   if (document.getElementById){
      var subobj=document.getElementById(subobjstr)
      subobj.style.display=(subobj.style.display!='block')? 'block' : 'none'
      var xpos=getposOffset(curobj, 'left')+((typeof opt_position!='undefined' && opt_position.indexOf('right')!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
      var ypos=getposOffset(curobj, 'top')+((typeof opt_position!='undefined' && opt_position.indexOf('bottom')!=-1)? curobj.offsetHeight : 0)
      subobj.style.left=xpos+'px'
      subobj.style.top=ypos+'px'
      return false
   }
   else
   return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display='none'
}

//written by Wooya
NewWindowPopUp = null;
function OpenWindow(src, wdth, hght, wcenter) {
   //close previous popup window
   if (NewWindowPopUp != null) {
        NewWindowPopUp.close();
        NewWindowPopUp = null;
   }
   //if center parameter given center opoup window 
   if (wcenter == false) { 
      wtop = 0;
      wleft = 0;
   } else {
        wtop = (screen.availHeight-hght)/2;
        wleft = (screen.availWidth-wdth)/2;
   }
   NewWindowPopUp = window.open(src, "","toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=yes,status=no,directories=no,resizable=yes,height="+hght+",width="+wdth+",top="+wtop+",left="+wleft+"");
   NewWindowPopUp.focus();
}

//Image Resizer by Matonor
function resize_forum_imgs(){
	var max;
	var viewport_width;
	//Get the width of the viewport
	if(self.innerWidth)
		viewport_width = self.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth)
		viewport_width = document.documentElement.clientWidth;
	else if(document.body)
		viewport_width = document.body.clientWidth;
	else
		viewport_width = 1000;

	//Set the max width/height according to the viewport-width
	if(viewport_width <= 800)
		max = 200;
	else if(viewport_width < 1152)
		max = 300;
	else if(viewport_width >= 1152)
		max = 400;
	
	//loop through images that have the className forum-img
	for(var i=0; i<document.images.length; i++) {
		var image = document.images[i];
		if(image.className!="forum-img"){
			continue;
		}
		var height = image.height;
		var width = image.width;
		var resized = false;
		//resize the image with correct aspect ratio
		if(width <= height){
			if(height > max){
				image.height = max;
				image.width = width*(max/height);
				resized = true;
			}
		}else{
			if(width > max){
				image.width = max;
				image.height = height*(max/width);
				resized = true;
			}
		}
		
		//Find the div around the image and the next element around the div.
		var span = image.parentNode;
		var parent = span.parentNode;
		if(span.className != "forum-img-wrapper"){
			continue;
		}
		
		if(resized){ //Insert the link and make the span inline
			span.style.display = "inline";
			if(parent.tagName != "A"){
				span.onclick = new Function("OpenWindow('"+image.src+"', "+(width+40)+", "+(height+40)+", true)");
				span.onmouseover = "this.style.cursor='pointer'";
			}
		}else{ //only make the span inline
			span.style.display = "inline";
		}
	}
	return true;
}

function onload_events(){//Add function calls to be executed onload here
	resize_forum_imgs();
	correctPNG();
}

window.onload = onload_events;

var shl = 1;
function photoadd(){
txt = document.getElementById("photo").innerHTML;
shl++;
if (shl>6){
return no();
}
t = '<div style="width: 100%"><b>фото №'+shl+':</b> <input type="file" style="width: 70%" name="foto[]"></div> \r\n'
document.getElementById("photo").innerHTML = txt + t;
}





function no(){	   
return false;
}

function chvendor(){
if (!requestok){return nofunc();}
requestok = false;

if (document.getElementById("vendor").value > 0){
modeajax = 1;
post = "mode=listmodel&id="+document.getElementById("vendor").value;

document.getElementById("model").innerHTML=" <b><i>..загрузка..</i></b> ";
openurl(siteurl+"ajax.php","post",post);
} else {
document.getElementById("model").innerHTML=" ";
}
}







function nopopupwindow(){
document.getElementById('popupwindow').style.display = "none";
lockOff()
}		
								
function sendzayvkakredit() { //отправка заявки на кредит
if (!requestok){return nofunc();}	
requestok = false;
frm = document.autokr;
modeajax = 19;


if (!frm.fio.value){
alert("Введите \"Ваше ФИО\"");
return nofuncno();
}		

if (!frm.tel.value){
alert("Введите \"Контактный телефон\"");
return nofuncno();
}	  


	   


if (!document.getElementById('vendor').value || document.getElementById('vendor').value == 0){
alert("Выбирите марку автомобиля.");
return nofuncno();
} 

if (!document.getElementById('modelsel').value || document.getElementById('modelsel').value == 0){
alert("Выберите модель автомоболя.");
return nofuncno();
}	

if (!frm.cena.value || frm.cena.value == 0){
alert("Введите орентеровочную стоимость авто.");
return nofuncno();
}	

if (!frm.summanew.value){
alert("Введите сумму первоначального взноса.");
return nofuncno();
}	


aut = frm.aut.value;
idm = document.getElementById('modelsel').value;
idv = document.getElementById('vendor').value;
yearauto = frm.yearauto.value;
autoshop = frm.autoshop.value;
cena = frm.cena.value;
summanew = frm.summanew.value;
srkr = frm.srkr.value;
vz = frm['vz[0]'].value;
sex = frm.sex.value;
fio = frm.fio.value;
tel = frm.tel.value;
mail = frm.mail.value;



loderOn();
lockOn();
post = "mode=sendkredit&aut="+aut+"&idm="+idm+"&idv="+idv+"&yearauto="+yearauto+"&autoshop="+autoshop+"&cena="+cena+"&summanew="+summanew+"&srkr="+srkr+"&vz="+vz+"&sex="+sex+"&fio="+fio+"&tel="+tel+"&mail="+mail;
openurl(siteurl+"ajax.php","post",post);
}

function showtxtquest(idq,aid) {
if (!requestok){return nofunc();}	 

requestok = false;
modeajax = 18;
loderOn();
lockOn();

post = "mode=txtquest&id="+idq+"&aid="+aid;
openurl(siteurl+"ajax.php","post",post);

}

function windowpic(w,h,content){	
loderOff();	
lockOn();
elm = document.getElementById('popupwindow');	  
lf = (getClientWidth()/2) - (w/2);
tp = getClientCenterY() - (h/2);	
//elm.style = "z-index: 999";
elm.style.left = lf + "px";
elm.style.top = tp+"px";
elm.style.watch = w+"px";
elm.style.height = h+"px";
elm.style.display = "block";		 
elm.innerHTML = "<div align=\"right\" title=\"Закрыть\" class=\"pupwin\" onclick=\"nopopupwindow();\"><a href=\"JavaScript:{}\"><b>X</b></a></div>"+content+"<div class=\"pupwin\" onclick=\"nopopupwindow();\"><b><a href=\"JavaScript:{}\">закрыть</b></div>";
}
	
 
function napstrah(){   

elem = document.getElementById("napstr");
document.getElementById("docbody").style.display="";

document.getElementById("docbody").style.height=getDocumentHeight()+"px";
document.getElementById("docbody").style.width=getDocumentWidth()+"px";

elem.style.display="";
pos = getElementPosition("napstr");	
lf = getClientCenterX() - (pos.width/2);
tp = getClientCenterY() - (getElementPosition("napstr").height/2);

elem.style['left'] = lf+"px";
elem.style['top'] = tp+"px";
return lockOn();
} 

function chcolor(){
if (!requestok){return nofunc();}
requestok = false;
modeajax = 2;

	if (document.getElementById("chcolorid").value > 0){
		post = "mode=colorsel&id="+document.getElementById("chcolorid").value;
		openurl(siteurl+"ajax.php","post",post);
	}
}


function delphajax(id,aid,idp){
if (!requestok){return nofunc();}
requestok = false;
modeajax = 3;

lockOn();					  
loderOn();
//lockOn() lockOff() loderOn() loderOff()
document.getElementById('photo').innerHTML="...Думаю...";
yPos = siteurl+"ajax.php?id="+idp;
post = "id="+id;
url = siteurl+"ajax.php?mode=delphotocat";
openurl(url,"post",post);
}


function newlistphoto(url){
if (!requestok){return nofunc();}
requestok = false;
modeajax = 4;


post = "mode=catphotov";
openurl(url,"post",post);
}

function photokol(url){
if (!requestok){return nofunc();}
requestok = false;
modeajax = 5;

post = "mode=catphotokol";
openurl(url,"post",post);
}

function actcat(m,id){	   
if (!requestok){return nofunc();}
requestok = false;
modeajax = 6;


yPos = m;	
xPos = id;	
url = siteurl+"ajax.php";
post = "mode=setact&act="+m+"&id="+id;
openurl(url,"post",post);
}


function adddop(){
if (!requestok){return nofunc();}
requestok = false;
modeajax = 8;

summkol = summkol+1;
num = summkol;
	if (summkol<5){
		post = "mode=adddop&num="+num;
		openurl(siteurl+'ajax.php',"post",post);
	}
}

function adddop1(){
if (!requestok){return nofunc();}
requestok = false;
modeajax = 9;

post = "mode=adddop1&num="+num;
openurl(siteurl+'ajax.php',"post",post);
}		

function sendyrik(){
if (!requestok){return nofunc();}  

dat = document.yrist;

if (!dat.fio.value){
alert("Введите \"Ваше ФИО\"");
return nofuncno();
}		

if (!dat.tel.value){
alert("Введите \"Контактный телефон\"");
return nofuncno();
}		

if (!dat.sut.value){
alert("Введите \"Суть притензии\"");
return nofuncno();
}		 

if (!dat.summa.value){
alert("Введите \"Сумму претензии\"");
return nofuncno();
}		 


requestok = false;
modeajax = 16;	 

lockOn();
loderOn();
	 
post = "mode=sendyrik&fio="+dat.fio.value+"&tel="+dat.tel.value+"&mail="+dat.mail.value+"&gorod="+dat.gorod.value+"&strkomp="+dat.strkomp.value+"&sut="+dat.sut.value+"&summa="+dat.summa.value;
openurl(siteurl+'ajax.php',"post",post);

}






function sendzayavka(){
if (!requestok){return nofunc();}

	if (!document.remember["name_remember"].value){
		alert('Заполните поле "Имя"');
		return no();
	}

	if (!document.remember["phone_remember"].value){
		alert('Заполните поле "Мобильный телефон"');
	return no();
	}

	if (!document.remember["mail_remember"].value){
		alert('Заполните поле "Электронная почта"');
	return no();
	}

requestok = false;
modeajax = 12;

elem = document.getElementById("napstr");
elem.style.display="none";
document.getElementById("loaderpic").src = loaderImg.src;
document.getElementById("loaderpic").style.display="";
lpic = getClientCenterX()-50;
document.getElementById("loaderpic").style.left=lpic+"px	";
document.getElementById("loaderpic").style.top=getClientCenterY() + "px";
name_remember = document.remember["name_remember"].value;
url_remember = document.remember["url_remember"].value;
data_remember = document.remember["dd"].value+"."+document.remember["mm"].value+"."+document.remember["yy"].value;
phone_remember = document.remember["phone_remember"].value;
mail_remembe = document.remember["mail_remember"].value;
post = "mode=remember&name="+name_remember+"&data="+data_remember+"&phone="+phone_remember+"&mail="+mail_remembe;
openurl(url_remember,"post",post);
}	   


function showpiccat(pic){
if (!requestok){return nofunc();}
requestok = false;
modeajax = 14;	

//lockOn() lockOff() loderOn() loderOff()
lockOn(); 
loderOn()
var shImg = new Image();
shImg.src = pic; 
yPos = pic;
post = "mode=sizepic&pic="+pic;
openurl(siteurl+"ajax.php","post",post);
}





 							 
// lockOn() lockOff() loderOn() loderOff()
function cancelzayavka(){		
loderOff();	
lockOff();
elem = document.getElementById("napstr");
elem.style.display="none";
idbody = document.getElementById("docbody");
idbody.style.display="none";
}


function actcatch(m){
	if (m==0){
		document.getElementById('noact'+xPos).style.color = "#000000";
		document.getElementById('noact'+xPos).style.background = "#ffffff";
		document.getElementById('act'+xPos).style.color = "#ffffff";
		document.getElementById('act'+xPos).style.background = "#000000";
	} 
	if (m==1){
		document.getElementById('noact'+xPos).style.color = "#FFFFFF";
		document.getElementById('noact'+xPos).style.background = "#000000";
		document.getElementById('act'+xPos).style.color = "#000000";
		document.getElementById('act'+xPos).style.background = "#ffffff";
	}

}





function konkursdelphoto(id){ 
	document.konkurs.file.style.display="";	   
	document.konkurs.file.value="";	  
	document.konkurs.fileok.value="false";	  
	document.getElementById('fotokonkurs').style.display="none";
}				 
	  
function sendquote() {

name = document.quest.name.value;  
if (!name){
alert('Введите ваше имя');
return no();
}					   

quote = document.quest.quote.value;
if (!quote){
alert('Нет текста оштзыва');
return no();
}					   	 

strkompsel = document.quest.strkompsel.value;
strkomp = document.quest.strkomp.value;

if (strkompsel == "null" && !strkomp){
alert('Выберете стаховую компанию или введите её название');
return no();
}					   	 
if (strkomp){
komp = strkomp;
} else {
komp = strkompsel;
}	   
if (!document.quest.star1.value){
alert('Вы невыбрали рейтинг данной компании!');
return no();
}

rating = document.quest.star1.value;
if (!requestok){return nofunc();}
requestok = false;
modeajax = 17;																

loderOn();	
lockOn();
post = "mode=sendguote&name="+name+"&guote="+quote+"&komp="+komp+"&rating="+rating;
openurl(siteurl+"ajax.php","post",post);

}

function sendkonkurs(){
var elm = document.konkurs;	  

idv = document.getElementById('vendor').value;
if (!idv || idv==0){
alert('Выбирете марку');
return no();
}		
if (!document.getElementById('modelsel')){
alert('Выбирете модель');
return no();
}

idm = document.getElementById('modelsel').value;
if (!idm || idm==0){
alert('Выбирете модель');
return no();
}		

if (!elm['kfam'].value){
alert('Заполните поле "Фамилия"');
return no();
}		
kfam = elm['kfam'].value;

if (!elm['kname'].value){
alert('Заполните поле "Имя"');
return no();
}		


kname= elm['kname'].value;
if (!elm['kotch'].value){
alert('Заполните поле "Отчество"');
return no();
}		
kotch = elm['kotch'].value;
file = elm['file'].value;
if (!file && !elm['file'].style.display){
alert('Выбирете фотографию');
return no();
}	

file = elm['file'].value;

if (!elm['captcha_code'].value){
alert('Введите проверочный код');
return no();
}	
elm['modelmarka'].value=document.getElementById('modelsel').value;

return elm.submit();
}		  
	  
function editokkonkurs(){	
var elm = document.konkurs;	 

idv = document.getElementById('vendor').value;
	if (!idv || idv==0){
		alert('Выбирете марку');
		return no();
	}		
 
	if (!document.getElementById('modelsel')){
		alert('Выбирете модель');
		return no();	   
	}
elm['modelmarka'].value=document.getElementById('modelsel').value;
return elm.submit();
}				   

function liststrah() {
document.getElementById('str').style.display = "";
document.getElementById('strsel').style.display = "none";

}
