﻿// JavaScript Document

//preload images
function preloadImages(path,pics) {

        var images = new Array;

        for (var picNum=0; picNum<pics.length; picNum++)
            {
            images[picNum] = new Image(pics[picNum][1],pics[picNum][2]);
            images[picNum].src = (path + pics[picNum][0]);
            }

        return (images);
}

function preload(){
	var putanja = "images/";
	var pocSlike = new Array;
	
	pocSlike[0] = new Array("podmeni_03.jpg",37,9);
	pocSlike[1] = new Array("podmeni_04.jpg",20,9);
	pocSlike[2] = new Array("podmeni_05.jpg",35,9);
	pocSlike[3] = new Array("podmeni_06.jpg",19,9);
	pocSlike[4] = new Array("podmeni_07.jpg",40,9);
	pocSlike[5] = new Array("podmeni_08.jpg",21,9);
	pocSlike[6] = new Array("podmeni_09.jpg",37,9);
	pocSlike[7] = new Array("podmeni_10.jpg",6,9);

	var mySlike = preloadImages(putanja, pocSlike);
	
	
}

//show submenu under proizvodi
function show_submenu()
{
	document.getElementById('meni').innerHTML = "&nbsp;"
	
	var podmeni = "<table id='podmeni' width='276' height='9' border='0' cellpadding='0' cellspacing='0'>"
	podmeni += "<tr><td><a href='windows.php'><img src='images/podmeni_01.jpg' width='46' height='9' border='0' alt=''></a>"
	podmeni += "</td><td><img src='images/podmeni_02.jpg' width='24' height='9' alt=''></td><td><a href='panels.php'>"
	podmeni += "<img src='images/podmeni_03.jpg' width='39' height='9' border='0' alt=''></a></td><td>"
	podmeni += "<img src='images/podmeni_04.jpg' width='21' height='9' alt=''></td><td><a href='doors.php'>"
	podmeni += "<img src='images/podmeni_05.jpg' width='35' height='9' border='0' alt=''></a></td><td>"
	podmeni += "<img src='images/podmeni_06.jpg' width='20' height='9' alt=''></td><td><a href='shutters.php'>"
	podmeni += "<img src='images/podmeni_07.jpg' width='52' height='9' border='0' alt=''></a></td><td>"
	podmeni += "<img src='images/podmeni_08.jpg' width='15' height='9' alt=''></td><td><a href='lids.php'>"
	podmeni += "<img src='images/podmeni_09.jpg' width='24' height='9' border='0' alt=''></a></td><td>"
	podmeni += "</td></tr></table>"
	
	document.getElementById('meni').innerHTML = podmeni
}

//hide submenu under proizvodi
function hide_submenu(){
	document.getElementById('meni').innerHTML = "&nbsp;"
	document.getElementById('downmeni').innerHTML = "&nbsp;"
}

//show bottom menu
function show_bottommenu(){
	document.getElementById('downmeni').innerHTML = "&nbsp;"

	var bottommeni = "<a name='dolje'><b><a href='windows.php'>WINDOWS</a></b> | <a href='panels.php'>PANELS</a></b> | <a href='doors.php'>DOORS</a></b> | "
	bottommeni += "<a href='shutters.php'>SHUTTERS</a></b> | <a href='lids.php'>LIDS</a></b></a>"
	
	document.getElementById('downmeni').innerHTML = bottommeni
}

//resize left shadow
function resize_shadow(){
	var visina = document.body.scrollHeight;
	
	//var sirina = document.body.clientWidth;
	document.getElementById('shadow').style.height = visina+"px";
	
	var informator_data = "<a href='map.php'>How to find us?</a> :: <a href='windows.php'>Windows - top quality insulation</a> :: ";
	informator_data += "<a href='panels.php'>ALU panels - european quality</a> :: <a href='doors.php'>Great selection of entrance doors</a> :: ";
	informator_data += "<a href='shutter.php'>Shutters - keepers of your privacy</a> :: <a href='lids.php'>Window lids - protection and safety</a> :: ";
	informator_data += "<a href='network.php'>Distribution network of MIRAL products</a> :: <a href='reference.php'>Our references</a> :: ";
	informator_data += "<a href='contact.php'>Send us e-mail - get your answers fast!</a>"
	document.getElementById('informator').innerHTML = informator_data;
	
	//var visina_tabele = document.getElementById('Table_01').clientHeight;
	//document.getElementById('zone').top = visina_tabele - 5;
}

function navi_tip(){
	if (navigator.appName == "Microsoft Internet Explorer"){
		var ime_navi = "MSIE";
	} else if (navigator.appName == "Netscape") {
		var ime_navi = "Netscape";
	}
	return ime_navi;
}

