// JavaScript Document

// GLOBAL VARS
// TO be used between functions
var globalWidgetVar = 100


function isInteger(str)
{
 return (str.search(/^[0-9]*$/) != -1);
}

function isMoney(str)
{
 return (str.search(/^[0-9]*(\.[0-9]{1,2})?$/) != -1);
}

function isPeriod(str)
{
 if(str.charAt(str.length - 2) == 0) {
   return (str.search(/^2[0-9]{3}[0][0-9]$/) != -1);}
 else {
   return (str.search(/^2[0-9]{3}[1][012]$/) != -1);}
}

function isEmailAddress(str)
{
   return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str);
}  

function isBlank(str){
	for (var i = 0; i <str.length; i++){
		var c = str.charAt(i);
	if ((c != ' ') && (c != '\n') && (c !='')) return false;
	}
	return true
}

function isDateShort(str)
 {
 if(str.search(/^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{1,4}$/) != -1)
  {
    var elements = str.split("/");
    if(elements.length == 3) 
    {
     var eDate = new Date(parseInt(elements[2], 10), parseInt(elements[1], 10) - 1, parseInt(elements[0], 10));
      if(!isNaN(eDate) && ((eDate.getMonth() + 1) == (elements[1] - 0))) 
      {
        return true;
      }
    }    
  }
  return false;
}  

function isDateFull(str)
{
 return (str.search(/^\d{2}(\-|\/|\.)\d{2}\1\d{4}$/) != -1);
} 

function getElement(id)
// Sorts out getElementByID etc across browsers
{
  if(document.getElementById) return document.getElementById(id);
  return document.all[id];
}




function hide(id)
// Hides element id
{
  var element = getElement(id);
  if(element)
  {
    with(element)
    {
      style.visibility = "hidden";
      style.height = "0px";
      style.display = "none";
    }
  }
}
function show(id)
// Shows element id
{
  var element = getElement(id);
  if(element)
  {
    with(element)
    {
      style.visibility = "visible";
      style.height = "auto";
      //style.display = "inline";
	  style.display = "block";
    }
  }
}
function toggleShowHide(id)
// Shows element id
{
  var element = getElement(id);

	if (element.style.display != "none") {
		hide(id)
	}
	else {
		show(id)
	}
}
function visible(id)
// Shows element id
{
  var element = getElement(id);
  if(element)
  {
    with(element)
    {
      style.visibility = "visible";
    }
  }
}

function invisible(id)
// Hides element id
{
  var element = getElement(id);
  if(element)
  {
    with(element)
    {
      style.visibility = "hidden";
    }
  }
}

function disable(id)
//disables element id
{
 var element = getElement(id);
if(element)
 {
  with(element)
  {
	disabled = true
  }
 }
}


function enable(id)
//enables element id
{
 var element = getElement(id);
 if(element)
 {
  with(element)
  {
	disabled = false
  }
 }
}

function showFullDate(date,element)
//Either include validation.js or have the date validation functions present
{
 if(isDateShort(date))
 {
 var currYear = new Date()
 currYear = new String(currYear.getFullYear())
 var tempDate = date.split("/")
 var tempDay = tempDate[0]
 var tempMonth = tempDate[1]
 var tempYear = tempDate[2]
 if(tempDay.length == 1)
 {tempDay = "0"+tempDay}
 if(tempMonth.length == 1)
 {tempMonth = "0"+tempMonth}
 if(tempYear.length == 1)
 {tempYear = currYear.substring(0,3)+tempYear}
 if(tempYear.length == 2)
 {tempYear = currYear.substring(0,2)+tempYear}
 tempDate = tempDay+"/"+tempMonth+"/"+tempYear
 document.getElementById(element).value = tempDate	
 } 
}

function makeWindow(url,name,width,height)
{
	url=encodeURI(url);
	window.open(url,name,"menubar=0, width="+width+",height="+height+",location=0, toolbar=0, resizeable=0, scrollbars=1")
}

 

<!-- Begin Capture screen size to cookies!
function getScreenSize() {
var xy = navigator.appVersion; 
xz = xy.substring(0,4); 
document.cookie = "ScreenWidth=" + screen.width
document.cookie = "ScreenHeight=" + screen.height
}
// End --> 



