// change selected option in product description
// used in product detail
function changeOther(thisItem, divId)
{
	// change other spans
	var spans = thisItem.parentNode.getElementsByTagName('span');
	for ( i=0; i < spans.length; i ++)
	{
		if ( spans[i].className != "hdn" )
		{
			if (spans[i] == thisItem)
			{
				spans[i].className = "tab active";
			}
			else 
			{
				spans[i].className = "tab";
			}
		}
	}
	// change other divs from Id in divId
	var divs = thisItem.parentNode.getElementsByTagName('div');
	for ( i=0; i < divs.length; i ++)
	{
		if (divs[i].id == divId)
		{
			divs[i].className = "text";
		}
		else 
		{
			divs[i].className = "text hdn";
		}
	}
}
// show item image color
function showColor(colorUrl, colorBigUrl)
{
	var image = document.getElementById('js-img-detail');
	var anchorImage = document.getElementById('js-a-imageDetailHref');

	//anchorImage.href = 'javascript:popImage(\''+colorBigUrl+'\',\''+colorBigUrl+'\');';
	anchorImage.href = colorBigUrl;
	anchorImage.onclick = function(){showBig(colorBigUrl,anchorImage);return false;}
	image.src = colorUrl;
}

// change image
function nextImage(thisButton)
{
	var image = document.getElementById('js-img-detail');
	var inputList = document.getElementById('js-input-list');
	var inputListBig = document.getElementById('js-input-list-big');
	var inputActual = document.getElementById('js-input-actual');
	var anchorImage = document.getElementById('js-a-imageDetailHref');
	var arrImages = inputList.value.split(';');
	var arrImagesBig = inputListBig.value.split(';');
	var strongImagePage = document.getElementById('js-strong-imagePaging');
	
	if ( (inputActual.value*1) + 1 != arrImages.length)
	{
		inputActual.value = inputActual.value*1 + 1;
	}
	image.src = arrImages[inputActual.value*1];
	//anchorImage.href = 'javascript:popImage(\''+arrImagesBig[inputActual.value*1]+'\',\''+arrImagesBig[inputActual.value*1]+'\');';
	anchorImage.href = arrImagesBig[inputActual.value*1];
	anchorImage.onclick = function(){showBig(arrImagesBig[inputActual.value*1],anchorImage);return false;}
	
	strongImagePage.innerText = inputActual.value*1+1 +'/'+ arrImages.length;
	strongImagePage.innerHTML = inputActual.value*1+1 +'/'+ arrImages.length;
}
function previousImage(thisButton)
{
	var image = document.getElementById('js-img-detail');
	var inputList = document.getElementById('js-input-list');
	var inputActual = document.getElementById('js-input-actual');
	var inputListBig = document.getElementById('js-input-list-big');
	var anchorImage = document.getElementById('js-a-imageDetailHref');
	var arrImages = inputList.value.split(';');
	var arrImagesBig = inputListBig.value.split(';');
	var strongImagePage = document.getElementById('js-strong-imagePaging');
	
	if ( (inputActual.value*1) > 0)
	{
	inputActual.value = inputActual.value*1 - 1;
	}
	image.src = arrImages[inputActual.value*1];
	//anchorImage.href = 'javascript:popImage(\''+arrImagesBig[inputActual.value*1]+'\',\''+arrImagesBig[inputActual.value*1]+'\');';
	anchorImage.href = arrImagesBig[inputActual.value*1];
	anchorImage.onclick = function(){showBig(arrImagesBig[inputActual.value*1],anchorImage);return false;}
	
	
	strongImagePage.innerText = inputActual.value*1+1 +'/'+ arrImages.length;
	strongImagePage.innerHTML = inputActual.value*1+1 +'/'+ arrImages.length;
}

