
function popUp(URL) {

	day = new Date();
	id = day.getTime();
	window.open(URL, id, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=380,height=400');

}

function GetMyCookieVal(offset) {
    var endstr = document.cookie.indexOf ( ";", offset ) ;
    if ( endstr == -1 ) endstr = document.cookie.length ;
    return unescape(document.cookie.substring(offset, endstr) ) ;
}
function GetMyCookie(name) {
    var arg = name + "=" ;
    var alen = arg.length ;
    var i = 0 ;
    var clen = document.cookie.length ;

    while (i < clen) {
        var j = i + alen
        if ( document.cookie.substring(i,j) == arg ) {
            var v =  GetMyCookieVal (j) ;
            return v ;
        }
        i = document.cookie.indexOf (" ", i) + 1 ;
        if ( i == 0 ) break ;
	} return null ;
}
function read_querystring()
   {
   var a_out = new Object();
   //a_out[0] = "";
   var s_loc = String(location.href);
 	//alert(s_loc);
   if(s_loc.indexOf('?')>0)
     {
     var p;
     var s_query = s_loc.substr(s_loc.indexOf('?')+1);
     var a_query = s_query ? s_query.split('&') : new Array();

     for(var i=0; i<a_query.length; i++)
       {
       p = a_query[i].split('=');
       a_out[p[0]] = p[1].replace(/\+/g, ' ');
     }
   }
    return a_out;

}










function popHold() {

		newwin = window.open('pophold.php','','height=350,width=350,scrollbars=0,toolbar=0,status=0');

		newwin.focus();

	}


function tos()
	{
	var popurl="tos.php"
	window.open(popurl,"","width=600,height=500,scrollbars,")
	}
function openpopup()
	{
	var popurl="tos.php"
	window.open(popurl,"","width=600,height=500,scrollbars,")
	}
function openpopupphone()
	{
	var popurl="http://www.securebiller.com/phone/index.php?aid=#aid#"
	window.open(popurl,"","width=375,height=400,")
	}



function popUnder() {

	url = "../ata/index.htm";

	newwin = Window.open(url,'','');

	//newwin.blur();

	self.focus();
	setTimeout("self.focus()",300);

}


function openpopuptos()
	{
	var popurl="tos.php"
	window.open(popurl,"","width=600,height=500,scrollbars,")
	}
function openpopuptosTrial()
{
var popurl="tos.php";
window.open(popurl,"","width=600,height=500,scrollbars,")
}
function openpopupcopyright()
	{
	var popurl="copyright.php"
	window.open(popurl,"","width=600,height=500,scrollbars,")
	}



function js_in_array(the_needle, the_haystack){
        var the_hay = the_haystack.toString();
        if(the_hay == ''){
            return false;
        }
        var the_pattern = new RegExp(the_needle, 'g');
        var matched = the_pattern.test(the_haystack);
        return matched;
    }

function js_get_index_at(the_needle, the_haystack) {
    for(var i=0; i<the_haystack.length; i++)
    {
        if ( the_haystack[i] == the_needle ) {
        	return i+1;
        }

    }
    return 0;
}

function confRemoval(name) {

    conf = confirm("Are you sure you wish to delete this item? " + name)

    return conf;

}

function jsValidateEmailAddress(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail ID")
		return false
	}

	if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail ID")
		return false
	}

	return true

}

function club_discount_check() {

    row = document.getElementById('discount_row');
    chk = document.getElementById('discount_check');

	if ( row == undefined || chk == undefined ) {
		return;
	}

    if ( chk.checked ) {
        row.className 	= 'blk-element';
    }
    else {
        row.className 	= 'blk-off';
    }

}

function add_ins_check() {

    row = document.getElementById('ins_row');
    chk = document.getElementById('ins_check');

	if ( row == undefined || chk == undefined ) {
		return;
	}

    if ( chk.checked ) {
        row.className 	= 'blk-element';
    }
    else {
        row.className 	= 'blk-off';
    }

}
function add_rush_check() {

    row = document.getElementById('rush_row');
    chk = document.getElementById('rush_check');

	if ( row == undefined || chk == undefined ) {
		return;
	}

    if ( chk.checked ) {
        row.className 	= 'blk-element';
    }
    else {
        row.className 	= 'blk-off';
    }

}

