function ValidateSearch() {
	var frm = document.forms["fmSearch"];
	if (!frm) return false;
	if (frm.Keywords.value.length > 2) {
		frm.Action.value = "search";
		return true;
	} else {
		return false;
	}
}

function Search() {
	var frm = document.forms["fmSearch"];
	if (!frm) return false;
	if (ValidateSearch()) frm.submit();
}

function SearchByPrice(min, max) {
	var frm = document.forms["fmSearchByPrice"];
	if (!frm) return false;
	frm.MinPriceLevel.value = min;
	frm.MaxPriceLevel.value = max;
	frm.submit()
}

function Added() {
  alert('Your item has been added to your shopping cart');
}

function AddProductToCart(id, sURL) {
	var frm = document.forms["fmProduct"];
	if (frm) {
		if (ValidateQty()) {
			frm.Action.value = 'add';
			frm.submit();
		}
	} else {
		if (id) {
			var sURL = sURL + "?Action=add&ProdID=" + id;
			location.href = sURL;
		}
	}
}

function chat(bGuest) {
	var sURL = 'chat/chat.asp';
	if (bGuest)
		openWindow(sURL, '', 410, 190, "status=no,toolbar=no,resizable=yes,scrollbars=no,menubar=no");
	else
		openWindow(sURL, '', 500, 400, "status=no,toolbar=no,resizable=yes,scrollbars=no,menubar=no");				
}

function changeEmail(el) {
	if(el.name == 'Contact_Email') {
		var userName = find_object('Account_UserName');
		if (userName) {
			userName.value = el.value;
		}
	}
}

function ApplyCurrency() {
	var frm = document.forms["fmCurrency"];
	if (!frm) return false;
	frm.currency.value="currency";
	frm.submit();
}

function SwitchLanguage(sLanguage) {
	var frm = document.forms["fmLanguage"];
	if (!frm) return false;
	frm.language.value = sLanguage;
	frm.submit();
}

//--- Ajax implementation---//

function loadStates(countryID, prefix) {
	if (find_object('ExpressCheckout')) {
		recalculateExpressCheckout(countryID, prefix);
	}
	if (countryID > 0) {
		var progressDiv = find_object('progress_div');
		if (progressDiv != null) progressDiv.display();
		if (prefix == "undefined") prefix = "";
		statePrefix = prefix + "Address_StateID";
		var sel = document.getElementById(statePrefix); //Object of <select> with id="{$prefix}Address_StateID"
		var xmlHttp=GetXmlHttpObject();
		if (xmlHttp != null) {
			while (sel.length > 0) {
				sel.options[0] = null;
			}
			sel.disabled = true;
		} else{
			sel.form.action=location;
			Refresh();
			return;
		}
		var url = "../ajax_contact.asp?CountryID=" + countryID + "&Prefix=" + prefix;
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				try {
					eval(xmlHttp.responseText);
					var progressDiv = find_object('progress_div');
					if(progressDiv) progressDiv.hide();
				}
				catch(e){
				}
				finally{
					var progressDiv = find_object('progress_div');
					if(progressDiv) progressDiv.hide();
				};
			}
		}
		if (window.XMLHttpRequest) {
			xmlHttp.open("GET", url, true);
		}
		else if (window.ActiveXObject) {
			xmlHttp.open("GET", url, false);
		}
		xmlHttp.send(null);
	}
}

