function vstockover(obj)
{
	obj.style.backgroundColor = "#294677";
	obj.style.borderTopColor = "#6284B2";
	obj.style.color = "#ffffff";

}

function vstockout(obj)
{
	obj.style.borderTopColor = "#ffffff";
	obj.style.backgroundColor = "transparent";
	obj.style.color = "#1E3967";
}

function vstockdown(obj)
{
	obj.style.backgroundColor = "#EC561A";
	obj.style.borderTopColor = "#F27C35";
	obj.style.color = "#ffffff";
}

function sideOver(obj)
{
	obj.style.backgroundColor = "#F27C35";
	obj.style.color = "#ffffff";

}

function IsNumeric(sText)


{
   var ValidChars = "0123456789. -";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){

		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){

		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){

		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){

		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }


function sideOut(obj)
{
	obj.style.backgroundColor = "transparent";
	obj.style.color = "#ffffff";
}

function sideDown(obj)
{
	obj.style.backgroundColor = "#EC561A";
	obj.style.color = "#ffffff";
}

function clickForm(make)
{
	document.forms['vstock_search_form'].task.value = 'showMake';
	document.forms['vstock_search_form'].make.value = make;
	document.forms['vstock_search_form'].submit();
}

function showMake(make, task, iid)
{
	iid = 2;
	window.location = "http://ciesielczyk-auto.pl/index.php?option=com_vstock&task=" + task + "&Itemid=" + iid + "&make=" + make;
}

function showSearch(make, model, task, iid)
{
	iid = 2;
	window.location = "http://ciesielczyk-auto.pl/index.php?option=com_vstock&task=" + task + "&Itemid=" + iid + "&make=" + make + "&model=" + model;
}

function makeChange(sel)
{
	if(sel.selectedIndex != 0)
	{
		var text ="";
		document.forms['vstock_search_form'].vstock_search_model.disabled = false;
		document.forms['vstock_search_form'].vstock_search_submit.disabled = false;
		document.forms['vstock_search_form'].vstock_search_model.options.length = 0;
		document.forms['vstock_search_form'].make.value = sel.options[sel.selectedIndex].value; 
		document.forms['vstock_search_form'].vstock_search_model.options[0] = new Option('-wszystkie modele-','0');
		for(var i = 0; i < makes[sel.options[sel.selectedIndex].value].length; i++ )
		{
			var m = makes[sel.options[sel.selectedIndex].value][i];
			document.forms['vstock_search_form'].vstock_search_model.options[i+1] = new Option(m, m);
		}
		
	}
	else
	{
		document.forms['vstock_search_form'].vstock_search_model.options.length = 0;
		document.forms['vstock_search_form'].vstock_search_model.options[0] = new Option('-wybierz model-','0');
		document.forms['vstock_search_form'].vstock_search_model.disabled = true;
		document.forms['vstock_search_form'].vstock_search_submit.disabled = true;
	}
	
}

function vstockSubmit()
{
	if(document.forms['vstock_search_form'].vstock_search_model.selectedIndex == 0)
	{
		document.forms['vstock_search_form'].task.value = 'showMake';
		showMake(document.forms['vstock_search_form'].make.value, 'showMake', '2');
		return true;
	}
	else
	{
		document.forms['vstock_search_form'].task.value = 'showSearch';
		showSearch(document.forms['vstock_search_form'].make.value, document.forms['vstock_search_form'].vstock_search_model.value , 'showSearch', '2');
		return true;
	}
	
	
	//document.forms['vstock_search_form'].submit();
}

function vsCalculatePrice(c)
{
	var actprice = parseInt(document.forms['carops'].price.value);
	if(c.checked)
	{
		actprice = parseInt(actprice) + parseInt(c.value);
	}
	else
	{
		actprice = parseInt(actprice) - parseInt(c.value);
	}
	
	document.forms['carops'].price.value = actprice;
		
	if(document.forms['carops'].price.value == document.forms['carops'].price_start.value)
	{
		var d = document.getElementById("priceWOpt");
		d.innerHTML = "";
	}
	else
	{
		var d = document.getElementById("priceWOpt");
		d.innerHTML = "Cena z zaznaczonym wyposażeniem: " + document.forms['carops'].price.value + " zł";
	}
 	
}


function toggleOpenClose(module,module2)
{
	var el = document.getElementById(module);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = 'block';
	}
	var el2 = document.getElementById(module2);
	if ( el2.style.display != 'none' ) {
		el2.style.display = 'none';
	}
	else {
		el2.style.display = 'block';
	}		
}
	

function formatPrice(p)
{
var c = p.length;
var sh = c%3;
var n = "";
	for(i = sh; i < c; i++)
	{
		n += p.substr(i, 1);
		
	}
}

function rowOn(r)
{
	r.className = 'rowOn';
}

function rowOut(r, c)
{
	r.className = c;
}

function rowClick(url)
{
	window.location = url;
}

function SubmitCarForm()
{
	var f = document.forms['carops'];

	 var e = f.getElementsByTagName("input");
	for (var i=0;i<e.length;i++)
  {
     var o = e[i];

	     if((o.checked))
	     {
	     	f.addsoptions.value += o.name + " " + o.value + "<br>";
	     }


  }
	
	f.submit();
	
}



function init()
{
BrowserDetect.init();

var b = BrowserDetect.browser;
var t = document.getElementById('menutable');

switch (b)
{
	case 'Opera':
		t.style.height = '24px';
		break;
	case 'Firefox':
		t.style.height = '24px';
		break;
	case 'Explorer':
		t.style.height = '24px';
		break;

}


}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

