//
//  BROWSER DETECTION
//

var dom = (document.getElementById)? true : false;
var nn4 = (document.layers)? true : false;
var ie4 = (!dom && document.all)? true : false;
var opr = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;

//
// IMAGES
//

function objImage(imgName,imgOff,imgOn) 
{
	this.name = imgName;
	this.offImgObject = loadImage(imgOff);
	this.onImgObject  = loadImage(imgOn);
	this.on  = imageOn;
	this.off = imageOff;
	this.statuson  =  false;
}

function imageOn()
{
	document[this.name].src = this.onImgObject.src;
	this.statuson = true;
}

function imageOff()
{
	document[this.name].src = this.offImgObject.src;
	this.statuson = false;
}

function loadImage(imgSrcName)
{
	imgObject = new Image()
	imgObject.src = imgSrcName;
	return imgObject;
}
//
// COOKIES
//

var today = new Date();
var expiryyear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
var expirymonth = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000);
var expiryday = new Date(today.getTime() + 24 * 60 * 60 * 1000);

function getCookieVal(offset) 
{
	var endstr = document.cookie.indexOf(";", offset);
	if(endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) 
		{
			return getCookieVal (j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return 0;
}

function deleteCookie(name,path,domain) 
{
	if (getCookie(name)) 
	{
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function setCookie( name, value, expires, path, domain, secure ) 
{

var today = new Date();
today.setTime( today.getTime() );

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}





function startflashcookie() {
	if (getCookie('tlmflash') == 'flashviewed') {
		window.location = 'index.php';
		
	} else {
		setCookie( 'tlmflash', 'flashviewed', 30, '/', '', '' );
	}

	

}



function openGroup(id) {
	if (dom) {
		if (document.getElementById('group' + id).style.display == 'none') {
			eval('icon' + id + '.on();');
			document.getElementById('group' + id).style.display = 'block';
		} else {
			eval('icon' + id + '.off();');
			document.getElementById('group' + id).style.display = 'none';
		}
	} else if (ie4 || opr) {
		document.all['group' + id].style.display = (document.all['group' + id].style.display == 'none') ? 'block' : 'none';
	}
	
	if (document.ProductForm) {
		for (var i = 0; i < document.ProductForm.Category.length; i++) {
			if (document.ProductForm.Category[i].value == id) document.ProductForm.Category.selectedIndex = i;
		}
	}
}

function openWindow(winName,winURL,winFullScreen,winChannelMode,winToolBar,winLocation,winDirectories,winStatus,winMenubar,winScrollbars,winResizable,winWidth,winHeight,winTop,winLeft)
{
	var winFeatures  = "fullscreen=" + winFullScreen + "," + "channelmode=" + winChannelMode + "," + "toolbar=" + winToolBar + "," + "location=" + winLocation + "," + "directories=" + winDirectories + "," + "status=" + winStatus + "," + "menubar=" + winMenubar + "," + "scrollbars=" + winScrollbars + "," + "resizable=" + winResizable + "," + "width=" + winWidth + "," + "height=" + winHeight + "," + "top=" + winTop + "," + "left=" + winLeft + ",";
	var winName = window.open(winURL,winName,winFeatures);
}


function openSpan(name) {
	if (dom) {
		document.getElementById(name).style.display = 'block';
	} else if (ie4 || opr) {
		document.all[name].style.display = 'block';
	}
}


function closeSpan(name) {
	if (dom) {
		document.getElementById(name).style.display = 'none';
	} else if (ie4 || opr) {
		document.all[name].style.display = 'none';
	}
}

function loadSpan (name, info) { 
	if (dom) eval('document.getElementById("' + name + '").innerHTML = info;');
	else if (ie4 || opr) eval('document.all["' + name + '"].innerHTML = info;');
}


function changeLanguage(Language) {
	document.mainForm.Language.value = parseInt(Language);
	document.mainForm.submit();
}

function SearchQuery() {
	document.searchForm.submit();	
}

function DigitsCheck (item) {
	var str = document.getElementById(item).value
	var digits = '0987654321';
	var resstring = '';
	var char = '';

	for (var i = 0; i < str.length; i++) {
		char = str.substring(i, i + 1);
		
		if (digits.indexOf(char) >= 0) {
			resstring += char;
		}
	}
	
	document.getElementById(item).value = resstring;
}

function FloatCheck (item) {
	var str = document.getElementById(item).value
	var digits = '0987654321.';
	var resstring = '';
	var char = '';

	for (var i = 0; i < str.length; i++) {
		char = str.substring(i, i + 1);
		
		if (digits.indexOf(char) >= 0) {
			resstring += char;
		}
	}
	
	document.getElementById(item).value = resstring;
}

function isEmail(item) {
	var at="@"
	var dot="."
	var lat=item.indexOf(at)
	var litem=item.length
	var ldot=item.indexOf(dot)
	
	if (item.indexOf(at)==-1) return false;	
	if (item.indexOf(at)==-1 || item.indexOf(at)==0 || item.indexOf(at)==litem) return false;
	if (item.indexOf(dot)==-1 || item.indexOf(dot)==0 || item.indexOf(dot) >= litem - 2) return false;
	if (item.indexOf(at,(lat+1))!=-1) return false;
	if (item.substring(lat-1,lat)==dot || item.substring(lat+1,lat+2)==dot) return false;
	if (item.indexOf(dot,(lat+2))==-1) return false;
	if (item.indexOf(" ")!=-1) return false;
	return true	
}

function Submit() {
	
	var email = document.getElementById('email').value
	
	if (isEmail(email)) {
		document.subscribeForm.submit();	
	} else {
		alert('Complectati cimpurile obligatorii');
	}
}


function SubmitCalc() {
	if ((document.getElementById('pret').value != '') && (document.getElementById('avans').value != '') && (document.getElementById('casco').value != '') && (document.getElementById('perioada').value != '')) {
		document.leasing.submit();
	}
}


function Print() {
	
	var pret = document.leasing.pret.value;
	var avans = document.leasing.avans.value;
	var rata = document.leasing.rata.value;
	var comision = document.leasing.comision.value;
	var casco = document.leasing.casco.value;
	var perioada = document.leasing.perioada.value;
	var frecventa = document.leasing.frecventa.value;

	printWindow = openWindow('print','print.php?pret=' + pret + '&avans=' + avans + '&rata=' + rata + '&comision=' + comision + '&casco=' + casco + '&perioada=' + perioada + '&frecventa=' + frecventa + '',0,0,0,0,0,0,0,1,1,600,500,0,0);
}


function windowPrint() {
	window.print();
	window.close();
}

function openMap() {
openWindow('TotalMap','officeshot.php',0,0,0,0,0,0,0,0,0,500,350,30,30);


}


function switchSpan(item) {
	if (document.getElementById(item).style.display == 'none') {
		openSpan(item);
	} else {
		closeSpan(item);
	}
}


function aboutus(item) {

  if (item == 'about') {
    switchSpan('about');
    closeSpan('mission');
    closeSpan('Acts');
    closeSpan('technik');
  } else if (item == 'mission') {
    closeSpan('about');
    switchSpan('mission');
    closeSpan('Acts');
    closeSpan('technik');
  } else if (item == 'Acts'){
    closeSpan('about');
    closeSpan('mission');
    switchSpan('Acts');
    closeSpan('technik');
  } else {
    switchSpan('technik');
    closeSpan('about');
    closeSpan('mission');
    closeSpan('Acts');
  }
}


function leasing(item) {

  if (item == 'auto') {
    switchSpan('auto');
    closeSpan('util');
    closeSpan('technic');
  } else if (item == 'util') {
    closeSpan('auto');
    closeSpan('technic');
    switchSpan('util');
  } else {
    closeSpan('auto');
    closeSpan('util');
    switchSpan('technic');
  }
}



function SubmitJ() {
	
//	var email = document.getElementById('email').value;
	
	var allfields = isEmpty('name') + isEmpty('adress') + isEmpty('phone') + isEmpty('director') + isEmpty('cont') +  isEmpty('contact') + isEmpty('date') + isEmpty('time');

	if (allfields == 8) {
		document.leasingForm.submit();	
	} else {
		alert('Complectati toate cimpurile');
	}
}

function SubmitF() {
	
//	var email = document.getElementById('email').value;
	
	var allfields = isEmpty('name') + isEmpty('adress') + isEmpty('phone') + isEmpty('date') + isEmpty('time');

	if (allfields == 5) {
		document.leasingForm.submit();	
	} else {
		alert('Complectati toate cimpurile');
	}
}

function isEmpty(item) {
	if (document.getElementById(item).value == '') {
		return 0;
	} else {
		return 1;
	}
}

function runstartflash() {
  document.write('<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="320" height="240" id="tlmstartflash" align="middle" >\n');
  document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
  document.write('<param name="movie" value="tlmstartflash.swf" />\n');
  document.write('<param name="quality" value="high" />\n');
  document.write('<param name="bgcolor" value="#ffffff" />\n');
  document.write('<embed src="tlmstartflash.swf" quality="high" bgcolor="#ffffff" width="320" height="240" name="tlmstartflash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
  document.write('</object>\n');
  
}

function runcontentflash(lang, startframe) {
  document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="300" height="250" id="menu' + lang +'" align="middle">\n');
  document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
  document.write('<param name="movie" value="menu' + lang +'.swf?startframe=' + startframe +'" />\n');
  document.write('<param name="quality" value="high" />\n');
  document.write('<param name="bgcolor" value="#ffffff" />\n');
  document.write('<embed src="menu' + lang +'.swf?startframe=' + startframe +'" quality="high" bgcolor="#ffffff" width="300" height="250" name="menu" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
  document.write('</object>\n');
}
