// JavaScript Document


var events = YAHOO.util.Event;
var $$ = YAHOO.util.Selector.query;
var fx = YAHOO.widget.Effects;
var $ = YAHOO.util.Dom;
var ani = YAHOO.util.Anim;
var subheight;
var loaded=false;
var pageheight;
var shiprateset = '';

//YAHOO.util.Event.onDOMReady(setShipForm);

//function setShipForm(){

//YAHOO.util.Event.removeListender("shiprate", "submit");
//YAHOO.util.Event.addListener("shiprate", "submit", FIC_checkForm);
//YAHOO.util.Event.addListener("shiprate", "submit", getshiprate);

//}

function showsub(id){

	if (ani){
		if (ani.isAnimated){
			ani.stop();
		}
			ani = null;
	}
	
	
	
	
	var elem  = document.getElementById('sub_nav_'+id);
	
	var par = document.getElementById(id);
	
	var kids = $$('#sub_nav_'+id+' ol li');
	
	
	ol = elem.firstChild;
	
	if (subheight === undefined || subheight !== kids.length * 20){
	//subheight = parseInt($.getStyle(elem, 'height'), 10); 
	subheight =  kids.length * 20;
	elem.style.height = '1px';
	}


	if (elem){
		if (elem.style.visibility !== 'visible'){
			
			elem.style.visibility = 'visible';
			ani = new YAHOO.util.Anim(elem, {height: {to:subheight}}, .3, YAHOO.util.Easing.easeOut);
			ani.animate();
		}else{
			
			ani = new YAHOO.util.Anim(elem, {height: {to:1}}, .3, YAHOO.util.Easing.easeOut);
			
			ani.onComplete.subscribe(function() {
					elem.style.visibility = 'hidden';
																					
				});
			ani.animate();
			
		}
	}
	
}



function removefromcart(item)
{ 

	
		//alert(form.action);
 	
		
		//alert(form.action);
	    YAHOO.util.Connect.asyncRequest('GET', "remove.php?iid="+item.id+"&session="+sessionID+"&ajax=true", removefromcartback); 

	
	return false;

}


function updatecart(form) {
	
		YAHOO.util.Connect.setForm(form);
		//alert(form.action);
	    YAHOO.util.Connect.asyncRequest('POST', form.action, removefromcartback, 'session='+sessionID+'&ajax=true'); 

	
}


function addtocart(form)
{ 

	
	
 	
		YAHOO.util.Connect.setForm(form);
		//alert(form.action);
	    YAHOO.util.Connect.asyncRequest('POST', form.action, addtocartback, 'session='+sessionID+'&ajax=true'); 

	
	return false;

}

function setshipstate(form)
{ 

	
	
 	
	YAHOO.util.Connect.setForm(form);
	//alert(form.action);
	YAHOO.util.Connect.asyncRequest('POST', form.action, setstateback, 'session='+sessionID+'&ajax=true'); 

	
	return false;

}



function updateminicart(){
		YAHOO.util.Connect.asyncRequest('GET', "minicart.php?session="+sessionID+"&ajax=true", updateminicartback); 
}

var updateminicartback = 
{	customevents:{

		onSuccess:function(eventType, args) {
		
		document.getElementById('minicart_div').innerHTML = args[0].responseText;
		initPageChangers();
	   
		}
	}
}

var removefromcartback = 
{	customevents:{
		onStart:function(eventType, args) {
		
		$.setStyle('cs_modal_container', 'z-index', '97');
		$.setStyle('cs_modal_container', 'display', 'block');
			

		},
		onComplete:function(eventType, args) {
		$.setStyle('cs_modal_container', 'z-index', '0');
		$.setStyle('cs_modal_container', 'display', 'none');

		},
		onSuccess:function(eventType, args) {
		
		document.getElementById('subcontent_div').innerHTML = args[0].responseText;
		if (!document.getElementById('cs_cart_form')) {
			document.getElementById('minicart_div').innerHTML = '';
		}
		else
		{
			updateminicart();
		}
		initPageChangers();
		initTextLinks();
	   
		},
		onFailure:function(eventType, args) {

		},

		onUpload:function(eventType, args) {

		},
		onAbort:function(eventType, args) {

		}
	}
}



