﻿//-----------------------------------------------------
// Cart functions
//-----------------------------------------------------
function addOptions(p)
{
var optionlist = '';
var o = document.getElementsByTagName('input');
var c; var qv;

for (x=0;x<o.length;x++)
{
	if (o[x].name.indexOf('option') >= 0)
	{
		if (o[x].type == 'checkbox')
		{
			c = o[x];
			var op = c.name.substring(7);
			if (c.checked)
				{
					if (optionlist == '')
						{
							optionlist += op;
						}
					else
						{
							optionlist += ','+op;
						}
				}
		}
	}
	
	if (o[x].name == 'QuantityTextBox') {
		if (typeof o[x].attributes['ProductID'] != 'undefined') {
			if (o[x].attributes['ProductID'].value == p)
			{ qv = o[x].value; }
		}
	}
}
//var q = document.getElementById('QuantityTextBox');
  //  if (q == null)
	//{
		//qv = 1;
	  //  }
		//else
		//{
		//qv = q.value;
		//}
		//if (qv <= 1){qv=1;}
		
	var cb = document.getElementById('cartbutton');
	cb.href += '&options='+optionlist+'&Quantity='+qv;
	return true;
}


//-----------------------------------------------------
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	return;
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


startList = function() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("menu1");
		for (i=0; i < navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function editCategoryContent(categoryid) {
window.showModalDialog('./modals/Edit_Category_Content.aspx?CategoryID='+categoryid,'','dialogWidth:660px;dialogHeight:550px;resizable:no;scroll:no;center:yes;');
return false;
}

//==========================================================
//============== Realty Listing Functions ==================
//==========================================================
function PhotoShow(listingid) {
window.showModalDialog('./modals/Photo_Show.aspx?ListingID='+listingid,'','dialogWidth:800px;dialogHeight:800px;resizable:yes;scroll:yes;center:yes;');
return false;
}
//==========================================================
//==========================================================
function NewProduct(categoryid)
{
//var ar = document.all;
window.showModalDialog('./modals/NewMasterProduct.aspx?category='+categoryid,'','dialogWidth:800px;dialogHeight:800px;resizable:yes;scroll:yes;center:yes;')
//alert(ar.length);
return true;
}

function EditProduct(productid)
{
//var ar = document.all;
window.showModalDialog('./modals/NewMasterProduct.aspx?mode=edit&product='+productid,'','dialogWidth:800px;dialogHeight:700px;resizable:yes;scroll:yes;center:yes;')
//alert(ar.length);
return true;
}
function EditCatalogCategory(categoryid)
{
//var ar = document.all;
window.showModalDialog('./modals/EditCategoryContent.aspx?mode=edit&category='+categoryid,'','dialogWidth:800px;dialogHeight:550px;resizable:no;scroll:no;center:yes;')
//alert(ar.length);
return false;
}
function NewSubProduct(productid)
{
//var ar = document.all;
window.showModalDialog('./modals/NewSubProduct.aspx?product='+productid,'','dialogWidth:800px;dialogHeight:800px;center:yes;')
//alert(ar.length);
return true;
}

function EditSubProduct(productid)
{
//var ar = document.all;
window.showModalDialog('./modals/NewSubProduct.aspx?mode=edit&product='+productid,'','dialogWidth:800px;dialogHeight:700px;center:yes;')
//alert(ar.length);
return true;
}

function OpenModal(u,w,h)
{
window.showModalDialog(u,'','dialogWidth:'+w+'px;dialogHeight:'+h+'px;resizable:no;scroll:no;center:yes;')
}

//window.onload=startList;
function AddCart(productid,quantity,price,applicationpath)
{
//var ar = document.all;
window.showModalDialog(applicationpath+'/cci_Cart/AddToCart.aspx?product='+productid+'&quantity='+quantity+'&price='+price,'','dialogWidth:1px;dialogHeight:1px;center:yes;resizable:no;');
//alert(ar.length);
return false;
}


function  printProps(obj) {
  var output = "" ;
  for (var prop in obj) {
	output += "." + prop + " = " + obj[prop] + "<br/>\n" ;
  }
  return output ;
}

function  propsToOptions(obj) {
  // Takes an object and an object name 
  // Returns an array of option objects, one for each property in "obj"
  // The value of option.text is objName.propertyName
  var opts = new Array() ;
  for (var prop in obj) {
	opts[opts.length] = new Option("." + prop)
  }
  return opts ;    
}


function createOptions(selectObj, optsArray) {
  selectObj.options = optsArray ;
  return true ;
}

function arrayToOptions(arr) {
  var opts = new Array() ;
  var alen = arr.length ; 
  for (var i = 0; i < alen ; i++) {
	opts[i] = new Option(arr[i])
  }
  return opts ;
}

function highlightElement(elementID) {
    var el = document.getElementsByName(elementID)
    el[0].style.border = '2px #000000 dashed';
}