// function to check the combination for the item
function checkCombination(thisSelect)
{
	var inputCombinations = document.getElementById('js-input-availablesProperties');
	var inputItemAltNumber = document.getElementById('js-input-altNumber');
	var spanSupported = document.getElementById('js-span-support');
	var combinations = inputCombinations.value.split(';');
	//create combinations
	var selects = thisSelect.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('select');//from table
	var combinationString = inputItemAltNumber.value;
	var boolInList = false;
	var boolSelectedAll = true;
	for (i = 0; i < selects.length; i++)
	{
		combinationString = combinationString +"#"+ selects[i].value;
		if ( selects[i].value == "-1")
		{
			boolSelectedAll = false;
		}
	}
	
	//alert(combinationString);
	
	for (i = 0; i < combinations.length; i++)
	{
		if ( combinationString == combinations[i].toString())
		{
			boolInList = true;
		}
	}
	
	if ( boolSelectedAll )
	{
		if (!boolInList)
		{	
			spanSupported.innerText = 'Combination Not Available';
			spanSupported.innerHTML = 'Combination Not Available';
			spanSupported.className = 'red';
		}
		else
		{
			spanSupported.innerText = '<br/>';//'Combination is Available';
			spanSupported.innerHTML = '<br/>';//'Combination is Available';
			spanSupported.className = 'green';
		}
	}
	else
	{
			spanSupported.innerText = 'Please Select:';
			spanSupported.innerHTML = 'Please Select:';
			spanSupported.className = 'blue';
	}
	//alert(spanSupported.outerText);
}

var resizeFrame;
var resizeImg;

function showBig(imageURL,href)
{
	var newDiv = document.createElement('div');
	var newImg = document.createElement('img');
	var body = document.getElementsByTagName('body');
	var closeImg = document.createElement('img');
	var aBaseRef = document.getElementById('aBaseRef');
	
	resizeFrame = newDiv;
	resizeImg = newImg;
	//var close = document.createElement('a');
	//newDiv.setAttribute('id','divBigImage');
	if (document.getElementById('divBigImage'))
	{
		body[0].removeChild(document.getElementById('divBigImage'));
	}
	newDiv.id = 'divBigImage';
	//btn.setAttribute('onClick','alert("wow")');
    //close.href = 'javascript:this.parentNode.remove();';
    //close.onclick = function(){this.parentNode.parentNode.removeChild(newDiv);};
    //close.innerText = 'x';
    //close.innerHTML = 'x';
    //close.style.cursor = 'pointer';
	//newDiv.onClick = 'alert("wow");';
	//newDiv.setAttribute('style','border:solid 2px #CCCCCC;position:absolute;top:100px;left:100px;z-index:100;background-color:white;width:600px;height:700px;');

	closeImg.setAttribute('src',aBaseRef.href +'/styles/img/closeL.jpg');
	
	newDiv.style.border = 'solid 2px #888888';
	newDiv.style.position = 'absolute';
	newDiv.style.top = '50px';
	newDiv.style.left = '50px';
	newDiv.style.zIndex = '100';
	newDiv.style.backgroundColor = '#FFFFFF';
	
	
	//newImg.setAttribute('src',imageURL);
	newImg.src = imageURL;
	newImg.style.cursor = 'pointer';
	newImg.onLoad = resizeDiv(newImg,newDiv);
	newDiv.onclick = function(){this.parentNode.removeChild(newDiv);};
	newDiv.style.height = newImg.height+'px';
	newDiv.style.width = newImg.width+'px';
	newDiv.style.background = 'url('+imageURL+')';
	//background: url(img/html.gif)
	closeImg.style.cursor = 'pointer';
	//closeImg.style.position = 'absolute';
	closeImg.onclick = function(){this.parentNode.parentNode.removeChild(newDiv);};
	
	//var dimension = document.createTextNode(newImg.height + "x" + newImg.width);
	//var imageName = document.createTextNode(newImg.src);
	body[0].insertBefore(newDiv,body[0].firstChild);
	//body[0].appendChild(newDiv);
	//newDiv.appendChild(dimension);
	//newDiv.appendChild(imageName);
	//newDiv.appendChild(close);
	newDiv.appendChild(closeImg);
	//newDiv.appendChild(newImg);
	
	//newImg.setAttribute('height',newImg.height);
}

function resizeDiv()
{
	if ( resizeImg.height == 0 )
	{
		casovac = window.setTimeout("resizeDiv()",200);
	}
	else
	{
		//alert(resizeImg.height + 'x' + resizeImg.width + 'this is size of loaded image');
		resizeFrame.style.height = resizeImg.height+'px';
		resizeFrame.style.width = resizeImg.width+'px';
	}
}

function call()
{
	alert('Call testing function is successfull ');
}