// JavaScript Document
function menuOver(imgId,sel)
{
	document.getElementById(imgId).src = "/img/"+imgId+sel+".jpg";
}
function getParentId(idControl)
{
    return idControl.substring(0,idControl.lastIndexOf("_")+1);
}
function displayListItems(divItems)
{
    var divList = document.getElementById(divItems);	
	if(divList.style.display == "" || divList.style.display == "block" )
	{			
		divList.style.display= "none";	
	}
	else
	{    
	 divList.style.display= "block";	  
	}
	
}
function editBasket(idProduct,action)
{
	if(action == "d")
	{
		document.getElementById("hDeleteProd").value = idProduct;
	}
	if(action == "u")
	{
		document.getElementById("hUpdateProd").value = idProduct;
	}
	document.fBasket.submit();
}
function selectDelivery(id,title)
{
	document.getElementById("hDelevery").value = title;
	document.getElementById("product_hSelectedItem").value = id;
	document.fBasket.submit();
}
function validateField(idInput,dvError,extraValidation)
{	
	var valid = true;
	//var inputE = document.getElementById(idInput).value.replace("'","\'");	
	var inputE = document.getElementById(idInput).value.replace("\"","");	
	
	if(extraValidation != "")
	{
		var st = extraValidation+'("'+inputE+'")';
		var isVal = eval(st);	
		if(!isVal)
		{ 
			if(dvError != "")
				document.getElementById(dvError).innerHTML += errorTexts[errorIndex];
			document.getElementById(idInput).style.border= "solid 1px #B11F24";
			valid = false;
			
		}
		else
		{
			if(dvError != "")
				document.getElementById(dvError).innerHTML += "";
			document.getElementById(idInput).style.border= "solid 1px #EDEAE2";
		}
		
	}
	else
	{
		if(dvError != "")
			document.getElementById(dvError).innerHTML += "";
		document.getElementById(idInput).style.border= "solid 1px #EDEAE2";	
	}		
	
	return valid;
}
function requierdField(idInput,dvError)
{
	var valid = true;
	var inputE = document.getElementById(idInput).value;
	if(inputE == "")
	{
		//if(dvError != "")
			//document.getElementById(dvError).innerHTML = errorTexts[0];			
		document.getElementById(idInput).style.border= "solid 1px #B11F24";
		valid = false;		
	}
	else
		document.getElementById(idInput).style.border= "solid 1px #EDEAE2";
	
	return valid;
}

function validateField1(idInput,dvError,extraValidation)
{	
	var valid = true;
	//var inputE = document.getElementById(idInput).value.replace("'","\'");	
	var inputE = document.getElementById(idInput).value.replace("\"","");	
	
	if(extraValidation != "")
	{
		var st = extraValidation+'("'+inputE+'")';
		var isVal = eval(st);	
		if(!isVal)
		{ 
			if(dvError != "")
				document.getElementById(dvError).innerHTML += errorTexts[errorIndex];
			document.getElementById(idInput).style.backgroundColor = "#C2B59B";
			valid = false;
			
		}
		else
		{
			if(dvError != "")
				document.getElementById(dvError).innerHTML += "";
			document.getElementById(idInput).style.backgroundColor = "#ffffff";
		}
		
	}
	else
	{
		if(dvError != "")
			document.getElementById(dvError).innerHTML += "";
		document.getElementById(idInput).style.backgroundColor = "#ffffff";	
	}		
	
	return valid;
}

function requierdField1(idInput,dvError)
{	
	var valid = true;
	if(document.getElementById(idInput) == null) alert(idInput);
	var inputE = document.getElementById(idInput).value;
	if(inputE == "")
	{
		//if(dvError != "")
			//document.getElementById(dvError).innerHTML = errorTexts[0];			
		document.getElementById(idInput).style.backgroundColor = "#C2B59B";
		valid = false;		
	}
	else
		document.getElementById(idInput).style.backgroundColor = "#ffffff";;
	
	return valid;
}

