// Funtion to seamlessly call the blah function at the end of the onload
// This causes the footer to position correctly. Still if you deal with 
// any javascript that changes the hieght of the page you will have to 
// recall the blah funtion.

// xHttpRequest r9, Copyright 2006-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
function dirtypop(content)
{
  var generator=window.open('','name','height=400,width=500');
  generator.document.write('<html><head><title>Popup</title>');
  generator.document.write('<link rel="stylesheet" href="css/common.css">');
  generator.document.write('</head><body>');
  generator.document.write('<div style=\'width:100%;height:100%;background-color:#FFFFFF;padding:10px;\'>'+content+'</div>');
  generator.document.write('<p><a href="javascript:self.close()">Close</a></p>');
  generator.document.write('</body></html>');
  generator.document.close();
}
function doit(ele){
	var elex = document.getElementById(ele);
	var elex2 = document.getElementById(ele+"t");
	var elex3 = document.getElementById(ele+"desc");	
	elex2.style.backgroundColor = "gray";
	elex3.style.display="block";
}
function undoit(ele){
	var elex = document.getElementById(ele);
	var elex2 = document.getElementById(ele+"t");
	var elex3 = document.getElementById(ele+"desc");	
	elex2.style.backgroundColor = "white";
	elex3.style.display="none";	
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

function addLoadEvent(func) {   
	var oldonload = window.onload;   
	if (typeof window.onload != 'function') {   
		window.onload = func;   
	} else {   
		window.onload = function() {   
    			oldonload();   
  			func();   
  		}	   
  	}   
}   
addLoadEvent(function(){blah(0);});   

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

function positionFooter(offset,num){
	hide('footer');
	var mxid='';
	var mx=0;
	var cur=0;
	for(var i=0;i<=num;i++)
	{
		cur=xPageY(xGetElementById('foot'+i));
		if(cur>mx){mx=cur;mxid='foot'+i;}
	}

	try{
		cur=xPageY(xGetElementById('footex'));
		if(cur>mx){mx=cur;mxid='footex';}
	}catch(err){}

	try{xTop('footer',mx+offset);}
	catch(err){alert(e.message);}
	show('footer');
	
	try{if(xGetElementById('HTF1')){xHeight('HTF1',mx+offset+50-xPageY('HTF1'));}}
	catch(err){alert(err.message);}
	try{if(xGetElementById('HTF2')){xHeight('HTF2',mx+offset+50-xPageY('HTF2'));}}
	catch(err){alert(err.message);}
	try{if(xGetElementById('HTF3')){xHeight('HTF3',mx+offset+50-xPageY('HTF3'));}}
	catch(err){alert(err.message);}
	try{if(xGetElementById('HTF4')){xHeight('HTF4',mx+offset+50-xPageY('HTF4'));}}
	catch(err){alert(err.message);}
	try{if(xGetElementById('HTF5')){xHeight('HTF5',mx+offset+50-xPageY('HTF5'));}}
	catch(err){alert(err.message);}
	try{if(xGetElementById('HTF6')){xHeight('HTF6',mx+offset+50-xPageY('HTF6'));}}
	catch(err){alert(err.message);}
}

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

function setDropDown(ele,val) {
	for(index = 0; index < ele.length; index++) {
		if(ele[index].value == val)
			ele.selectedIndex = index;
	}
}
function toggleCartSize(element){
	var attributes = {
		height: { to: 150 }
	};
	var attributes2 = {
		height: { to: 1 }
	};
	if(document.getElementById(element).style.height=='1px'){
		var anim = new YAHOO.util.Anim(element, attributes, 0.5, YAHOO.util.Easing.bounceOut);
		anim.animate();
	}else{
		var anim = new YAHOO.util.Anim(element, attributes2, 0.5, YAHOO.util.Easing.easeIn);
		anim.animate();
	}
}

function toggleCatalogPageSize(element){
	if(xDisplay(element)=='none'){
		xDisplay(element,'block');
	}else{
		xDisplay(element,'none');
	}
	blah(50);
}

function show(id){
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	} else {
		if (document.layers) {
			document.id.display = 'block';
		} else {
			document.all.id.style.display = 'block';
		}
	}
}

function hide(id){
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	} else {
		if (document.layers) {
			document.id.display = 'none';
		} else {
			document.all.id.style.display = 'none';
		}
	}
}

//show OR hide funtion depends on if element is shown or hidden
function shoh(id) { 
	
	if (document.getElementById) { // DOM3 = IE5, NS6
		if (document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = 'block';
			//filter(("img"+id),'imgin');			
		} else {
			//filter(("img"+id),'imgout');
			document.getElementById(id).style.display = 'none';			
		}	
	} else { 
		if (document.layers) {	
			if (document.id.display == "none"){
				document.id.display = 'block';
				//filter(("img"+id),'imgin');
			} else {
				//filter(("img"+id),'imgout');	
				document.id.display = 'none';
			}
		} else {
			if (document.all.id.style.visibility == "none"){
				document.all.id.style.display = 'block';
			} else {
				//filter(("img"+id),'imgout');
				document.all.id.style.display = 'none';
			}
		}
	}
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}


function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}

