
var main_banner_content = "";
var current_mode = "master";

function change_site_width() {
	
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false

	winW = (ns4)? window.innerWidth-16 : document.body.offsetWidth-20
	winH = (ns4)? window.innerHeight : document.body.offsetHeight

	if (winW<800 || winW==960) {
		if (current_mode != "slim") {
			setActiveStyleSheet("slim");
		}
	} else {
		if (current_mode != "master") {
			setActiveStyleSheet("master");
		}
	}
	
	if (document.getElementById("main_banner") != undefined) {
		
		if (main_banner_content == "") {
			main_banner_content = document.getElementById("main_banner").innerHTML;
		}
		
		if (winW<800 || winW==960) {
			if (current_mode != "slim") {
				var str = "";
				str += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"770\" height=\"300\">"
				str += "<param name=\"movie\" value=\"img/Banners/" + document.getElementById("main_banner").title + "_770x300.swf\" />"
				str += "<param name=\"quality\" value=\"high\" />"
				str += "<param name=\"wmode\" value=\"transparent\" />"
				str += "<embed src=\"img/Banners/" + document.getElementById("main_banner").title + "_770x300.swf\" quality=\"high\" wmode=\"transparent\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"770\" height=\"300\"></embed>"
				str += "</object>"
				document.getElementById("main_banner").innerHTML = str;
			}
		} else {
			if (current_mode != "master") {
				document.getElementById("main_banner").innerHTML = main_banner_content;
			}
		}
		
		
	}
	
	if (winW<800) {
		current_mode = "slim";
	} else {
		current_mode = "master"
	}
	
}
window.onresize = change_site_width;
window.onload = change_site_width;

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}


var modalName = 'modalWindow';

function show_warning_modal(wn)
{
	
	if (wn != undefined) {
		modalName = wn;
	}
	
	$(modalName).style.display = $('modalBackground').style.display = 'block';

	// special < IE7 -only processing for windowed elements, like select	
	if (window.XMLHttpRequest == null)
	{
		//var type = $('hideType').value;
		
		//if (type == 'iframe')
		//	$('modalIframe').style.display = 'block';
		//if (type == 'replace')
		//	ReplaceSelectsWithSpans();
	}

	// call once to center everything
	OnWindowResize();
	
	if (window.attachEvent)
		window.attachEvent('onresize', OnWindowResize);
	else if (window.addEventListener)
		window.addEventListener('resize', OnWindowResize, false);
	else
		window.onresize = OnWindowResize;
	
	// we won't bother with using javascript in CSS to take care
	//   keeping the window centered
	if (document.all)
		document.documentElement.onscroll = OnWindowResize;
}

function OnWindowResize()
{
	// we only need to move the dialog based on scroll position if
	//   we're using a browser that doesn't support position: fixed, like < IE 7
	var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
	var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
	var div = $(modalName);
	
	div.style.left = Math.max((left + (GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
	div.style.top = Math.max((top + (GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';
}

function RemoveSelectSpans()
{
	var selects = document.getElementsByTagName('select');
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className != 'selectReplacement')
		{
			continue;
		}
			
		select.parentNode.removeChild(select.nextSibling);
		select.style.display = select.cachedDisplay;
	}
}

function close_warning_modal()
{
	$(modalName).style.display = $('modalBackground').style.display = 'none';
	return;
	// special IE-only processing for windowed elements, like select	
	if (document.all)
	{
		//var type = $('hideType').value;
		
		//if (type == 'iframe')
		//	$('modalIframe').style.display = 'none';
		//if (type == 'replace')
			//RemoveSelectSpans();
	}
	
	if (window.detachEvent)
		window.detachEvent('onresize', OnWindowResize);
	else if (window.removeEventListener)
		window.removeEventListener('resize', OnWindowResize, false);
	else
		window.onresize = null;
}

function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}

function GetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}

function showModal(url) {
	loadHTML('loginModalWindow', 'https://www.lupalook.co.il/login_modal.aspx?redirect_page='+url);
	show_warning_modal('loginModalWindow');
}

function loadHTML(divObj, url) {
	$(divObj).empty();
	var req = new Request.HTML({
					method: 'post',
					url: url,
					onRequest: function() {  },
					//update: $('login_win'),
					onComplete: function(response) {
						$(divObj).adopt(response);
					}
				}).send();
}

function postForm(formName, postURL) {
	var req = new Request.HTML({
					method: 'post',
					url: postURL,
					onRequest: function() {  },
					//update: $('grid_container'),
					onComplete: function(response) {
						if ($(formName+'lbl') != null) {
							$(formName+'lbl').set('text', ''); 
                       		$(formName+'lbl').adopt(response);
						}
						
					}
				}).post($(formName));
}

function postLogin(url) {
	postForm('login_form', 'https://www.lupalook.co.il/login_modal.aspx?redirect_page='+url);
	return false;
}

function postReg(url) {
	postForm('reg_form', 'https://www.lupalook.co.il/register_modal.aspx?redirect_page='+url);
	return false;
}

var currentF=''
function focusField(f) {
	document.getElementById(f).style.border = '2px solid #FF3300';
	document.getElementById(f).style.padding = '4px';
	document.getElementById(f).focus();
	if (currentF != '' && currentF != f){
		document.getElementById(currentF).style.border = '1px solid';
		document.getElementById(currentF).style.padding = '5px';
	}
	currentF=f;
}