var setstateback = 
{	customevents:{
		onStart:function(eventType, args) {
		
		$.setStyle('cs_modal_container', 'z-index', '97');
		$.setStyle('cs_modal_container', 'display', 'block');
			

		},
		onComplete:function(eventType, args) {
		$.setStyle('cs_modal_container', 'z-index', '0');
		$.setStyle('cs_modal_container', 'display', 'none');

		},
		onSuccess:function(eventType, args) {
			
		document.getElementById('subcontent_div').innerHTML = args[0].responseText;
		initPageChangers();
		initTextLinks();
	   
		},
		onFailure:function(eventType, args) {

		},

		onUpload:function(eventType, args) {

		},
		onAbort:function(eventType, args) {

		}
	}
}

var addtocartback = 
{	customevents:{
		onStart:function(eventType, args) {
		
		$.setStyle('cs_modal_container', 'z-index', '97');
		$.setStyle('cs_modal_container', 'display', 'block');
			

		},
		onComplete:function(eventType, args) {
		$.setStyle('cs_modal_container', 'z-index', '0');
		$.setStyle('cs_modal_container', 'display', 'none');

		},
		onSuccess:function(eventType, args) {
			
		document.getElementById('minicart_div').innerHTML = args[0].responseText;
		initPageChangers();
		initTextLinks();
	   
		},
		onFailure:function(eventType, args) {

		},

		onUpload:function(eventType, args) {

		},
		onAbort:function(eventType, args) {

		}
	}
}
	

var formBack = 
{	customevents:{
		onStart:function(eventType, args) {
		
		$.setStyle('cs_modal_container', 'z-index', '97');
		$.setStyle('cs_modal_container', 'display', 'block');
			

		},
		onComplete:function(eventType, args) {
		$.setStyle('cs_modal_container', 'z-index', '0');
		$.setStyle('cs_modal_container', 'display', 'none');

		},
		onSuccess:function(eventType, args) {
			//alert('hello');
		var content = args[0].responseText;
		content = content.replace(/\\'/g, '\'');
		//alert(content);
		document.getElementById('subcontent').innerHTML = content;
		if (document.getElementById('cart_shipping')){
			//alert('hello');
			document.getElementById('cart_shipping_amount').innerHTML = document.getElementById('shiprate').value;
			document.getElementById('cart_shipping').style.display="block";
		}
							 
	   
		},
		onFailure:function(eventType, args) {

		},

		onUpload:function(eventType, args) {

		},
		onAbort:function(eventType, args) {

		}
	}
	
}

function formAjax(form)
{
	//alert(form.id);
	var check = FIC_checkForm(form);
	//alert(check);
	if (check)
	{
			YAHOO.util.Connect.setForm(form);
			YAHOO.util.Connect.asyncRequest('POST', form.action, formBack, null);
	}
	
	return false;
}


var callback =
{
	customevents:{
		onStart:function(eventType, args) {
	
		},
		onComplete:function(eventType, args) {
	
		},
		onSuccess:function(eventType, args) {
			
		  	var blah = document.getElementById('cs_tools_image_thumb_div_'+args[0].responseText);
			blah.parentNode.removeChild(blah);
	   
		},
		onFailure:function(eventType, args) {
	
		},

   
		onUpload:function(eventType, args) {
		
		},
		onAbort:function(eventType, args) {
		}
	}
}

function confirmDelete(form)
{ 

	
	
 	if (confirm("Really?"))
	{
		YAHOO.util.Connect.setForm(form);
		//alert(form.action);
	    YAHOO.util.Connect.asyncRequest('POST', form.action, callback, null); 
		
	}
	else
	{
		
	}
	
	return false;

}


