// JavaScript Document

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function isNumeric(val)
{
	return(parseFloat(val,10)==(val*1));
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

function popup(file,width,height)
{
	newWin=window.open(file,"detailWin","dependent=yes,scrollbars=yes,toolbar=no,resizable=yes,height="+height+",width="+width+",menubar=no,left=10,top=10");
}


function votez(id)
{
	url=path+"votcom.php?idf="+id;
    window.open(url,"detailWin","dependent=yes,resizable=no,height=330,width=480,menubar=no,left=10,top=10");
}

function friendly(amount) //daca suma are mai mult de 3 zerouri se insereaza o virgula
{
	var suma="",sum="";
	
	suma=String(amount);
	
	if(suma.length-6>0)
	{
		sum+=suma.substring(0,suma.length-6);
		sum+=".";
		sum+=suma.substring(suma.length-6,suma.length-3);
		sum+=".";
		sum+=suma.substring(suma.length-3,suma.length);
	}
	else if(suma.length-3>0)
	{
		sum+=suma.substring(0,suma.length-3);
		sum+=".";
		sum+=suma.substring(suma.length-3,suma.length);
	}
	else sum+=suma;

	return sum;
}

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 '';
}

function SetCookie(name, value, days, path)
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	
	var expDate=new Date();
	expDate.setTime(expDate.getTime()+days*24*60*60*1000);
	
	expires=expDate;
	
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) +  ((domain == null) ? "" : ("; domain=" + domain)) +    ((secure == true) ? "; secure" : "");
}