function loadAddressBook(addrBookID, prefix, clientID) {
	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp) {
		if (addrBookID != 'empty') {
			var progressDiv = find_object('progress_div');
			if(progressDiv) progressDiv.display();
			//New address
			if (addrBookID == -1) {
				setValue(prefix + 'Contact_FirstName', '');
				setValue(prefix + 'Contact_LastName', '');
				setValue(prefix + 'Contact_Company', '');
				setValue(prefix + 'Address_Address' , '');
				setValue(prefix + 'Address_Address2', '');
				setValue(prefix + 'Address_City', '');
				setValue(prefix + 'Address_PostalCode', '');
				setValue(prefix + 'Address_CountryID', '');
				setValue(prefix + 'Contact_Phone', '');
				setValue(prefix + 'Contact_Email', '');

				var sel = document.getElementById(prefix+'Address_StateID');
				while (sel.length > 0) {
					sel.options[0] = null;
				}
				if (window.ActiveXObject) {
					var td1 = document.getElementById(prefix + 'Address_StateID' + '_1');
					var td2 = document.getElementById(prefix + 'Address_StateID' + '_2');
					sel.disabled = true;
					td1.style.display='none';
					td2.style.display='none';
				}
			}
			//Copy Billing info to Shipping
			if (addrBookID == 0) {
				document.getElementById(prefix + 'AddressBookItem').value = 'empty';
				setValue(prefix + 'Contact_FirstName', document.getElementById('Contact_FirstName').value);
				setValue(prefix + 'Contact_LastName', document.getElementById('Contact_LastName').value);
				setValue(prefix + 'Contact_Company', document.getElementById('Contact_Company').value);
				setValue(prefix + 'Address_Address', document.getElementById('Address_Address').value);
				setValue(prefix + 'Address_Address2', document.getElementById('Address_Address2').value);
				setValue(prefix + 'Address_City', document.getElementById('Address_City').value);
				setValue(prefix + 'Address_PostalCode', document.getElementById('Address_PostalCode').value);
				setValue(prefix + 'Address_CountryID', document.getElementById('Address_CountryID').value);
				setValue(prefix + 'Contact_Phone', document.getElementById('Contact_Phone').value);
				setValue(prefix + 'Contact_Email', document.getElementById('Contact_Email').value);

				var sel = document.getElementById(prefix+'Address_StateID');
				while (sel.length > 0) {
					sel.options[0] = null;
				}
				//if (window.ActiveXObject){
					var td1 = document.getElementById(prefix + 'Address_StateID' + '_1');
					var td2 = document.getElementById(prefix + 'Address_StateID' + '_2');
					sel.disabled = true;
					td1.style.display = 'none';
					td2.style.display = 'none';
				//}
				if (document.getElementById('Address_StateID').value > 0) {
					loadStates(document.getElementById('Address_CountryID').value,prefix);
					document.getElementById(prefix + 'Address_StateID').value = document.getElementById('Address_StateID').value;
				}
			}

			//Load Address from Address Book
			if (addrBookID > 0) {
				var url = "../ajax_contact.asp?AddressBookID=" + addrBookID + "&Prefix=" + prefix + "&ClientID=" + clientID;
				xmlHttp.onreadystatechange = function() {
					if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
						eval(xmlHttp.responseText);
						var progressDiv = find_object('progress_div');
						if(progressDiv != null) progressDiv.hide();
						var el;
						if(el=document.getElementById('tdRecalculate')) el.style.display='block';
					}
				}
				if (window.XMLHttpRequest) {
					xmlHttp.open("GET", url, true);
				}
				else if (window.ActiveXObject) {
					xmlHttp.open("GET", url, false);
				}
				xmlHttp.send(null);
				loadPayments();
			}
		}
	} else {
		//Copy(this,prefix); //For Mozilla Firefox using old conception
	}
}

function shipDestinationChanged(el) {
	changeDiv('shippinginfo', ('shipaddress' == el.value)?'block':'none');
	var prefix = ('shipaddress' == el.value)?'ShippingInfo_':'';
	if (document.getElementById('ExpressCheckout')) {
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp != null) {
			recalculateExpressCheckout(find_object(prefix + 'Address_CountryID').value, prefix);
		} else {
			el.form.Action.value='recalculate';
			el.form.submit();
		}
	}
}

function loadPayments() {
	var xmlHttp = GetXmlHttpObject();
	var settlePayment = false;
	if (xmlHttp) {
		var progressDiv = find_object('progress_div');
		if(progressDiv != null) progressDiv.display();
		var form = document.forms["fmCheckout"];
		if(!form) {
			form = document.forms["fmSettlePayment"];
			if(!form) {
				if(progressDiv != null) progressDiv.hide();
				return;
			}
			settlePayment = true;
		}
		var tmp = form.Action.value;
		form.Action.value = 'ajax-payment-method';
		var querystring = getFormElements(form);
		form.Action.value = tmp;

		var url = ((settlePayment)?'settlepayment.asp?':'default.asp?');
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				try {
					var sResponse = xmlHttp.responseText;
					if(sResponse != '') {
						var divPaymentMethodContainer = find_object('divPaymentMethodContainer');
						if(divPaymentMethodContainer != null) divPaymentMethodContainer.innerHTML = sResponse;
						var progressDiv = find_object('progress_div');
						if(progressDiv) progressDiv.hide();
					}
				}
				catch(e){}
				finally {
					var progressDiv = find_object('progress_div');
					if(progressDiv) progressDiv.hide();
				};
			}
		}
		if (window.XMLHttpRequest) {
			xmlHttp.open("POST", url, true);
		} else if (window.ActiveXObject) {
			xmlHttp.open("POST", url, false);
		}
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(querystring);
	} else {
		Refresh();
	}
}