var events = YAHOO.util.Event;
var $$ = YAHOO.util.Selector.query;
var fx = YAHOO.widget.Effects;
var $ = YAHOO.util.Dom;
var ani = YAHOO.util.Anim;







function Unhighlight(el){
	var bright = new YAHOO.util.ColorAnim(el, {backgroundColor: {to: '#968D6C'}}, .1);
	bright.animate();
	
}


function Highlight(el){
	var dark = new YAHOO.util.ColorAnim(el, {backgroundColor: {to: '#A59C72'}}, .6);
	dark.animate();
	
}


function noclick(){

	return false;
}





var html, lastSection = '', lastSubsection, bookmarkedSection, bookmarkedSubsection, currentSection, currentSubsection, querySection, querySubsection, initSection, initSubsection, currentId;
  var anchors, i, len, href, section, subsection, subLinks, iconLinks, anchor, iconLink, subLink;






var newState = '', newItemState, currentState, currentItemState, initialPageState, bookmarkedPageState, queryPageState, polaroidCount;

events.onDOMReady(function(){
		
		//alert('hello');
		
		
		/*initNavHistory2();
				
		blank();
		initPolaroid();
		flirInit();
		flirMenu();
		flirTitle();
		initStyles();
		initSideBars();
		
		attachBehaviors();	
		
		
		if (initialPageState == defaultPageState || initialPageState == ''){
			showSplash();
			setTimeout('places()', 9200);
			setTimeout('polaroid.animate()', 9200);
			setTimeout('loadPage()', 9200);
			polaroidState = "visible";
			polaroidCount = 1;
		}
		else
		{
			places();
			loadPage();
		}
		
		*/
		
	});



 




var checkoutForm = "";

    function initCheckoutLinks() {
        	
			//alert('hello');
			
			var forms = $$('form.checkout');
			//alert(forms.length);
			for (i = 0, len = forms.length; i < len; i++) {
			
			
            form = forms[i];
            YAHOO.util.Event.addListener(form, "submit", function (evt) {
                action = this.getAttribute("action");
			 nextStep = action.replace('.php', '');
				try {

						
						
						var check = FIC_checkForm(this);
						//alert(check + ' ' + action + ' ' + nextStep);
						//var check = true;
						if (check)
						{
							
							//var myobj = {form:this, step:nextStep};
							//alert (myobj.form.id);
							checkoutForm = this;
							YAHOO.util.History.navigate("step", nextStep);
						}
					
				} catch (e) {
					//loadSection(newState);
		
				}
                YAHOO.util.Event.preventDefault(evt);
            });
        }
    }


function ClickHereToPrint(){

	var whatever = document.getElementById('cs_content').innerHTML;
	var win = window.open('', '', 'width=600,height=800');
	win.document.open();
	win.document.write("<body onload='self.print();'>" + whatever + "</body>");
	//win.document.close();
	//win.focus();
	return false;
	
}


function cardType(number) {

//alert(number);

document.getElementById('inp_card').value=number.substr(number.length-4);
var ctype; 

switch (number.substr(0, 1)) { 
	case '4':  ctype='visa';  cardmsg = '<img class="card_type_thumb" src="cs-content/images/cc_'+ctype+'_sm.png\" />';
	break; 
	case '5':  ctype='mastercard';  cardmsg = '<img class="card_type_thumb" src="cs-content/images/cc_'+ctype+'_sm.png\" />';
	break; 
	case '6':  ctype='discover';  cardmsg = '<img class="card_type_thumb" src="cs-content/images/cc_'+ctype+'_sm.png\" />';
	break; 
	case '3':  ctype='amex';  cardmsg = '<img class="card_type_thumb" src="cs-content/images/cc_'+ctype+'_sm.png\" />';
	break;   
	default:
	cardmsg = '16 digits, no spaces or dashes';
}
	//alert(cardmsg);
	document.getElementById('inp_card_type').value = ctype;
	document.getElementById('card_tip').innerHTML = cardmsg;
}

