// JavaScript Document
function tabSwitch(active, number, tab_prefix, content_prefix) {
	
	for (var i=1; i < number+1; i++) {
	  document.getElementById(content_prefix+i).style.display = 'none';
	  document.getElementById(tab_prefix+i).className = '';
	}
	document.getElementById(content_prefix+active).style.display = 'block';
	document.getElementById(tab_prefix+active).className = 'active';	
	
}

// show hide mainDet content
function show(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='block';
}
function hide(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='none';
}
function showHide(divID) 
{
	document.getElementById(divID).style.display == 'none' ? document.getElementById(divID).style.display = 'block' : document.getElementById(divID).style.display = 'none';
}

// Checks if a field is empty, and if so, resets the input's content to the default value
function checkField( obj, value )
{
	// Match any amount of white spaces
	if( obj.value == "" )
	{
		obj.value = value;
	}
	
	return false;
}

// Clears an input's content
function clearField( obj, value )
{
	if( obj.value == value )
	{
		obj.value = "";
	}
	
	return false;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function reloadWindow()
{
	window.location=mainWebsiteURL;
	
	return;
}

function viewBox(bid, iid)
{
	if (iid.checked) document.getElementById(bid).style.display = 'block';
	else  document.getElementById(bid).style.display = 'none';
}

function orderDetail(oid)
{
	linie = document.getElementById(oid);
	if (linie.style.display == 'table-row') 
	{
		linie.style.display = 'none';
	}
	else
	{
		linie.style.display = 'table-row';
	}
}

function obiect(id)
{
	if (document.getElementById(id)) return document.getElementById(id);
	else return false;
}

function changeSofer(poza,nume)
{
	if (obiect('picSofer') && obiect('numeSofer'))
	{
		obiect('numeSofer').innerHTML = decodeURIComponent(nume.replace(/\+/g,  " "));
		obiect('picSofer').src = decodeURIComponent(poza.replace(/\+/g,  " "));
		obiect('picSofer').alt = decodeURIComponent(nume.replace(/\+/g,  " "));
	}
}

function encode(obj) {
	var unencoded = obj;
	return encodeURIComponent(unencoded);
}

function decode(obj) {
	var obj = document.getElementById('dencoder');
	var encoded = obj.value;
	obj.value = decodeURIComponent(encoded.replace(/\+/g,  " "));
}

function updateOptions(sel, id, sel_label)
{
	for (c=1;c<=5;c++) 
	{
		if (obiect('c'+c)) obiect('c'+c).style.display = 'none';
	}
	if (sel.value != '0')
	{
		arr1 = tari[sel.value].split('$');
		resetSelect('orase');
		insertOption('orase',sel_label,0);
		for (i=0;i<arr1.length;i++)
		{
			if (arr1[i] != '')
			{
				arr2 = arr1[i].split('|');
				insertOption('orase',arr2[1],arr2[0]);
			}
		}
		selectOption('orase',0);
		if (obiect('c'+continente[sel.value])) obiect('c'+continente[sel.value]).style.display = 'block';
	}
	else 
	{
		resetSelect('orase');
		insertOption('orase',sel_label,0);
	}
	updateServicii(obiect('orase'));
}

function insertOption(sId, txt, val)
{
	select = obiect(sId);
	var opt = document.createElement('OPTION');
	opt.text = txt;
	opt.value = val;
	try 
	{
		select.add(opt, null);
	}
  	catch(ex) 
  	{
    	select.add(opt);
	}
}

function resetSelect(sId)
{
	select = obiect(sId);
	for (i=select.length-1;i>=0;i--) 
	{
		select.remove(i);
	}
}

function selectOption(sId, index)
{
	select = obiect(sId);
	select[index].selected = 1;
}

function checkBookForm(form, prefix)
{
	tara = form.tid.value;
	oras = form.oid.value;
	error = 'Nu ati selectat locatia completa!';
	error_en = 'Please select the complete location!';
	if (tara == 0 || oras == 0)
	{
		alert(error+prefix);
		return false;
	}
	else return true;
}

function checkBookForm2(form, prefix)
{
	oras = form.oid.value;
	error = 'Nu ati selectat locatia completa!';
	error_en = 'Please select the complete location!';
	if (oras == 0)
	{
		alert(error+prefix);
		return false;
	}
	else return true;
}

function openForm(caz)
{
	left = screen.width/2-300;
	switch (caz)
	{
		case "companii":
			window.open("contactForm.php?tip=companii","Contact","scrollbars=no,width=600,height=750,left="+left+",top=50");
			break
		case "operator":
			window.open("contactForm.php?tip=operator","Contact","scrollbars=no,width=600,height=750,left="+left+",top=50");
			break
		case "persoane":
			window.open("contactForm.php?tip=persoane","Contact","scrollbars=no,width=600,height=750,left="+left+",top=50");
			break
		case "afiliati":
			window.open("contactForm.php?tip=afiliati","Contact","scrollbars=no,width=600,height=750,left="+left+",top=50");
			break
		default:
			window.open("contactForm.php?tip=companii","Contact","scrollbars=no,width=600,height=750,left="+left+",top=50");
			break
	}
}

function markFields(campuri)
{
	var vector = new Array;
	vector = campuri.split("%");
	for (i=0;i<vector.length;i++)
	if (document.getElementById(vector[i]))
	{
		if (vector[i] == 'ttip1' || vector[i] == 'ttip2') document.getElementById(vector[i]+'l').style.backgroundColor = '#e1c8c3';
		else document.getElementById(vector[i]).style.backgroundColor = '#e1c8c3';
	}
}