function refreshOrder(el, recalculate) {
	if(document.getElementById('fmCheckout') == null) return;

	// in case there is no payment section and order total can change
	// call recalculate instead of refresh
	if (el.form.PaymentMethodID == null) {
		recalculateOrder();
		return;
	}

	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp != null) {
		var progressDiv = find_object('progress_div');
		if(progressDiv != null) progressDiv.display();
		var prefix = '';
		if('shipaddress' == document.getElementById('ShipDestination').value) {
			prefix = 'ShippingInfo_';
		}
		var elState = document.getElementById(prefix + 'Address_StateID');
		var lStateID='';
		if(elState != null) {
			lStateID = elState.value;
		}

		var elPostalCode = document.getElementById(prefix + 'Address_PostalCode');
		var sPostalCode='';
		if(sPostalCode != null) {
			sPostalCode = elPostalCode.value;
		}

		var elShipping = document.getElementById('ShippingMethodID');
		var lShippingMethodID='';
		if(elShipping != null) {
			lShippingMethodID = elShipping.value;
			elShipping.disabled = true;
		}

		var elPayment = document.getElementById('PaymentMethodID');
		var lPaymentMethodID='';
		if(elPayment != null) {
			lPaymentMethodID = elPayment.value;
		}

		var elOrder = document.getElementById('OrderID');
		var sOrderID='';
		if(elOrder != null) {
			sOrderID = elOrder.value;
		}

		var url = "../ajax_contact.asp?CurrentOrderID=" + sOrderID + "&CurrentShippingMethodID=" + lShippingMethodID + "&StateID=" + lStateID + "&Prefix=" + prefix + "&PostalCode=" + sPostalCode + "&PaymentMethodID=" + lPaymentMethodID;
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				try {
					eval(xmlHttp.responseText);
					var progressDiv = find_object('progress_div');
					if(progressDiv) progressDiv.hide();
				}
				catch(e){}
				finally {
					var progressDiv = find_object('progress_div');
					if(progressDiv) progressDiv.hide();
				};
			}
		};
		if (window.XMLHttpRequest) {
			xmlHttp.open("GET", url, true);
		} else if (window.ActiveXObject) {
			xmlHttp.open("GET", url, false);
		}
		xmlHttp.send(null);
	} else {
		if('undefined' == typeof(recalculate)) {
			Refresh();
		} else {
			el.form.Action.value='recalculate';
			el.form.submit();
		}
	}
}

function recalculateOrder() {
	if(null == document.getElementById('fmCheckout')) return;
	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp != null) {
		var progressDiv = find_object('progress_div');
		if(progressDiv != null) progressDiv.display();
		var form = document.forms["fmCheckout"];
		var tmp = form.Action.value;
		form.Action.value = 'ajax-recalculate';
		var querystring = getFormElements(form);
		form.Action.value = tmp;
		var url = 'default.asp';
		var sel = document.getElementById('ShippingMethodID');
		while (sel.length > 0) {
			sel.options[0] = null;
		}
		sel.disabled = true;
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				try {
					sel.disabled = false;
					eval(xmlHttp.responseText);
					var progressDiv = find_object('progress_div');
					if(progressDiv) progressDiv.hide();
				}
				catch(e) {}
				finally {
					var progressDiv = find_object('progress_div');
					if(progressDiv) progressDiv.hide();
				};
			}
		}
		if (window.XMLHttpRequest) {
			xmlHttp.open("POST", url, true);
		} else if (window.ActiveXObject) {
			xmlHttp.open("POST", url, false);
		}
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(querystring);
	} else {
		var el = find_object('tdRecalculate');
		if(el != null) el.style.display='block';
	}
}

