SELECT_ENTRY = "Vyberte si ...";
function masterInit() {
	if (window.init) { init(); }
}
function get(objid){
	try{
		var obj=document.getElementById(objid);
		if (obj.type=="select") {
			return obj.options[obj.selectedIndex].value;
		}else{
			return obj.value;
			}
}catch(err){
return "-----";
}
}
function set(objid,value){
document.getElementById(objid).value=value;
}
function submitme(page){
if (page) {
document.getElementById("form1").action=page;
}
document.getElementById("form1").submit();
}

function getParameter(parameterName) {
var queryString=window.top.location.search.substring(1);
var parameterName = parameterName + "=";
if (queryString.length > 0) {
begin = queryString.indexOf (parameterName);
if (begin != -1) {
begin += parameterName.length;
end = queryString.indexOf ("&" , begin);
if (end == -1) {
end = queryString.length
}
return unescape (queryString.substring (begin, end));
}
return "null";
}
} 


function onClickRow(itemId)
{
	var element = document.getElementById("selectedRowSection");
	if (element != null)
	{
		element.innerHTML = "<input type='hidden' name='selectedRowIndex' value='" + itemId + "'/>";
		document.getElementById("form1").submit();
	}
}
function clearOnClickRow()
{
	var element = document.getElementById("selectedRowSection");
	if (element != null)
	{
		element.innerHTML = "";
	}
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
  	if (this.obj) {
		this.style = document.getElementById(name).style;
	}
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	if (this.obj) {
		this.style = document.all[name].style;
	}
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	if (this.obj) {
		this.style = this.obj;
	}
  }
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}
function showCity(id)
{
	var city = new getObj('mesto_'+id);
	city.style.display='block';
}
function hideCity(id)
{
	var city = new getObj('mesto_'+id);
	city.style.display='none';
} 
function sendMailTo(name, company, domain)
{
	locationstring = 'mai'+'lto:'+name+'@'+company+'.'+domain;
	window.location.replace(locationstring);
}
function navTo(url) {
	window.location.href = url;
}
function changeBGColor(element,bgcolor)
{
	element.style.backgroundColor = bgcolor;
}

function swapContent(element,old_value,new_value)
{
  if(element.value == old_value) element.value= new_value;
}


var oldItemClassName;
function overItem(item)
{

		if (item.className != 'select')
	{
		oldItemClassName = item.className;
		item.className = 'over';
	}

}
function overItemErr(item)
{

	if (item.className != 'select')
	{
		oldItemClassName = item.className;
		item.className = 'overErr';
	}

}
function outItem(item)
{

	if (item.className != 'select')
	{
		
		item.className = oldItemClassName;
	}
}
function selectItem(item)
{
	item.className = 'select';
}

function setClass(item,className)
{
	item.className = className;
}
function newsletterItemCheck(cb,item_id)
{	
	if (cb.checked == true)
	{
		selectItem(document.getElementById('item_'+item_id));	
	}
	else
	{
		setClass(document.getElementById('item_'+item_id),'over');
	}
}
function ccItemCheck(cb,item_id,value)
{
	value = value.replace(',', '.');

	if (cb.checked == true)
	{
		addPrice(parseFloat(value));
		changePrice();
		selectItem(document.getElementById('item_'+item_id));
	
	}
	else
	{
		addPrice(-parseFloat(value));
		changePrice();
		setClass(document.getElementById('item_'+item_id),'over');

	}
}

var totalPrice = 0;


function addPrice(price)
{
	totalPrice += price;	
	if (totalPrice < 0) totalPrice = 0;
}
function changePrice()
{
	//var eurPrice = (totalPrice * 100) / 30.1260;
	//eurPrice = Math.round(eurPrice);
	//eurPrice = eurPrice / 100;
	//document.getElementById('total_price').innerHTML = formatNumberBy3(totalPrice,',',' ')+' Sk (' + formatNumberBy3(eurPrice,',',' ').replace('.', ',') + ' EUR)';
	var skkPrice = totalPrice * 100 * 30.1260;
	skkPrice = Math.round(skkPrice);
	skkPrice = skkPrice / 100;
	var totalPriceRound = Math.round(totalPrice * 100, 2);
	totalPriceRound /= 100;
	document.getElementById('total_price').innerHTML = formatNumberBy3(totalPriceRound,',',' ').replace('.',',')+' € <span style="font-size:9px">('
		+ formatNumberBy3(skkPrice,',',' ').replace('.', ',') + ' Sk)</span>';	
}

var oldSubmenuIndex;
function toggleSubmenu(index)
{
	if (oldSubmenuIndex) {
		var submenu = new getObj('sub_'+oldSubmenuIndex);
		if (submenu && submenu.style) {
			submenu.style.display = (submenu.style.display != 'block') ? 'block' : 'none';
		}
	}

	oldSubmenuIndex = index;
	var submenu = new getObj('sub_'+index);
	if (submenu && submenu.style) {
		submenu.style.display = (submenu.style.display != 'block') ? 'block' : 'none';
	}
}

