function populate_shipping() {
	val = unescape(document.getElementById('definedshipping').options[document.getElementById('definedshipping').selectedIndex].value); 
	
	theval = val.split('^'); 
	document.getElementById('ship_first').value = theval[0];
	document.getElementById('ship_last').value = theval[1];
	document.getElementById('ship_address1').value = theval[2];
	document.getElementById('ship_address2').value = theval[3];
	document.getElementById('ship_city').value = theval[4];
	document.getElementById('ship_state').value = theval[5];
    document.getElementById('ship_zip').value = theval[6]
    document.getElementById('ship_country').value = theval[7];
    document.getElementById('ship_country').selectedIndex = (theval[7] - 1);
}

function populate_billing() {
	val = unescape(document.getElementById('definedbilling').options[document.getElementById('definedbilling').selectedIndex].value); 
	theval = val.split('^'); 
	document.getElementById('bill_first').value = theval[0];
	document.getElementById('bill_last').value = theval[1];
	document.getElementById('bill_address1').value = theval[2];
	document.getElementById('bill_address2').value = theval[3];
	document.getElementById('bill_city').value = theval[4];
	document.getElementById('bill_state').value = theval[5];
    document.getElementById('bill_zip').value = theval[6]
    document.getElementById('bill_country').value = theval[7];
    document.getElementById('bill_country').selectedIndex = (theval[7] - 1);
}	

function hide(theelement) {
	var theelement;
    document.getElementById(theelement).style.display='none';
}

function show(theelement) {
	var theelement;
    document.getElementById(theelement).style.display='block';
}

function open_popup(source,width,height,scrolling) {
	var source;
	var width;
	var height;
	var scrolling;
	window.open(source,"spool","width=" + width + ",height=" + height + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scrolling + ",copyhistory=no,resizable=yes,left=100,top=100");
}

function roundvalue(val){
	var dec = 2;
	var result = Math.round(val * Math.pow(10, dec)) / Math.pow(10, dec);
	return result;
}

function swap(element, value) {
	var element;
    var value;
    document.getElementById(element).innerHTML = value;
}

function rowlight(id, limit) {
	var id;
	var i = 1;
	var limit;
	for(i = 1; i <= limit; i++) {
		if(i == id) {
			document.getElementById(i).style.background='#e1fff8';	
		} else {
			document.getElementById(i).style.background='#FFF';	
		}
	}
}

function tabbox(tabid) {
	// document.getElementById('introbox').style.display = 'none';
	document.getElementById('thebox').className = 'tabbox-selected';
	var tabid;
	var tabcount = 3;
	var i;
	for(i = 1; i <= tabcount; i++) {
		var box = "box" + i;
		var tab = "tab" + i;
		if(tab == tabid) {
			document.getElementById(tab).className = 'tab-selected';
			document.getElementById(box).style.display = 'block';
		} else {
			document.getElementById(tab).className = 'tab';
			document.getElementById(box).style.display = 'none';	
		}
	}
}

function ajaxUpdate( elemid, url, options ) {
	var params = options.params || "";
	var meth = options.meth || "post";
	var async = options.async;
	if( async == null )
		async = true;
	var startfunc = options.startfunc || "";
	var endfunc = options.endfunc || "";
	var errorfunc = options.errorfunc || "";
	var noauthfunc = options.noauthfunc || "";
	var req = false;
	if( window.XMLHttpRequest )
		req = new XMLHttpRequest();
	else if( window.ActiveXObject )
		req = new ActiveXObject( "Microsoft.XMLHTTP" );
	else
	{
		alert(  "Your browser cannot perform the requested action. "+
				"Either your security settings are too high or your "+
				"browser is outdated. Try the newest version of "+
				"Internet Explorer or Mozilla Firefox." );
		return false;
	}
	if( startfunc != "" )
		eval( startfunc );
	req.onreadystatechange =
		function()
		{
			if ( req.readyState == 4 ) 
			{
				if ( req.status == 200 )
				{
					if( elemid != '' )
						document.getElementById(elemid).innerHTML = req.responseText;
					if( endfunc != "" )
						eval( endfunc );
					return true;
				}
				else
				{
					if( req.status == 403 && noauthfunc != "" )
						eval( noauthfunc );
					else
					{
						if( endfunc != "" )
							eval( endfunc );
						if( errorfunc != "" )
							eval( errorfunc );
					}
					return false;
				}
			}
		};
	if( meth == "get" )
	{
		req.open( meth, url+( params != "" ? "?"+params : "" ), async );
		req.send(null);
	}
	else
	{
		req.open( meth, url, async );
		req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
		req.send( params );
	}
}


function swapimg(imgid,limit,thisi) {
	var imgid;
    var limit;
    var thisi;
    var i = 1;
    for(i = 1; i <= limit; i++) {
    	if(i == thisi) {
        	document.getElementById('micro' + i).className='microbox-selected';
        } else {
        	document.getElementById('micro' + i).className='microbox';
        }	
    }
    
  	ajaxUpdate("productimg", "/content/ajax-productimg.php", {
		params:"id=" + imgid + "",
		meth:"post",
		async:true
        }
	);	  
}

function swapimg2(imgid,limit,thisi) {
	var imgid;
    var limit;
    var thisi;
    var i = 1;
    for(i = 1; i <= limit; i++) {
    	if(i == thisi) {
        	document.getElementById('micro' + i).className='microbox-selected';
        } else {
        	document.getElementById('micro' + i).className='microbox';
        }	
    }
    
  	ajaxUpdate("systemimg", "/content/ajax-systemimg.php", {
		params:"id=" + imgid + "",
		meth:"post",
		async:true
        }
	);	  
}

function statechanger(state) {
	var state;
	val = unescape(document.getElementById('country').options[document.getElementById('country').selectedIndex].value); 
  	ajaxUpdate("shipstates", "/content/ajax-states.php", {
		params:"id=" + val + "&state=" + state + "",
		meth:"post",
		async:true
        }
	);	
}

function flip_states_ship() {
	val = unescape(document.getElementById('ship_country').options[document.getElementById('ship_country').selectedIndex].value); 
	
  	ajaxUpdate("shipstates", "/content/ajax-shipstates.php", {
		params:"id=" + val + "",
		meth:"post",
		async:true
        }
	);	
}

function flip_states_bill() {
	val = unescape(document.getElementById('bill_country').options[document.getElementById('bill_country').selectedIndex].value); 
	
  	ajaxUpdate("billstates", "/content/ajax-billstates.php", {
		params:"id=" + val + "",
		meth:"post",
		async:true
        }
	);	
}

function populate_shipping_checkout() {
	val = unescape(document.getElementById('definedshipping').options[document.getElementById('definedshipping').selectedIndex].value); 
  	ajaxUpdate("shippingaddress", "/content/ajax-shippingaddress.php", {
		params:"id=" + val + "",
		meth:"post",
		async:true
        }
	);	
}


function populate_billing_checkout() {
	val = unescape(document.getElementById('definedbilling').options[document.getElementById('definedbilling').selectedIndex].value); 
  	ajaxUpdate("thebilladdress", "/content/ajax-billingaddress.php", {
		params:"id=" + val + "",
		meth:"post",
		async:true
        }
	);	
}


function populate_user_billing() {
	val = unescape(document.getElementById('definedshipping').options[document.getElementById('definedshipping').selectedIndex].value); 

  	ajaxUpdate("addarea", "/content/ajax-billaddress.php", {
		params:"id=" + val + "",
		meth:"post",
		async:true
        }
	);	
}