function emailCheck(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		return false;
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false;
	 }
	 return true;					
}
function checkDelivery(cb)
{
	var name = document.getElementById("txNamel");
	var lastname = document.getElementById("txLastNamel");
	var address = document.getElementById("txAddressl");
	var city = document.getElementById("txCityl");
	var region = document.getElementById("txRegionl");
	var postal = document.getElementById("txPostall");
	var tel = document.getElementById("txTell");
	
	if(cb.checked)
	{
		name.readOnly = true;		
	    lastname.readOnly = true;
	    address.readOnly = true;
	    city.readOnly = true;
	    region.readOnly = true;
	    postal.readOnly = true;
	    tel.readOnly = true;
		
		name.style.backgroundColor = "#E7E1D7";
		lastname.style.backgroundColor = "#E7E1D7";
	    address.style.backgroundColor = "#E7E1D7";
	    city.style.backgroundColor = "#E7E1D7";
	    region.style.backgroundColor = "#E7E1D7";
	    postal.style.backgroundColor = "#E7E1D7";
	    tel.style.backgroundColor = "#E7E1D7";
	}
	else
	{
		name.readOnly = false;
	    lastname.readOnly = false;
	    address.readOnly =false;
	    city.readOnly = false;
	    region.readOnly = false;
	    postal.readOnly = false;
	    tel.readOnly = false;
		
		name.style.backgroundColor = "#ffffff";
		lastname.style.backgroundColor = "#ffffff";
	    address.style.backgroundColor = "#ffffff";
	    city.style.backgroundColor = "#ffffff";
	    region.style.backgroundColor = "#ffffff";
	    postal.style.backgroundColor = "#ffffff";
	    tel.style.backgroundColor = "#ffffff";
	}
}
function checkCompany(cb)
{
	var name = document.getElementById("txCompany");
	var cif = document.getElementById("txCif");
	var cnr = document.getElementById("txCnr");
	var address = document.getElementById("txCAddress");
	var city = document.getElementById("txCCity");
	var region = document.getElementById("txCRegion");
	var postal = document.getElementById("txPostall");
	var bank = document.getElementById("txBank");
	var account = document.getElementById("txAccount");
	
	if(!cb.checked)
	{
		name.readOnly = true;		
	    cif.readOnly = true;
		cnr.readOnly = true;
	    address.readOnly = true;
	    city.readOnly = true;
	    region.readOnly = true;
	    postal.readOnly = true;
	  	bank.readOnly = true;
		account.readOnly = true;
		
		name.style.backgroundColor = "#E7E1D7";
		cif.style.backgroundColor = "#E7E1D7";
		cnr.style.backgroundColor = "#E7E1D7";
	    address.style.backgroundColor = "#E7E1D7";
	    city.style.backgroundColor = "#E7E1D7";
	    region.style.backgroundColor = "#E7E1D7";
	    postal.style.backgroundColor = "#E7E1D7";
	    bank.style.backgroundColor = "#E7E1D7";
		account.style.backgroundColor = "#E7E1D7";
	}
	else
	{
		name.readOnly = false;		
	    cif.readOnly = false;
		cnr.readOnly = false;
	    address.readOnly = false;
	    city.readOnly = false;
	    region.readOnly = false;
	    postal.readOnly = false;
	  	bank.readOnly = false;
		account.readOnly = false;
		
		name.style.backgroundColor = "#ffffff";
		cif.style.backgroundColor = "#ffffff";
		cnr.style.backgroundColor = "#ffffff";
	    address.style.backgroundColor = "#ffffff";
	    city.style.backgroundColor = "#ffffff";
	    region.style.backgroundColor = "#ffffff";
	    postal.style.backgroundColor = "#ffffff";
	    bank.style.backgroundColor = "#ffffff";
		account.style.backgroundColor = "#ffffff";
		
	}
}
function expandDiv(idElement)
{	
	
	if( document.getElementById(idElement).style.display == "none")
	{	
		document.getElementById("l"+idElement).innerHTML = "-";	
	}
	else
		document.getElementById("l"+idElement).innerHTML = "+";
	Effect.toggle(idElement,'BLIND');
	
	
}
function  getPageHeightWidth()
{
  var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}
function initElements(type)
{		
	   if(document.getElementById("dhtmlgoodies_scrolldiv") != null)
	   {	
	   		var contentDiv = document.getElementById("scrolldiv_content");
	        scrolldiv_setColor('#C2B59B');	// Setting border color of the scrolling content				
			setSliderBgColor('#B11F24');
			setContentBgColor('#B11F24');	// Setting color of the scrolling content
			setScrollButtonSpeed(1);	// Setting speed of scrolling when someone clicks on the arrow or the slider
			setScrollTimer(3);	// speed of 1 and timer of 5 is the same as speed of 2 and timer on 10 - what's the difference? 1 and 5 will make the scroll move a little smoother.
				
		    if(type == 1) //terms and conditions
		    {
			   if(contentDiv.offsetHeight > 346)
				{
					
					document.getElementById("scrolldiv_slider").style.display="block";
					scrolldiv_setWidth(350);	// Setting total width of scrolling div
					scrolldiv_setHeight(350);	// Setting total height of scrolling div
					scrolldiv_initScroll();	// Initialize javascript functions					
				}
				
					
		   	}
			 if(type == 2) //orders
		    {
			   if(contentDiv.offsetHeight > 400)
				{
					document.getElementById("scrolldiv_slider").style.display="block";
					scrolldiv_setWidth(606);	// Setting total width of scrolling div
					scrolldiv_setHeight(417);	// Setting total height of scrolling div
					scrolldiv_initScroll();	// Initialize javascript functions
					
				}
				
					
		   	}
			
			if(document.attachEvent)
			{
				document.getElementById("scrolldiv_slider").attachEvent('onselectstart', rfalse); 
			}
		}
		
		
}
//window.onload = initElements;
function rfalse()
{
return false;
} 
function closePopup()
{
	document.getElementById('dvPopupContent').style.display='none';
	document.getElementById('dvPopup').style.display='none';
}
//display swf object in specified parent div
function displayFlash(parentDiv,flashFile,imgFile,width,height)
{
	var divP = document.getElementById(parentDiv);
	if(divP!=null)
	{
		var so = new SWFObject(flashFile, "", width, height, "8", "#FFFFFF");
		so.addParam("wmode", "transparent");
		so.write(parentDiv);
		if(flashFile=='/upload/')
			divP.innerHTML = "<img src='"+imgFile+"' alt=''/>";
	}
}