/*
Author: Robert Hashemian
http://www.hashemian.com/
*/
function formatNumberBy3(num, decpoint, sep) {
  // check for missing parameters and use defaults if so
  if (arguments.length == 2) {
    sep = ",";
  }
  if (arguments.length == 1) {
    sep = ",";
    decpoint = ".";
  }
  // need a string for operations
  num = num.toString();
  // separate the whole number and the fraction if possible
  a = num.split(decpoint);
  x = a[0]; // decimal
  y = a[1]; // fraction
  z = "";


  if (typeof(x) != "undefined") {
    // reverse the digits. regexp works from left to right.
    for (i=x.length-1;i>=0;i--)
      z += x.charAt(i);
    // add seperators. but undo the trailing one, if there
    z = z.replace(/(\d{3})/g, "$1" + sep);
    if (z.slice(-sep.length) == sep)
      z = z.slice(0, -sep.length);
    x = "";
    // reverse again to get back the number
    for (i=z.length-1;i>=0;i--)
      x += z.charAt(i);
    // add the fraction back in, if it was there
    if (typeof(y) != "undefined" && y.length > 0)
      x += decpoint + y;
  }
  return x;
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}
var oldCatModel;
function showCat(model) {
	if (model==null) return;
	if (oldCatModel) {
		var divCat = document.getElementById("sc_" + oldCatModel);
		if (divCat) {
			divCat.style.display="none";
//			toggleSubmenu(oldCatModel);
		}
	}
	oldCatModel=model;
	var divCat = document.getElementById("sc_" + model);
	if (divCat) {
		divCat.style.display="block";
//		toggleSubmenu(model);
	}
}

function showModel(model){
parent.location='Model.aspx?model='+model;
}
function cc(model){
parent.location='MasterPage.aspx?pageId=carconfig&model='+model;
}

function goAccessory(subcategory,category){
set("cat",category);
set("subcat",subcategory);
set("pageId","prislusenstvo");
submitme();
}

function setActive(which){
set("active",which);
submitme();
}

function showContent() {
document.getElementById("main").style.visibility="visible";
document.getElementById("content").style.visibility="visible";
//document.getElementById("loading").style.display="none";
flashfix();
}

function generateAccessoryCats(){
for (i=0;i<prislCategories.length;i++) {
var cat = prislCategories[i][0];
var catname = prislCategories[i][1];
document.write("<div id=\"sc_" +cat + "\" style=\"DISPLAY: none\">");
document.write("<div><img border=\"0\" src=\"images/prislusenstvo/" + cat + ".gif\" /></div>");
document.write("<h4>" + catname + "</h4><ul>");
if (cat=="col") {
document.write("<li><a href=\"javascript:goAccessory('1', '" + cat + "')\">Bienvenue - Vítame Vás</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('2', '" + cat + "')\">Passion - Sport</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('3', '" + cat + "')\">Kids - Hry a hracky</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('4', '" + cat + "')\">Oxygene - V prírode</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('5', '" + cat + "')\">Paris - Prestíž</a> </li>");
} else if (cat=="mod") {
document.write("<li><a href=\"javascript:goAccessory('1', '" + cat + "')\">Novinky</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('2', '" + cat + "')\">Závodné automobily</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('3', '" + cat + "')\">Legendy</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('4', '" + cat + "')\">Úžitkové a iné automobily</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('5', '" + cat + "')\">Mikro</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('6', '" + cat + "')\">Velká mierka</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('7', '" + cat + "')\">Mini</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('8', '" + cat + "')\">Pre najmenších</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('9', '" + cat + "')\">Udalosti 2005</a> </li>");
} else {
document.write("<li><a href=\"javascript:goAccessory('1', '" + cat + "')\">Osobitost</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('2', '" + cat +"')\">Bezpecnost</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('3', '" + cat + "')\">Pohodlie a cestovanie</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('4', '" + cat + "')\">Navigácia a komunikácia</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('5', '" + cat + "')\">Butik</a> </li>");
document.write("<li><a href=\"javascript:goAccessory('6', '" + cat + "')\">Váš Citroën</a> </li>");
}
document.write("</ul></div>");
}
}

function stripTags(html) {
a = html.indexOf("<");
b = html.indexOf(">");
len = html.length;
c = html.substring(0, a);
if(b == -1)
b = a;
d = html.substring((b + 1), len);
html = c + d;
tagCheck = html.indexOf("<");
if(tagCheck != -1)
html = stripTags(html);
return html;
}

function unicodeEscape (pstrString) 
{  
	if (pstrString == "") { return ""; }  
	var iPos = 0;  
	var strOut = "";  
	var strChar;  
	var strString = escape(pstrString);  
	while (iPos < strString.length) {    
		strChar = strString.substr(iPos, 1);    
		if (strChar == "%") {      	
			strNextChar = strString.substr(iPos + 1, 1);      
			if (strNextChar == "u") {        
				strOut += strString.substr(iPos, 6);        
				iPos += 6; 
			}  else {       
				strOut += "%u00" + strString.substr(iPos + 1, 2);
				iPos += 3;      
			}    
		} else {      
			strOut += strChar;      
			iPos++;    
		}  
	}  
	return strOut;
}

function openGalleryBrowser(model) 
{	
	var galleryBrowser = window.open('Gallery.aspx?id=model_'+model, '_blank', 'width=757,height=765');
	galleryBrowser.focus();
}