//check validity of mail details
function kreni(form){
	var ime_browsera = navi_tip();
		
	switch (ime_browsera)
	{
		case "MSIE": 
			if (form.realname.value == "") {
				document.getElementById('imeiprezime').style.color = "#FF0000";
				//form.realname.focus()
				return false
				}
			if (form.address.value == "") {
				document.getElementById('adresa').style.color = "#FF0000";
				//form.address.focus()
				return false
				}
			if (form.email.value == "") {
				document.getElementById('mail').innerText = "You didn't enter your e-mail!"
				document.getElementById('mail').style.color = "#FF0000";
				//form.email.focus()
				return false
				}
			var izraz = form.email.value
			var pozicija = izraz.indexOf("@")
			var tacka = izraz.indexOf(".")
			var duzina = izraz.length
			if (pozicija == 0 || pozicija == -1){
				document.getElementById('mail').innerText = "Your e-mail is not valid!"
				document.getElementById('mail').style.color = "#FF0000";
				//form.email.focus()
				return false
				}
			if (tacka == -1 || tacka < pozicija + 1 || tacka == duzina-1) {
				document.getElementById('mail').innerText = "Your e-mail is not valid!"
				document.getElementById('mail').style.color = "#FF0000";
				//form.email.focus()
				return false
				}
			if (form.extra.value == "") {
				document.getElementById('poruka').style.color = "#FF0000";
				//form.extra.focus()
				return false
				}
			alert ("Thanks you on your interest. We will contact you in following 2 days!")
			return true
			break;
		
		case "Netscape":
			if (form.realname.value == "") {
				document.getElementById('imeiprezime').style.color = "#FF0000";
				//form.realname.focus()
				return false
				}
			if (form.address.value == "") {
				document.getElementById('adresa').style.color = "#FF0000";
				//form.address.focus()
				return false
				}
			if (form.email.value == "") {
				document.getElementById('mail').innerHTML = "You didn't enter your e-mail!"
				document.getElementById('mail').style.color = "#FF0000";
				//form.email.focus()
				return false
				}
			var izraz = form.email.value
			var pozicija = izraz.indexOf("@")
			var tacka = izraz.indexOf(".")
			var duzina = izraz.length
			if (pozicija == 0 || pozicija == -1){
				document.getElementById('mail').innerHTML = "Your e-mail is not valid!"
				document.getElementById('mail').style.color = "#FF0000";
				//form.email.focus()
				return false
				}
			if (tacka == -1 || tacka < pozicija + 1 || tacka == duzina-1) {
				document.getElementById('mail').innerHTML = "Your e-mail is not valid!"
				document.getElementById('mail').style.color = "#FF0000";
				//form.email.focus()
				return false
				}
			if (form.extra.value == "") {
				document.getElementById('poruka').style.color = "#FF0000";
				//form.extra.focus()
				return false
				}
			alert ("Thanks you on your interest. We will contact you in following 2 days!")
			return true
			break;
			
		default:
			break;
	}
}

//warn about illegal form mail fields
function red_white(objekat){
	var ime_browsera = navi_tip();
	
	if (ime_browsera == "MSIE"){	
		switch(objekat)
		{
			case "realname":
				if (document.getElementById('imeiprezime').style.color == "#ff0000"){
					document.getElementById('imeiprezime').style.color = "#ffffff";
				}
				break;
				
			case "address": 
				if (document.getElementById('adresa').style.color == "#ff0000"){
					document.getElementById('adresa').style.color = "#ffffff";
				}
				break;
			
			case "email": 
				if (document.getElementById('mail').style.color == "#ff0000"){
					document.getElementById('mail').style.color = "#ffffff";
				}
				break;
			
			case "extra": 
				if (document.getElementById('poruka').style.color == "#ff0000"){
					document.getElementById('poruka').style.color = "#ffffff";
				}
				break;
			
			default:
				break;
		}
	} else {
		switch(objekat)
		{
			case "realname":
				if (document.getElementById('imeiprezime').style.color == "rgb(255, 0, 0)"){
					document.getElementById('imeiprezime').style.color = "rgb(255, 255, 255)";
				}
				break;
				
			case "address": 
				if (document.getElementById('adresa').style.color == "rgb(255, 0, 0)"){
					document.getElementById('adresa').style.color = "rgb(255, 255, 255)";
				}
				break;
			
			case "email": 
				if (document.getElementById('mail').style.color == "rgb(255, 0, 0)"){
					document.getElementById('mail').style.color = "rgb(255, 255, 255)";
				}
				break;
			
			case "extra": 
				if (document.getElementById('poruka').style.color == "rgb(255, 0, 0)"){
					document.getElementById('poruka').style.color = "rgb(255, 255, 255)";
				}
				break;
			
			default:
				break;
		}
	}
}