function checkInputLength(elem,length,restriction)
{
	if(length > restriction){
		alert("Sorry you cannot enter more than " + restriction + " characters in this field.\nYour text will now be truncated")
		getElement(elem).value = getElement(elem).value.substring(0,restriction)
	}
}

function calculatorLabelValue(id, rdObj)
{
	var rbtn = rdObj.getElementsByTagName("INPUT");
    for (var i = 0; i < rbtn.length; i++) 
	{
        if (rbtn[i].checked) {
            var value = rbtn[i].value;            
        }
    }
	getElement(id).innerHTML = value;	
	getElement('lblbricksize').value = value;
}
function calculateResults()
{
	alert(getElement('txtLength').value)
}
function getBrickImageDetails(productCode)
{
	
	$.ajax({
		    type: "POST",
			url: '../../../../BrickData.asmx/getProductDetails',
		    data: ({productCode:productCode}),
		    dataType:"xml",
		    success: function(xml){	
			 var brickData = xml.getElementsByTagName("xs:element") 
			 var attributeName;
			 var attributeLabel;
			 var labelID;
			 var attributeValue;
			 $('#ProductCodeValue').text(productCode);
			 for( var i =0;i < brickData.length; i++)
			 {
				attributeName = brickData[i].getAttribute("name");
				attributeValue = brickData[i].getAttribute("default");
				if( attributeName == "ProductName" )
				{
					$('#ProductName').text(attributeValue);
				}
				else if( attributeName == "imageName")
				{
					$('#ProductImage').attr('src',attributeValue);
				}
				else if( attributeName.substring(0, attributeName.length - 1 ) == "attributeValue")
				{
						attributeLabel = 'attributeName' + attributeName.substring(attributeName.length - 1, attributeName.length );
						$('#'+attributeLabel).removeClass('hiddenBox');
						$('#'+attributeLabel).addClass('blockText');
						$('#'+attributeName).text(attributeValue);	
						if(attributeValue == '')
						{
							$('#'+attributeLabel).removeClass('floL');
							$('#'+attributeLabel).addClass('hiddenBox'); 						
						}
				}
			 }
			 brickImagePopUp();			 
			}
			
			});
}

function brickImagePopUp()
{
	$('#MessageDiv').addClass('hiddenBox'); 
	$('#divDetails').removeClass('hiddenBox');
	$('#buttonDiv').removeClass('hiddenBox');
	
	$('#dialog').dialog({ autoOpen: false });
	$('#dialog').dialog('option', 'width', 350);
	$('#dialog').dialog('option', 'height', 400);
	$('#dialog').dialog('open');	
}

function addBrickToBasket()
{
	var productCode = $('#ProductCodeValue').text();	
	$.ajax({
		    type: "POST",
			url: '../../../../BrickData.asmx/setBrickBasket',
		    data: ({productCode:productCode}),
		    dataType:"xml",
		    success: function(xml){			
				$('#buttonDiv').addClass('hiddenBox');
				$('#divDetails').addClass('hiddenBox'); 
				$('#MessageDiv').removeClass('hiddenBox');			
				}
				
			});
	
}
function addProductToBasket(productCode)
{
	$.ajax({
		    type: "POST",
			url: '../../../../BrickData.asmx/setBrickBasket',
		    data: ({productCode:productCode}),
		    dataType:"xml",
		    success: function(xml){			
			
				$('#buttonDiv').addClass('hiddenBox');
				$('#divDetails').addClass('hiddenBox'); 
				$('#MessageDiv').removeClass('hiddenBox');	
				window.location = "./Brick-Basket";
				}
				
			});
}
	
function openProductDetails()
{
		var productCode = $('#ProductCodeValue').text();
		$.ajax({
		    type: "POST",
			url: '../../../../BrickData.asmx/setProductCode',
		    data: ({productCode:productCode}),
		    dataType:"xml",
		    success: function(xml){
			    	$('#dialog').dialog('close');
					window.location = "./Product-Details";	
			}
			});
	
	
}
function openLibrary()
{
		window.location = "./Brick-Samples";		
}
function openMatcher()
{
		window.location = "./Brick-Matcher";		
}
function openBasket()
{
		$('#dialog').dialog('close');
		window.location = "./Brick-Basket";		
}
function showImage( itemID )
{
	window.open("../../../../ShowPicture.aspx?PictureID=" + itemID );
	return false;
}
function openCalculator()
{
	window.location = "./Brick-Calculator";
}

  // -->

