﻿// JScript File

function CProduct(ProductId, Price, ourPrice, Dynamic, Count,  Quantity) {
	this.ProductId = ProductId;
	this.Price = Price;
	this.ourPrice = ourPrice;
	this.Dynamic = Dynamic;
	this.Count = Count;
	this.Quantity = Quantity;
}


function initRegular(ProductId, orPrice, iOurPrice, QuantityLeft) {
	var orPriceh = document.getElementById("orPrice");
	var iOurPriceh = document.getElementById("iOurPrice"); 
	var basket = document.getElementById("basket");
	orPriceh.innerHTML = orPrice;
	iOurPriceh.innerHTML = iOurPrice; 
	document.productform.elements["RId"].value = ProductId;
	var soldout = document.getElementById("soldout");
	if(QuantityLeft!=0) {
		basket.innerHTML = "<a href=\"javascript:document.productform.submit();\"><img src=\"images/123124Tosk.png\" width=\"255\" height=\"53\" border=\"0\"></a>";
	} else {
		basket.innerHTML = "<a href=\"#\"  onclick=\"alert('Δεν υπάρχει διαθέσιμη ποσότητα!');\"><img src=\"images/123124Tosk.png\" width=\"255\" height=\"53\" border=\"0\"></a>"
			var NonSecureServer = document.productform.NonSecureServer.value;
			var OriginalImage = document.productform.SoldOutImage.value;
			var old_src = OriginalImage;
			old_src = old_src.replace(NonSecureServer, "");
			document.getElementById("theImg").src = OriginalImage;
	}

}

function initConfig(ProductId, orPrice, iOurPrice,  QuantityLeft) {
    var orPriceh = document.getElementById("orPrice");
    var iOurPriceh = document.getElementById("iOurPrice");
    var basket = document.getElementById("basket");
    orPriceh.innerHTML = orPrice;
    iOurPriceh.innerHTML = iOurPrice;
    var wishlist = document.getElementById("wishlist");
   var message = document.productform.elements["message"].value; 
   
   // document.productform.elements["RId"].value = ProductId;
    //   if (QuantityLeft != 0)<a href="#" onclick="alert('Please select size and color!');"><img src="images/123124Tosk.png" border="0"/></a>
    basket.innerHTML = "<a href=\"#\"  onclick=\"alert(\'"+message+"\');\"><img src=\"images/123124Tosk.png\" width=\"255\" height=\"53\" border=\"0\"></a>";
    wishlist.innerHTML = "<a href=\"#\"  onclick=\"alert(\'"+message+"\');\"><img src=\"images/123dToWishList.png\" width=\"191\" height=\"39\" border=\"0\"></a>";

}

