function isValidInputNumberInteger(s)
{
  if (s == "") return;
  for (i = 0 ; i < s.length ; i++) {
    if ((s.charAt(i) < '0') || (s.charAt(i) > '9')) return false
  }
  return true;
}

function CheckInputInteger(textBox)
{
	if(false == isValidInputNumberInteger(textBox.value))
	{
		textBox.value = textBox.value.substring(0, textBox.value.length - 1);
	}
}

var DMhttpObjInnerHTML;
function DMGetXmlHttpObject()
{
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

function DMSendEmailOnUserHtml(url)
{
	DMhttpObjInnerHTML=DMGetXmlHttpObject();
	DMhttpObjInnerHTML.onreadystatechange=DMSendUserEmailstateChangedInnerHtml;
	DMhttpObjInnerHTML.open("GET",url,true);
	DMhttpObjInnerHTML.send(null);
}

function DMSendUserEmailstateChangedInnerHtml()
{
	if (DMhttpObjInnerHTML.readyState==4 || DMhttpObjInnerHTML.readyState=="complete")
	{
	  //alert(DMhttpObjInnerHTML.responseText);
	}
}


	function Imagelightup(imageobject, opacity)
	{
		if (navigator.appName.indexOf("Netscape")!=-1 &&parseInt(navigator.appVersion)>=5)
		 imageobject.style.MozOpacity=opacity/100;
		else if (navigator.appName.indexOf("Microsoft")!= -1 &&parseInt(navigator.appVersion)>=4)
		 imageobject.filters.alpha.opacity=opacity;
	}
	
	function toggleImage(imageName,imgNameSRC)
	{
		useImage =imgNameSRC;
		if (document.all){
			myImage = document.images[imageName];
			if(document.images){
			// Check to see whether you are using a name, number, or object
				myImage.src = useImage;
			}
			return false;
		}else if (document.getElementById){
	
			myImage = document.images[imageName];
			if(document.images){
			// Check to see whether you are using a name, number, or object
				myImage.src = useImage;
			}			
			return false;
		}		
	}
	
	function goToLink(link)
	{
		if(link !='')
		{
			window.location.href =link;
		}
	}
	
/*Main for the shop*/
	var DMProdAddhttpObjInnerHTML;
	var DMProdRemovehttpObjInnerHTML;
	var objBestAmt = 0;
	var currentProductID ="";
	var addlink ="/Default.aspx?&cartcmd=add&productid=";
	var removelink  ="/Default.aspx?CartCmd=DelOrderLine&key=";

	function DMAddtoCart(bestillingVal)
	{
		currentProductID = bestillingVal;
		if(currentProductID !="")
		{
			var url ="";
			var isEmpty = true;
			if(null != document.getElementById('CF_prod_'+currentProductID+'_ORDERID'))
			{
				var akeyid= document.getElementById('CF_prod_'+currentProductID+'_ORDERID').value;
				url=removelink+akeyid+"&sid="+Math.random(); 
				isEmpty = false;
				DMRemoveProductRequest(url);
			}
			if(isEmpty == true)
			{
				DMAddProductTocart();
			}
		}
	}
	
	function DMAddProductTocart()
	{
		if(currentProductID !="")
		{
			if(null !=document.getElementById('CF_amount_'+currentProductID))
			{
				try
				{
					objBestAmt = parseInt(document.getElementById('CF_amount_'+currentProductID).value);
					if(objBestAmt > 0)
					{
						url=addlink+currentProductID+"&Quantity="+ objBestAmt+"&sid="+Math.random();
						DMAddProductRequest(encodeURI(url));
					}else
					{
						window.location.reload(true);
					}
			  }catch(err)
			  {
			    
			  }				
			}
		}
	}
	
  function FillCartValues()
	{
	  var cartInputValues=document.getElementsByName("CF_cart_products");
	  var theeleId = "";
		for(i=0;i<cartInputValues.length;i++)
		{
			theeleId = cartInputValues[i].id.substring(8);
			if((null !=document.getElementById('CF_amount_'+theeleId)) && (null != document.getElementById('CF_prod_'+theeleId)) )
			{
				document.getElementById('CF_amount_'+theeleId).value  = document.getElementById('CF_prod_'+theeleId).value;
			}	
			if((null !=document.getElementById('CF_prod_hid_id_'+theeleId)) && (null != document.getElementById('CF_prod_'+theeleId)) )
			{
				document.getElementById('CF_prod_hid_id_'+theeleId).value = document.getElementById('CF_prod_'+theeleId).value;
			}	
		}
	}

	function checkNumber(textBox,hidId,theId,weight)
	{
	   var ValidChars = "0123456789";
	   var Char;
	   var allowed = "";

	   if(textBox.value != hidId.value)
		 {
	     for (i = 0; i < textBox.value.length; i++) 
	     { 
	      Char = textBox.value.charAt(i); 
	      if (ValidChars.indexOf(Char) != -1) 
	      {
	      	allowed = allowed + Char;
	      }
	     }
	     textBox.value = allowed;
	     hidId.value = allowed;
	     DMAddtoCart(theId);
	  }
	}	
	
	function DMAddProductRequest(url)
	{
		DMProdAddhttpObjInnerHTML=DMGetXmlHttpObject();
		DMProdAddhttpObjInnerHTML.open("GET",url,true);
		DMProdAddhttpObjInnerHTML.onreadystatechange=DMAddProductstateChangedInnerHtml
		DMProdAddhttpObjInnerHTML.send(null);
	}

  function DMAddProductstateChangedInnerHtml()
  {
    if (DMProdAddhttpObjInnerHTML.readyState==4 || DMProdAddhttpObjInnerHTML.readyState=="complete")
    {
    	currentProductID ="";
			//window.location.reload(true);
			window.location.href = window.location.href;
    }
  }
	function DMRemoveProductRequest(url)
	{
		DMProdRemovehttpObjInnerHTML=DMGetXmlHttpObject();
		DMProdRemovehttpObjInnerHTML.open("GET",url,true);
		DMProdRemovehttpObjInnerHTML.onreadystatechange=DMProductRemovestateChangedInnerHtml
		DMProdRemovehttpObjInnerHTML.send(null);
	}
	
  function DMProductRemovestateChangedInnerHtml()
  {
    if (DMProdRemovehttpObjInnerHTML.readyState==4 || DMProdRemovehttpObjInnerHTML.readyState=="complete")
    {
			DMAddProductTocart();
    }
  }


	function generateDropDown(ProoductID,weight)
	{
		var output ="";
		var cov = 1;
		try
		{
			cov = parseInt(weight);
	  }catch(err)
	  {
	    cov = 1;
	  }

	  if(cov > 1)
	  {
	  	var incr = cov;
	  	output ='<select name="Installatorlogin_product_list" id="CF_amount_'+ProoductID+'" class="Elworks_product_list">';
			output +='<option value=""> </option>';
			for(var i=1;i <= 20; ++i)
			{
				output +='<option value="'+cov+'">'+cov+'</option>';
				cov += incr;
			}
	  	output +='</select>';
		}else
		{
			output ='<input name="Installatorlogin_product_list" type="text" value="" id="CF_amount_'+ProoductID+'" class="Elworks_product_list" onkeyup="CheckInputInteger(this);" style="text-align:center;">';
		}
		document.write(output);		
	}

	function getElementsByClassName(classname)
	{
		node = document.getElementsByTagName("body")[0];
		var a = [];
		var re = new RegExp('\\b' + classname + '\\b');
		var els = node.getElementsByTagName("*");
		for(var i=0,j=els.length; i<j; i++)
		{
			if(re.test(els[i].className))
			{
				a.push(els[i]);
			}
		}
	  return a;
	}
	
	function CheckUserLogedIn()
	{
		var objects = getElementsByClassName('Elworks_ProductBuy');
		if(typeof ExtranetUserName != "undefined")
		{
			for(i=0;i<objects.length;i++)
			{
				theeleId = objects[i].id;
				if((typeof theeleId != "undefined") && (theeleId !=""))
				{
					if(ExtranetUserName == "")
					{
						document.getElementById(theeleId).style.visibility = 'hidden';
						document.getElementById(theeleId).style.display = 'none';
					}else
					{
						document.getElementById(theeleId).style.visibility = 'visible';
						document.getElementById(theeleId).style.display = 'block';
					}
					
				}
			}
		}
			

		/*
		if(null != document.getElementById('Elworks_Product_Hide'))
		{
			alert('hide is there');
			if(ExtranetUserName == "")
			{
				alert('emptyname');
				document.getElementById('Elworks_Product_Hide').style.visibility = 'hidden';
				document.getElementById('Elworks_Product_Hide').style.display = 'none';
			}else
			{
				alert('full name');
				document.getElementById('Elworks_Product_Hide').style.visibility = 'visible'
				document.getElementById('Elworks_Product_Hide').style.display = 'block';
			}
		}
		*/
	}