function adjustState() {

		/// COUNTRY VALUES
		var bill_country	= document.getElementById("brazil_input_bill");
		var ship_country	= document.getElementById("brazil_input");

		/// ROWS
		var bill_state_text_row	= document.getElementById("bill_state_text_row");
		var bill_state_drop_row	= document.getElementById("bill_state_drop_row");
		var bill_state_text_row_can	= document.getElementById("bill_state_text_row_can");
		var bill_state_drop_row_can	= document.getElementById("bill_state_drop_row_can");


		var ship_state_text_row	= document.getElementById("ship_state_text_row");
		var ship_state_drop_row	= document.getElementById("ship_state_drop_row");
		var ship_state_text_row_can	= document.getElementById("ship_state_text_row_can");
		var ship_state_drop_row_can	= document.getElementById("ship_state_drop_row_can");

		/// TEXT VALS
		var bill_state_text	= document.getElementById("bill_state_text");
		var ship_state_text	= document.getElementById("ship_state_text");

		/// DROP VALS
		var bill_state_drop	= document.getElementById("bill_state_drop");
		var ship_state_drop	= document.getElementById("ship_state_drop");
		var bill_state_drop_can	= document.getElementById("bill_state_drop_can");
		var ship_state_drop_can	= document.getElementById("ship_state_drop_can");

        var ship_find_state = '';
        var bill_find_state = '';

		/// SHIP HANDLE - US
		if ( ship_country.options[ship_country.selectedIndex].value == 'US' ) {

            /// ATTEMPT TO FIND THE MATCHING DROP STATE
            if ( ship_state_text.value != undefined && ship_state_text.value.length >= 2 ) {
                ship_find_state = ship_state_text.value.substring(0,2);
            }

            /// TEXT OFF
            /// DROP ON
            ship_state_text_row.className 	    = 'ordertextOFF';
            ship_state_drop_row_can.className 	= 'ordertextOFF';
            ship_state_drop_can.disabled		= true;
            //ship_state_text.disabled		= true;

            ship_state_drop_row.className	= 'ordertext';
            ship_state_drop.disabled		    = false;

            /// SET DROP
            if ( ship_state_drop.selectedIndex < 1 ) {
                ship_state_drop.selectedIndex	= js_get_index_at(ship_find_state.toUpperCase(),the_states);
            }

		}
		else if ( ship_country.options[ship_country.selectedIndex].value == 'CA' ) {

            /// ATTEMPT TO FIND THE MATCHING DROP STATE
            if ( ship_state_text.value != undefined && ship_state_text.value.length >= 2 ) {
                ship_find_state = ship_state_text.value.substring(0,2);
            }

            /// TEXT OFF
            /// DROP ON
            ship_state_text_row.className 	= 'ordertextOFF';
            ship_state_drop_row.className 	= 'ordertextOFF';
            ship_state_drop.disabled		= true;
            //ship_state_text.disabled		= true;

            ship_state_drop_row_can.className	= 'ordertext';
            ship_state_drop_can.disabled		= false;

            /// SET DROP
            if ( ship_state_drop_can.selectedIndex < 1 ) {
                ship_state_drop_can.selectedIndex	= js_get_index_at(ship_find_state.toUpperCase(),can_states);
            }

		}
		else {

			/// TEXT ON
			/// DROP OFF
			ship_state_text_row.className 	= 'ordertext';
			ship_state_text.disabled		= false;

			ship_state_drop_row.className	    = 'ordertextOFF';
			ship_state_drop.disabled		    = true;
			ship_state_drop_row_can.className	= 'ordertextOFF';
			ship_state_drop_can.disabled		= true;

		}

		/// BILL HANDLE - US
		if (  bill_country.options[bill_country.selectedIndex].value == 'US' ) {

            /// ATTEMPT TO FIND THE MATCHING DROP STATE
            if ( bill_state_text.value != undefined && bill_state_text.value.length >= 2 ) {
                bill_find_state = bill_state_text.value.substring(0,2);
            }

            /// TEXT OFF
            /// DROP ON
            bill_state_text_row.className 	    = 'ordertextOFF';
            bill_state_drop_row.className	    = 'ordertextOFF';
            bill_state_drop_can.disabled		= true;
            //bill_state_text.disabled		= true;

            bill_state_drop_row.className	= 'ordertext';
            bill_state_drop.disabled		= false;

            /// SET DROP
            if ( bill_state_drop.selectedIndex < 1 ) {
                bill_state_drop.selectedIndex	= js_get_index_at(bill_find_state.toUpperCase(),the_states);
            }

		}
		else if (  bill_country.options[bill_country.selectedIndex].value == 'CA' ) {

            /// ATTEMPT TO FIND THE MATCHING DROP STATE
            if ( bill_state_text.value != undefined && bill_state_text.value.length >= 2 ) {
                bill_find_state = bill_state_text.value.substring(0,2);
            }

            /// TEXT OFF
            /// DROP ON
            bill_state_text_row.className 	    = 'ordertextOFF';
            bill_state_drop_row.className	    = 'ordertextOFF';
            bill_state_drop.disabled		= true;
            //bill_state_text.disabled		= true;

            bill_state_drop_row_can.className	= 'ordertext';
            bill_state_drop_can.disabled		= false;

            /// SET DROP
            if ( bill_state_drop_can.selectedIndex < 1 ) {
                bill_state_drop_can.selectedIndex	= js_get_index_at(bill_find_state.toUpperCase(),can_states);
            }

		}
		else {

			/// TEXT ON
			/// DROP OFF
			bill_state_text_row.className 	= 'ordertext';
			bill_state_text.disabled		= false;

			bill_state_drop_row.className	    = 'ordertextOFF';
			bill_state_drop.disabled		    = true;
			bill_state_drop_row_can.className	= 'ordertextOFF';
			bill_state_drop_can.disabled		= true;

		}

	}

	function adjustBillShip() {

		if ( document.getElementById("same_ship_check").checked ) {


			$("#bill_table").find("tbody").hide();

		}
		else {

			$("#bill_table").find("tbody").show();

		}


	}