function ChangeAttr_Old(Value, Id, AttrId, ConfId, AttrNo) {
    var attrId = document.getElementById(AttrId).value;
    var attribute = attrId + '~' + Value;
	var newProducts = new Array();
	var counter = 0;
	var imgg = '';
	var desc = '';	
	
	for(i=0;i<products.length; i++) {
		var word = products[i].Dynamic.split('@');
		for(j=0;j<word.length;j++) {
			if(word[j] == attribute)  {
			    newProducts[counter] = products[i];
				counter++;
				break;
			}
			
		}
	}
	var ProductDynamic = '';
	var cmb = new Array(products[0].Count);
	var type = new Array(products[0].Count);
	for(i=1;i<=products[0].Count;i++) {
		var cmbid = 'GlobalDynamic'+i;
		var cmbAttr = 'Attr'+i;
		var cmbAttrId = document.getElementById(cmbAttr).value;
		cmb[i] = document.getElementById(cmbid);

		
		
		//combo box
		if(i>1)
			ProductDynamic = ProductDynamic +'@';
		ProductDynamic = ProductDynamic + cmbAttrId+'~'+cmb[i].options[cmb[i].selectedIndex].value;
		if(cmbid!=Id ) {
			for(j=1;j<cmb[i].options.length;j++) {
				var option = cmbAttrId + '~'+cmb[i].options[j].value;
				for(k=0;k<newProducts.length;k++) {
					var word = newProducts[k].Dynamic.split('@');
					var flag=0;
					for(l=0;l<word.length;l++) {
						if(word[l]==option) {
							flag=1;
							break;
						}
					}
					if(flag==1)
						break;
				}
				if(flag==0) {
					if(navigator.appName=="Microsoft Internet Explorer") {
						emulateEnabled(cmb[i].options[j], false);
					} else {
						cmb[i].options[j].disabled = true;
					}
				}
				else {
					if(navigator.appName=="Microsoft Internet Explorer") {
						emulateEnabled(cmb[i].options[j], true);
					} else {
						cmb[i].options[j].disabled = false;
					}
				}
			}
		}
	}
	var orPriceh = document.getElementById("orPrice");
	var iOurPriceh = document.getElementById("iOurPrice"); 
	var basket = document.getElementById("basket");
	var wishlist = document.getElementById("wishlist");
	var soldout = document.getElementById('soldout');
	var message = document.productform.elements["message"].value;
	
	for(i=0;i<newProducts.length;i++) {
		if (newProducts[i].Dynamic==ProductDynamic) {
			orPriceh.innerHTML = newProducts[i].Price;
			iOurPriceh.innerHTML = newProducts[i].ourPrice;
			document.productform.elements["RId"].value = newProducts[i].ProductId;
			
			if (newProducts[i].Quantity != 0) {
			    basket.innerHTML = "<a href=\"javascript:document.productform.submit();\"><img src=\"images/123124Tosk.png\" width=\"255\" height=\"53\" border=\"0\"></a>";
			    wishlist.innerHTML = "<a href=\"ViewWishList.aspx?ProductId="+newProducts[i].ProductId+"&action=1\"><img src=\"images/123dToWishList.png\" width=\"191\" height=\"39\" border=\"0\"></a>";
			    var NonSecureServer = document.productform.NonSecureServer.value;
					var OriginalImage = document.productform.OriginalImage.value;
					document.getElementById("theImg").src = OriginalImage;
			} else {
				basket.innerHTML = "<a href=\"#\"  onclick=\"alert('Δεν υπάρχει διαθέσιμη ποσότητα!');\"><img src=\"images/123124Tosk.png\" width=\"255\" height=\"53\" border=\"0\"></a>";
				wishlist.innerHTML = "<a href=\"ViewWishList.aspx?ProductId="+newProducts[i].ProductId+"&action=1\"><img src=\"images/123dToWishList.png\" width=\"191\" height=\"39\" border=\"0\"></a>";
				var NonSecureServer = document.productform.NonSecureServer.value;
				var OriginalImage = document.productform.OriginalImage.value;
				var old_src = OriginalImage;
				old_src = old_src.replace(NonSecureServer, "");
				//document.getElementById("theImg").src = "OpenImageHot.aspx?Type=1&img1=" + old_src;
				var OriginalImage = document.productform.SoldOutImage.value;
				document.getElementById("theImg").src = OriginalImage;
				alert("Δεν υπάρχει διαθέσιμη ποσότητα!");
			}
			break;
		}
	}

	if(i==newProducts.length) {
	//	orPriceh.innerHTML = "Αρχική τιμή: ";
	//	iOurPriceh.innerHTML = "<strong>TIMH MAΣ:</strong>&nbsp;&nbsp;";
		basket.innerHTML = "<a href=\"#\"  onclick=\"alert(\'"+message+"\');\"><img src=\"images/123124Tosk.png\" width=\"255\" height=\"53\" border=\"0\"></a>";
		document.productform.elements["RId"].value = -1;
	}

}