function setValue(elementID, elementValue) {
	var el = document.getElementById(elementID);
	if (el != null) {
		if (el.type == "checkbox") {
			if (elementValue == 1) {
				el.checked = true;
			} else {
				el.checked = false;
			}
		} else {
			el.value = elementValue;
		}
	} else {
		// try to find in forms
		for(i=0;i < document.forms.length; i++) {
			el = document.forms[i].elements[elementID];
			if(el != null) {
				if (el.type == "checkbox") {
					if (elementValue == 1) {
						el.checked = true;
					} else {
						el.checked = false;
					}
				} else {
					el.value = elementValue;
					return;
				}
			}
		}
	}
}

function recalculateExpressCheckout(countryID, prefix) {
	recalculateOrder();
}

function accumulateQueryString(queryString, newValues) {
	if(queryString == "") {
		queryString = newValues; 
	} else {
		queryString = queryString + "&" + newValues;
	}
	return queryString;
}
    
function getFormElements(form) {
	var querystring = '';
	var formElements = new Array();
	if (form != null) {
		if (typeof form == "string") {
			var el = document.getElementById(form);
			if (el != null) {
				formElements = el.elements;
			}
		} else {
			formElements = form.elements;
		}
	}
	var values = toQueryString(formElements);
	return accumulateQueryString(querystring, values);
}

function openAddressBookItem(id, customerID, paymentType) {
	var xmlHttp=GetXmlHttpObject();

	if ((paymentType != 'card') && (paymentType != 'check')) {
		paymentType = '';
	}
	if (xmlHttp && (customerID.length > 0) && (id > 0)) {
		var progressDiv = find_object('progress_div');
		if(progressDiv) progressDiv.display();
		var fmObject = document.forms["fmObject"];
		fmObject.ID.value = id.toString();
		fmObject.Action.value = 'update';

		setValue('Contact_FirstName', '');
		setValue('Contact_LastName', '');
		setValue('Contact_Company', '');
		setValue('Address_Address', '');
		setValue('Address_Address2', '');
		setValue('Address_City', '');
		setValue('Address_PostalCode', '');
		setValue('Address_CountryID', '');
		setValue('Contact_Phone', '');
		setValue('Contact_Email', '');


		setValue('CashAssets_Name', '');
		setValue('Type', '');
		setValue('Number', '');
		setValue('Name_cardholder', '');
		setValue('ExpMonth', '1');
		setValue('ExpYear', '2007');

		setValue('Bank', '');
		setValue('AccountNumber', '');
		setValue('RoutingNumber', '');
		setValue('BankAddress', '');
		setValue('BankPhone', '');
		setValue('FederalID', '');   

		var sel = document.getElementById('Address_StateID');
		while (sel.length > 0) {
			sel.options[0] = null;
		}
		if (window.ActiveXObject) {
			var td1 = document.getElementById('Address_StateID');
			sel.disabled = true;
			td1.style.display='none';
		}   

		var url = "../../ajax_contact.asp?AddressBookItemID=" + id + "&ClientID=" + customerID + "&PaymentType=" + paymentType;
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				eval(xmlHttp.responseText);
				var progressDiv = find_object('progress_div');
				if(progressDiv != null) progressDiv.hide();
			} 
		}
		if (window.XMLHttpRequest) {
			xmlHttp.open("GET", url, true);
		} else if (window.ActiveXObject) {
			xmlHttp.open("GET",url,false);
		}
		xmlHttp.send(null);
	} else {
		window.location = location.pathname + "?ID="+id;
	}
}

function openTicket(id, customerID, message) {
	var xmlHttp=GetXmlHttpObject();

	if (xmlHttp && (customerID.length > 0) && (id > 0)) {
		var container = document.getElementById('message_container');
		if(container == null) return;

		var progressDiv = find_object('progress_div');
		if(progressDiv) progressDiv.display();

		var url = "../../ajax_contact.asp?TicketID=" + id + "&ClientID=" + customerID + "&Message=" + message
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				container.innerHTML = xmlHttp.responseText;
				var progressDiv = find_object('progress_div');
				if(progressDiv != null) progressDiv.hide();
			} 
		}
		if (window.XMLHttpRequest) {
			xmlHttp.open("GET", url, true);
		} else if (window.ActiveXObject) {
			xmlHttp.open("GET",url,false);
		}
		xmlHttp.send(null);
	} else {
		window.location = location.pathname + "?ID="+id;
	}
}














































