﻿//General javascript for KidSurplus.
//This is javascript that doesn't apply to a particular page.
//Item detail and checkout javascript shouldn't go here.


function setDefault(defaulttxt,e) {
    var el;
    if (document.getElementById(e)) {
        el = document.getElementById(e);
        if (el.value==defaulttxt) {
            el.value = "";        
        }         
    }
}


function resetDefault(defaulttxt,e) {
    var el;
    if (document.getElementById(e)) {
        el = document.getElementById(e);
        if (el.value=="") {
            el.value = defaulttxt;        
        }         
    }
}

function openSuper(itemNo) {        
    window.open("supersize.asp?item="+itemNo,null,"height=400,width=500,scrollbars=yes,status=no,toolbar=no,resizable=1");
}

function getCartInfo()
{
	var strCookie;
		
	strCookie = readCookie("snap%5fcart");
	
	//alert(strCookie);
	

}

function handleZipCode(elem,code)
{
	if(code)
	{
		if(code == '0000')
		{
			elem.value = elem.value.replace(/\D/g,"");
		}
		else
		{
			elem.value = elem.value.replace(/-/g,"");		
			elem.value = elem.value.replace(/:/g,"");		
			elem.value = elem.value.replace(/_/g,"");		
		}
	}
}
function handlePhoneNumber(elem)
{
	elem.value = elem.value.replace(/\D/g,"")
}


//---------------------------------------------------------------------
// ENABLE - DISABLE THE HOURGLASS CURSOR
//---------------------------------------------------------------------
function enable_wait(){
	document.body.style.cursor = 'wait';
}
function disable_wait(){
	document.body.style.cursor = 'default';
}
//-->

//-------------------------------------------------------------------
// Image resize
//-------------------------------------------------------------------
var imgCollection = new Array();
var ResizeFlag;
var ResizeWidth;
var ResizeHeight;

function RecallResize() // cause AOL sucks
{
	ResizeImage(ResizeFlag, ResizeWidth, ResizeHeight)
}
function ResizeImage(flag, w, h)
{
	var tmpWidth;
	var tmpHeight;
	var oImg = new Image();
	//alert("In resize");

	ResizeFlag		= flag;
	ResizeWidth		= w;
	ResizeHeight	= h

	for (var i in imgCollection) 
	{
		if ( ! imgCollection[i].complete )
		{
			//alert("Incomplete preload");
			window.setTimeout("RecallResize", 500) 
		}
		else
		{		
			//alert("Completed Preload");
			tmpWidth	= imgCollection[i].width
			tmpHeight	= imgCollection[i].height
				
			if(flag == 0)
			{	
				if( tmpWidth > w) 
				{
					tmpHeight = Math.round(((w)/tmpWidth) * tmpHeight); 
					tmpWidth = w;									
				}
			}
			else
			{
				if( tmpHeight > h) 
				{
					tmpWidth = Math.round(((h)/tmpHeight) * tmpWidth); 
					tmpHeight = h; 
				}			
			}	
			
			//alert("Assigning Values: src=" + imgCollection[i].src + "   width=" + tmpWidth + "  height=" + tmpHeight );
			document.getElementById(i).src			= imgCollection[i].src;
			document.getElementById(i).width		= tmpWidth;
			document.getElementById(i).height		= tmpHeight;			
			document.getElementById(i).style.width	= tmpWidth  + "px";
			document.getElementById(i).style.height	= tmpHeight + "px";
			document.getElementById(i).style.display= '';

		}
	}					
}

//-------------------------------------------------------------------
// Image resize
//-------------------------------------------------------------------