// this deletes the cookie when called
function DeleteCookie( name, path, domain ) {
if ( GetCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function saveInfo()
{
	var info="";

	for(var i=0;i<Nsel;i++)
		info+=iid[i]+" "+ct[i]+" ";

	info=PretTotal+" "+Nsel+" "+info;
	
	SetCookie('cos',info,7,'/');
}

function getInfo()
{
	var info=GetCookie('cos');

	if(info!="")
	{
		iold=0;
//---- PretTotal ----------------------
		i=info.indexOf(" ",iold);
		PretTotal=parseFloat(info.substring(iold,i));
		iold=i+1;

//---- Nsel ----------------------
		i=info.indexOf(" ",iold);
		Nsel=parseFloat(info.substring(iold,i));
		iold=i+1;

//---- Cant[] ---------------------
		var j=0;
		for(j=0;j<Nsel;j++)
		{
			i=info.indexOf(" ",iold);
//			iid[j]=parseFloat(info.substring(iold,i));
			iid[j]=info.substring(iold,i);
			iold=i+1;
			i=info.indexOf(" ",iold);
			ct[j]=parseFloat(info.substring(iold,i));
			iold=i+1;
		}
	}
}

function comand(mag)
{
	//alert('Pentru moment nu facem livrari. Reveniti.');
	if(Nsel==0)alert("Nu aveti nici un produs in cos. Va rugam continuati cumparaturile.");
	else window.location.href=path+"casa.php?casa";
}

var iid=new Array(),ct=new Array(),Nsel=0;
var PretTotal=0;
var Unit="RON",PretMinim=0;
var path="http://www.ecumparaturi.ro/";
//var path="http://localhost/art/";



function jumpFiltru(selObj)
{
	document.filtru.action=selObj.options[selObj.selectedIndex].value;
	document.filtru.submit();
}

function jumpCategs(selObj)
{
	window.location.href=selObj.options[selObj.selectedIndex].value;
}


function cauta()
{
	var art=document.cautare.cauta.value;
	if(art=="")return;	
	window.location.href=path+"?cauta="+art;//+"&mag="+magazin;
}
function cauta1()
{
	var art=document.cautare1.cauta.value;
	if(art=="")return;

	window.location.href=path+"?cauta="+art;//+"&mag="+magazin;
}

function plus(id)
{
	eval("document."+id+".value++");
}

function minus(id)
{
		if(eval("document."+id+".value>1"))
		  eval("document."+id+".value--");
}


function update(id,pret,idd,frm,pag)
{
	var cantitate=0,a;
	
	if(eval("trim(document."+frm+"."+idd+".value)"))
    	eval("cantitate=parseFloat(document."+frm+"."+idd+".value)");

	eval("document."+frm+"."+idd+".value='1'");
	
	if(cantitate<1)return;

	a=0;
	for(var ii=0;ii<Nsel;ii++)
		if(id==iid[ii])
		{	
			ct[ii]+=cantitate;
			a=1;
			break;
		}
	
	if(!a) 
	{
		iid[Nsel]=id;
		ct[Nsel++]=cantitate;
	}
	PretTotal+=cantitate*pret;
	saveInfo();
	window.location.href=path+"cos-cumparaturi.php?ref="+pag;
}


function adaugaEmail() 
{
  var error = 0;
  var error_message = "Adresa de email incorect introdusa.\nVa rugam reincercati.";
  
  var email=document.lista1.email5.value;	

  if(email.indexOf('@')<0||email.indexOf('.')<0)
  {
  	 alert(error_message);	
	 return;
  } 
  top.location.href=path+'newsletter.php?adauga='+email;
  document.lista1.email5.value='email-ul dvs.'; 
//  alert(document.all.email5.value);
}

function scoateEmail()
{
  var error = 0;
  var error_message = "Adresa de email incorect introdusa.\nVa rugam reincercati.";
  var email=document.lista1.email5.value;	

  if(email.indexOf('@')<0||email.indexOf('.')<0)
  {
  	 alert(error_message);	
	 return;
  } 
  top.location.href=path+'newsletter.php?scoate='+email;
  document.lista1.email5.value='email-ul dvs.'; 
}

function jump(selObj)
{
	document.jumpto.moneda.value=selObj.options[selObj.selectedIndex].value;
	document.jumpto.submit();
}


function selectCateg(idp)
{
	if(document.getElementById('categ'+idp).className=='cl_')
	{
		document.getElementById('categ'+idp).className='cl';
		document.getElementById('ref'+idp).className='categclass';
	}
	else
	{
		document.getElementById('categ'+idp).className='cl_';
		document.getElementById('ref'+idp).className='categclass_';
	}	
}




function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function setState(which, state) {
	document.getElementById(which).style.display = state;
	if (self["timer"+which]!=null) clearTimeout(self["timer"+which]);
}

function toggleTimed( targetId, state ) {
	var states = new Array("none", "block");
	
	
	if (document.getElementById(targetId).style.display==states[state] && self["timer"+targetId]!=null)
		clearTimeout(self["timer"+targetId]);
	else {
		if (state==0)
		{
			self["timer"+targetId]=setTimeout("setState('"+targetId+"', '"+states[state]+"')", 350);
			
			}
		else
		{
			setState(targetId, states[state]);
			
		}
	}
}

// fade show ///


/***********************************************
* Ultimate Fade-In Slideshow (v1.5): © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
 
//SET IMAGE PATHS. Extend or contract array as needed
/*
fadeimages[0]=["photo1.jpg", "", ""] //plain image syntax
fadeimages[1]=["photo2.jpg", "http://www.cssdrive.com", ""] //image with link syntax
fadeimages[2]=["photo3.jpg", "http://www.javascriptkit.com", "_new"] //image with link and target syntax

var fadeimages2=new Array() //2nd array set example. Remove or add more sets as needed.
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages2[0]=["photo1.jpg", "", ""] //plain image syntax
fadeimages2[1]=["photo2.jpg", "http://www.cssdrive.com", ""] //image with link syntax
fadeimages2[2]=["photo3.jpg", "http://www.javascriptkit.com", "_new"] //image with link and target syntax
 */
 
 /*
var fadeimages=new Array();

fadeimages[0]=["images/banners/Casca-Bluetooth.jpg", "http://www.ecumparaturi.ro/telefoane/25679/casca_bluetooth_jabra_jx-10_ii_s", ""]; //plain image syntax
fadeimages[1]=["images/banners/yak54.jpg", "http://www.ecumparaturi.ro/jucarii/18153/avion_cu_radiocomanda_yak_54", ""]; //image with link syntax
fadeimages[2]=["images/banners/nokiae71.jpg", "http://www.ecumparaturi.ro/telefoane/7637/telefon_mobil_nokia_e71_gsm", ""]; //image with link syntax
fadeimages[3]=["images/banners/zanussi_frigider.jpg", "http://www.ecumparaturi.ro/electrocasnice/26469/combina_frigorifica_zanussi_zrb636dw", ""]; //image with link syntax
fadeimages[4]=["images/banners/stilou.jpg", "http://www.ecumparaturi.ro/birotica/29635/stilou_waterman_exception_slim_negru_st", ""]; //image with link syntax
fadeimages[5]=["images/banners/banner-avion.jpg", "http://www.ecumparaturi.ro/jucarii/18139/avion_tiger_moth", ""]; //image with link syntax
fadeimages[6]=["images/banners/htc-touch-pro.jpg", "http://www.ecumparaturi.ro/telefoane/29405/smartphone_htc_touch_pro", ""]; //image with link syntax
fadeimages[7]=["images/banners/aspirator-hoover.jpg", "http://www.ecumparaturi.ro/electrocasnice/24189/aspirator_bagless_hoover_tfs7184", ""]; //image with link syntax
fadeimages[8]=["images/banners/banner_DSLR-A300K.jpg", "http://www.ecumparaturi.ro/foto-video/27357/aparat_foto_sony_dslr_a300k", ""]; //image with link syntax
*/


 

 
////NO need to edit beyond here/////////////
 
var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers
 
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all
 
function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}
 
var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2
 
if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;-khtml-opacity:10;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
 
if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}

function fadepic(obj){
if (obj.degree<100){
obj.degree+=10
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}
 
fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}
 
 
fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}
 
fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=obj.degree/100
}
 
 
fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}

////////////////////////