/*
function loadShippingMethods(countryID, prefix, useShipping)
{
  var xmlHttp = GetXmlHttpObject();
  if (xmlHttp != null)
  {
    var stateID='', postalCode='';
    var sel = document.getElementById('ShippingMethodID');
        if(sel != null) {
            //sel.disabled = true;
      while (sel.length > 0) {
        sel.options[0] = null;
      }
    }
    sel = find_object(prefix + 'StateID');
        if(sel != null) stateID = sel.value;
        sel = find_object(prefix + 'PostalCode');
        if(sel != null) postalCode = sel.value;
        
    var url = "ajax_contact.asp?OrderID="+sOrderID+"&CountryID="+countryID+"&GroupID="+sGroupID+"&Prefix="+prefix+"&UseShipping="+useShipping+"&StateID="+stateID+"&PostalCode="+postalCode;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
            try{
                   eval(xmlHttp.responseText)
                }
                catch(e){};
            }
    };
    if (window.XMLHttpRequest){
            xmlHttp.open("GET",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("GET",url,false);
        }
    xmlHttp.send(null);
  }
  else
  {
    Refresh();
  }
}
*/

// update billinginfo and promotes order to open status
function updateBillingInfo(form){
  if(null == document.getElementById("ExpressCheckout"))
      return;
      
  if("undefined" == typeof(form)) return;
  
  var arrRequired = new Array("Contact_FirstName", "Contact_LastName", "Contact_Phone", 
          "Contact_Email", "Address_City", "Address_PostalCode", "Address_Address");
          
  var i;
  for(i=0; i<arrRequired.length; i++)
      if(form[arrRequired[i]].value == "") return;
  
    var xmlHttp = GetXmlHttpObject();
  if (xmlHttp != null){
        var progressDiv = find_object("progress_div");
    if(progressDiv != null) progressDiv.display();
      
      var tmp = form.Action.value;
    form.Action.value = "ajax-updatebilling";
    var querystring = getFormElements(form);
    form.Action.value = tmp;
        
        var url = "ajax_order.asp";
    
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            try{
                var progressDiv = find_object("progress_div");
                if(progressDiv) progressDiv.hide();
            }
            catch(e){
                //alert(e);
            }
            finally{
                    var progressDiv = find_object("progress_div");
                    if(progressDiv) progressDiv.hide();
                };
        }
    }
    if (window.XMLHttpRequest){
            xmlHttp.open("POST",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("POST",url,false);
        }
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(querystring);
  }
}

/*
function selectForm(paymentType)
{
  var pCheckForm = document.getElementById('check-form');
  var pCardForm = document.getElementById('card-form');
  var pTitle = document.getElementById('title_grid');
  var pTitleSpace = document.getElementById('title_grid_space');

  pCardForm.style.display = 'none';
  pCheckForm.style.display = 'none';
  pTitle.style.display = 'none';
  pTitleSpace.style.display = 'none';

  if (paymentType == 'card')
  {   
    pCardForm.style.display = 'inline';
    pTitle.style.display = 'inline';
    pTitleSpace.style.display = 'inline';     
  }
  
  if (paymentType == 'check')
  {
    pCheckForm.style.display = 'inline';
    pTitle.style.display = 'inline';
    pTitleSpace.style.display = 'inline';     
  } 
  
}
*/





/** @private */
function toQueryString(elements) {
    var node = null;
    var qs = "";
    var name = "";
    
    var tempString = "";
    for(var i = 0; i < elements.length; i++) {
        tempString = "";
        node = elements[i];
        
        name = node.getAttribute("name");
        //use id if name is null
        if (!name) {
            name = node.getAttribute("id");
        }
        name = encodeURIComponent(name);
        
        if(node.tagName.toLowerCase() == "input") {
            if(node.type.toLowerCase() == "radio" || node.type.toLowerCase() == "checkbox") {
                if(node.checked) {
                    tempString = name + "=" + encodeURIComponent(node.value);
                }
            }
            
            if(node.type.toLowerCase() == "text" || node.type.toLowerCase() == "hidden" || node.type.toLowerCase() == "password") {
                tempString = name + "=" + encodeURIComponent(node.value);
            }
        }
        else if(node.tagName.toLowerCase() == "select") {
            tempString = getSelectedOptions(node);
        }
        
        else if(node.tagName.toLowerCase() == "textarea") {
            tempString = name + "=" + encodeURIComponent(node.value);
        }
        
        if(tempString != "") {
            if(qs == "") {
                qs = tempString;
            }
            else {
                qs = qs + "&" + tempString;
            }
        }
        
    }
    
    return qs;
}

