//Глобальные переменные
var AR_DOMAIN_ZONE=Array(".in.ua",".ua",".ru");
//Регистрация внтрестраничных переходов
function check_domen_name(domen) {
	for(var i=0;i<AR_DOMAIN_ZONE.length;i++){
		if(domen.indexOf(AR_DOMAIN_ZONE[i])+1){
			var str_tmp=domen.replace(AR_DOMAIN_ZONE[i],"");
			var ar_tmp=str_tmp.split(".");
			return Array(ar_tmp[ar_tmp.length-1]+""+AR_DOMAIN_ZONE[i],ar_tmp[ar_tmp.length-2]);
		}
	}
}
var ADR_SITE_SHORT=check_domen_name(document.domain)[0];
var ADR_SUB=check_domen_name(document.domain)[1];

/*Затемнение*/
function  getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	var scrollY=0;
	if (document.body && typeof document.body.scrollTop != "undefined")
	{
		scrollY += document.body.scrollTop;
		if (scrollY == 0 && document.body.parentNode && typeof document.body.parentNode != "undefined")
		{
			scrollY += document.body.parentNode.scrollTop;
		}
		} else if (typeof window.pageXOffset != "undefined")  {
			scrollY += window.pageYOffset;
	} 

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		windowWidth = windowWidth-17;
		xScroll = xScroll-17;
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return [pageWidth,pageHeight,windowWidth,windowHeight,scrollY];
}

//Показывает затемнение
function showLightbox(gid){
	var objLightbox = document.getElementById('win_lightbox');
	var arrayPageSize = getPageSize();
	var alpha=10;
	
		objLightbox.style.top = "0px";
		objLightbox.style.left = "0px";
		objLightbox.style.width = arrayPageSize[0]+"px";
		objLightbox.style.height = arrayPageSize[1]+"px";
		objLightbox.style.display = 'block';
		objLightbox.style.filter="alpha(opacity="+alpha+")";
		objLightbox.style.opacity = alpha/100;

	function show_fon(){
		objLightbox.style.filter="alpha(opacity="+alpha+")";
		objLightbox.style.opacity = alpha/100;
		alpha+=10;
		if(alpha>=50){
			clearInterval(timeoutLB);
			show_order();
		}
	}
	
	function show_order(){
		WINORDER = document.getElementById('win_order');
		IFRAMEORDER = document.getElementById('iframe_order');
		WINORDER.style.display='';
		WINORDER.style.top=arrayPageSize[4]+100+"px";
		WINORDER.style.left=(arrayPageSize[0]-600)/2+"px";
		if(!ADR_SUB)IFRAMEORDER.src="http://"+ADR_SITE_SHORT+"/iframe_order.php?id="+gid;
		else IFRAMEORDER.src="http://"+ADR_SUB+"."+ADR_SITE_SHORT+"/iframe_order.php?id="+gid;
	}
	
	timeoutLB = setInterval(show_fon, 10);
}
//Прячим затемнение
function hideLightbox(){
	var objLightbox = document.getElementById('win_lightbox');

	function hide_order(){
		WINORDER = document.getElementById('win_order');
		IFRAMEORDER = document.getElementById('iframe_order');
		WINORDER.style.display='none';
		IFRAMEORDER.src="http://"+ADR_SITE_SHORT+"/images/order_loader.gif";
	}
	hide_order();
	objLightbox.style.display = 'none';
}
document.write('<div id="win_lightbox" style="display:none; position:absolute; z-index:1000;"></div>');


//Показываем окно вопроса
document.write('<div id="win_order" style="display:none; position:absolute; z-index:2000;"><div class="win_order_top"><a href="javascript:hideLightbox();" title="Закрыть окно заказа"><img src="http://'+ADR_SITE_SHORT+'/images/win_order_close.png" /></a></div><iframe src="http://'+ADR_SITE_SHORT+'/images/order_loader.gif" id="iframe_order" frameborder="no" align="center"></iframe></div>');


//Картинка с кодом
function insert_simg(skod,img) {
	if(img==''){
		if(!ADR_SUB)window.frames['buffer'].location = "http://"+ADR_SITE_SHORT+"/info/simg.php";
		else window.frames['buffer'].location = "http://"+ADR_SUB+"."+ADR_SITE_SHORT+"/simg.html";
	}
	if(img!='') document.getElementById('span_simg').innerHTML = "<img src='http://"+ADR_SITE_SHORT+"/info/img/simg/"+img+"' align='absmiddle' /><input type='hidden' name='skod' id='skod' value='"+skod+"' />";
}

//Отправляем запрос
function form_subm() {
	var OBJ1=document.getElementById('uname');
	var OBJ2=document.getElementById('kod');
	var OBJ3=document.getElementById('uphone');
	var OBJ4=document.getElementById('uemail');

	errors="";
	if(OBJ1.value.length<3){
		errors=errors+" - контактное лицо\n";
		OBJ1.style.backgroundColor = "#ffd9d9";
	}
	else{
		OBJ1.style.backgroundColor = "";
	}

	if(OBJ3.value.length<3){
		errors=errors+" - контактный телефон\n";
		OBJ3.style.backgroundColor = "#ffd9d9";
	}
	else{
		OBJ3.style.backgroundColor = "";
	}

	if(OBJ4.value.length<3){
		errors=errors+" - контактный email\n";
		OBJ4.style.backgroundColor = "#ffd9d9";
	}
	else{
		OBJ4.style.backgroundColor = "";
	}

	if(OBJ2.value.length<5){
		errors=errors+" - код на картинке\n";
		OBJ2.style.backgroundColor = "#ffd9d9";
	}
	else{
		OBJ2.style.backgroundColor = "";
	}

	if(errors.length>0){
		alert("Следующие поля заполены с ошибкой:\n"+errors);
	}
	else document.getElementById('form_order').submit();

}