function ChangeAttr(Value, Id, AttrId, ConfId, AttrNo) {
	var attrId = document.getElementById(AttrId).value;
	var attribute = attrId + '~' + Value;
	var newProducts = new Array();
	var counter = 0;
	var imgg = '';
	var desc = '';	
	
	for(i=0;i<products.length; i++) {
		var word = products[i].Dynamic.split('@');
		for(j=0;j<word.length;j++) {
			if(word[j] == attribute)  {
			    newProducts[counter] = products[i];
				counter++;
				break;
			}
			
		}
	}
	var ProductDynamic = '';
	var cmb = new Array(products[0].Count);
	var cmb2 = new Array(products[0].Count);
	var type = new Array(products[0].Count);
	for (i=1;i<=products[0].Count;i++) {
		var cmbid = 'GlobalDynamic'+i;
		var cmbAttr = 'Attr'+i;
		var cmbAttrId = document.getElementById(cmbAttr).value;
		cmb[i] = document.getElementById(cmbid);
		
		
		
		//combo box
		if (i>1) ProductDynamic = ProductDynamic +'@';
		ProductDynamic = ProductDynamic + cmbAttrId+'~'+cmb[i].options[cmb[i].selectedIndex].value;
		
		selValue = cmb[i].options[cmb[i].selectedIndex].value;
		
		if (cmbid!=Id ) {
			cmb2[i] = document.getElementById('h' + cmbid);	
			
			try {
				for (jj = cmb[i].length - 1; jj>=1; jj--) {
					cmb[i].remove(jj);
				}
			}
			catch(ex) {
				;
			}
				
			
			for (j=1; j<cmb2[i].options.length; j++) {
				//alert(cmb2[i].options.length);
				var HasQuantity = 1;
				var option = cmbAttrId + '~' + cmb2[i].options[j].value;
				for (k=0; k<newProducts.length; k++) {
					var word = newProducts[k].Dynamic.split('@');
					var flag=0;
					for(l=0;l<word.length;l++) {
						if(word[l]==option) {
							flag=1;
							if (newProducts[k].Quantity==0) {
								HasQuantity = 0;
							}							
							break;
						}
					}
					if(flag==1)
						break;
				}
				if (flag==0) {
					/*
					if(navigator.appName=="Microsoft Internet Explorer") {
						emulateEnabled(cmb[i].options[j], false);
					} else {
						cmb[i].options[j].disabled = true;
					}
					*/
				}
				else {
					var elOptNew = document.createElement('option');
				  elOptNew.text = cmb2[i].options[j].text;
				  elOptNew.value = cmb2[i].options[j].value;
				  if (HasQuantity==0) {
				  	elOptNew.text = elOptNew.text + ' - Μη Διαθέσιμο';
				  }
				  if (cmb2[i].options[j].value==selValue) {
				  	elOptNew.selected = true;
				  }

					try {
    				cmb[i].add(elOptNew, null); // standards compliant; doesn't work in IE
  				}
  				catch(ex) {
  					cmb[i].add(elOptNew); // IE only
  				}

					/*
					if(navigator.appName=="Microsoft Internet Explorer") {
						emulateEnabled(cmb[i].options[j], true);
					} else {
						cmb[i].options[j].disabled = false;
					}
					*/
				}
			}
		}
	}
	var orPriceh = document.getElementById("orPrice");
	var iOurPriceh = document.getElementById("iOurPrice"); 
	var basket = document.getElementById("basket");
	var wishlist = document.getElementById("wishlist");
	var soldout = document.getElementById('soldout');
	var message = document.productform.elements["message"].value;
	
	for(i=0;i<newProducts.length;i++) {
		if (newProducts[i].Dynamic==ProductDynamic) {
			orPriceh.innerHTML = newProducts[i].Price;
			iOurPriceh.innerHTML = newProducts[i].ourPrice;
			document.productform.elements["RId"].value = newProducts[i].ProductId;
			
			if (newProducts[i].Quantity != 0) {
			    basket.innerHTML = "<a href=\"javascript:document.productform.submit();\"><img src=\"images/123124Tosk.png\" width=\"255\" height=\"53\" border=\"0\"></a>";
			    wishlist.innerHTML = "<a href=\"ViewWishList.aspx?ProductId="+newProducts[i].ProductId+"&action=1\"><img src=\"images/123dToWishList.png\" width=\"191\" height=\"39\" border=\"0\"></a>";
			    var NonSecureServer = document.productform.NonSecureServer.value;
					var OriginalImage = document.productform.OriginalImage.value;
					document.getElementById("theImg").src = OriginalImage;
			} else {
				basket.innerHTML = "<a href=\"#\"  onclick=\"alert('Δεν υπάρχει διαθέσιμη ποσότητα!');\"><img src=\"images/123124Tosk.png\" width=\"255\" height=\"53\" border=\"0\"></a>";
				wishlist.innerHTML = "<a href=\"ViewWishList.aspx?ProductId="+newProducts[i].ProductId+"&action=1\"><img src=\"images/123dToWishList.png\" width=\"191\" height=\"39\" border=\"0\"></a>";
				var NonSecureServer = document.productform.NonSecureServer.value;
				var OriginalImage = document.productform.OriginalImage.value;
				var old_src = OriginalImage;
				old_src = old_src.replace(NonSecureServer, "");
				//document.getElementById("theImg").src = "OpenImageHot.aspx?Type=1&img1=" + old_src;
				var OriginalImage = document.productform.SoldOutImage.value;
				document.getElementById("theImg").src = OriginalImage;
				alert("Δεν υπάρχει διαθέσιμη ποσότητα!");
			}
			break;
		}
	}

	if(i==newProducts.length) {
	//	orPriceh.innerHTML = "Αρχική τιμή: ";
	//	iOurPriceh.innerHTML = "<strong>TIMH MAΣ:</strong>&nbsp;&nbsp;";
		basket.innerHTML = "<a href=\"#\"  onclick=\"alert(\'"+message+"\');\"><img src=\"images/123124Tosk.png\" width=\"255\" height=\"53\" border=\"0\"></a>";
		document.productform.elements["RId"].value = -1;
	}

}

function emulateEnabled(option, enable) {
	if(enable)
		 option.style.color = "menutext";
	else 
		option.style.color = "graytext";
}