/** @private */
function getSelectedOptions(select) {
    var options = select.options;
    var option = null;
    var qs = "";
    var tempString = "";
    
    for(var x = 0; x < options.length; x++) {
        tempString = "";
        option = options[x];
        
        if(option.selected) {
            tempString = encodeURIComponent(select.name) + "=" + encodeURIComponent(option.value);
        }
        
        if(tempString != "") {
            if(qs == "") {
                qs = tempString;
            }
            else {
                qs = qs + "&" + tempString;
            }
        }
    }
    
    return qs;
}
//---//

//-----AJAX routine-----//
function GetXmlHttpObject()
{ 
 var xmlHttp1 = false;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp1=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP"); //IE 6.0+
      }
    catch (e)
      {
      try
        {
        xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP"); //IE 5.5+
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
 return xmlHttp1;
}
//---//

function openWindow(url, name, width, height, features) {
  var win;
  var top = 0;
  var left = 0;
  
  if (screen.width > width) left = (screen.width - width) / 2;
  if (screen.height > height) top = (screen.height - height) / 2;
  
  if (typeof(features) == "undefined") win = window.open(url, name, 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height);
  else win = window.open(url, name, 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height +', ' + features);
    
  if (navigator.appName != 'Microsoft Internet Explorer')  { if ( window.focus )  win.focus()};
}
//------------image expancion--------------//

function preview(imgSource, id){
  var divElement = find_object('preview_div'+id);
  var imgElement = find_object('preview_img'+id);
  var imgThumb = find_object('thumb_img'+id);
  //var imgElement = divElement.firstChild.firstChild.firstChild.firstChild.firstChild.firstChild;
  //alert(imgElement.nodeName);
  
  if(!divElement || !imgElement) return;
  var top = 0;
  var left = 0;
  var width = parseInt(divElement.style.width);
  var height = parseInt(divElement.style.height);
  //if (screen.width > width) left = (screen.width - width)/2;
  //if (screen.height > height) top = (screen.height - height)/2;
    
  divElement.style.display = 'inline';
  
  init(imgElement, imgThumb);
  
  if (imgElement.inited){
    //divElement.style.width=imgElement.originalWidth;
    //divElement.height=imgElement.originalHeight;
    imgElement.expand();
  }
  //divElement.style.top = top;
  //divElement.style.left = left;
  
}
 
 function init(imgElement, imgThumb)
  {
   imgElement.originalHeight = imgElement.height;
   imgElement.originalWidth = imgElement.width;
   imgElement.width = imgThumb.width;
   if(parseInt(imgElement.originalWidth)>0) imgElement.height = parseInt(imgThumb.width) / parseInt(imgElement.originalWidth ) * parseInt(imgElement.originalHeight);
   
   imgElement.expand = function() 
        {
         var factor1 = Math.round(imgElement.height*.15);
     var factor2 = Math.round(imgElement.width*.15);
         if(imgElement.width + factor2 < imgElement.originalWidth)
         {
          imgElement.width += factor2;
          imgElement.height += factor1;
          imgElement.imgDelayID = window.setTimeout(imgElement.expand,5);
         }
         else
         {
      
          imgElement.width = imgElement.originalWidth;
          imgElement.height = imgElement.originalHeight;
      clearTimeout(imgElement.imgDelayID);
         }
        };
  imgElement.inited = true;
}

function closePreview(id){
    var imgElement = find_object('preview_img'+id);
    var imgThumb = find_object('thumb_img'+id);
  if(imgElement && imgThumb)
    if(imgElement.inited){
      clearTimeout(imgElement.imgDelayID);
      imgElement.height = imgElement.originalHeight;
      imgElement.width = imgElement.originalWidth;
      imgElement.inited = false;
  }
  setVisibility('preview_div'+id, false);
}

function setVisibility(objname, vis, type){
    var obj = find_object(objname);
    if(!obj) return;
    if('visibility' == type)
        obj.style.visibility = vis?'visible':'hidden';
    else
        obj.style.display = vis?'inline':'none';
    
    
}

function find_object(sID)
{
  if (document.getElementById)
  {
    return document.getElementById(sID);
  }
  else if (document.all)
  {
    return document.all[sID];
  }
  else if (document.layers)
  {
    return document.layers[sID];
  }
  else
  {
    return null;
  }
}

    //---//     
 