﻿var host = window.location.hostname;


function $ELE( id ) {
	return document.getElementById(id);
}


// Create client id cookie
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}


function Set_Cookie( name, value, expires, path, domain, secure )
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{ expires = expires * 1000 * 60 * 60 * 24; }
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) + 
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function S4() {
	return (((1+Math.random())*0x10000)|0).toString(16).substring(1) }

function ClientIDGenerate()
{
	return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()).toUpperCase()
}


function windowOpen(txtBox, make, partnumber) 
{	
	var txtQty = $ELE(txtBox);
	
	var imgs = document.images;
	
		
	if ( !Get_Cookie( 'ClientID' ) )
	{
		Set_Cookie( 'ClientID', ClientIDGenerate(), '1', '/', '', '' );
	} 
			
	var clientID = Get_Cookie('ClientID');
	
	for ( var i = 0 ; i < imgs.length ; ++i )
	{
		var img = imgs[i];
		if ( img.className == "itemImage" )
		{
			if ( navigator.appName.indexOf("Internet Explorer") != -1 )
				img.style.zIndex = -1;
		}
	}
	
	// validation
	if ( !txtQty.value.match(/[^A-z]/) && txtQty.value != "" ) {
		alert("Please provide a quantity.");
		txtQty.focus();
		return;
	}
	
	// set qty value
	var qty = txtQty.value != "" && txtQty.value != null ? txtQty.value : 1;

	var iframeUrl = 'http://www.delvingware.com/QuoteBasket.aspx?partnumber=' + partnumber + '&make=' + make + '&qty=' + qty + '&source=' + host + '&clientid=' + clientID;


	dhtmlwindow.open('Quote Request','iframe',iframeUrl,'Request Quote', 'width=625px,height=400px,center=1,resize=1');
	
	
	//asyncWnd.style.display = "inline";		
	//$ELE("reqIframe").setAttribute("src", iframeUrl);
	
	// Set focus
	var txt = $ELE("dwQuoteBasket_txtFirstName");
	if(txt != null)
		txt.focus();

} // end


