 
 
function GetCgiValue(avp, key)
{
	for (i = 0; i < avp.length; i++)
	{
		ParsedAVP = /(.+)=(.*)/g.exec(avp[i]);
		if (ParsedAVP == null)
		{
			return("");
		}
		if (ParsedAVP[1] == key)
		{
			return(ParsedAVP[2]);
		}
	}
	return("");
}
				


function GetCgiAVPs()
{
	var avp = new Array();

	params = (window.location.search).split(/&/);
	var abc = "";
	var avp = new Array();
	for (i = 0; i < params.length; i++)
	{	
		avp[i] = params[i];
	}
	var p = /\?([^\?]+)/g.exec(avp[0]);
	avp[0] = p[1];
	return(avp);
}



function GetCgiAVPsFromForm(FormName)
{
	var avp = new Array();
	var f = document.forms[FormName];
	for (i=0; i<f.elements.length; i++) 
	{ 
		var e = f.elements[i];
		avp[i] = e.name + '=' + e.value;
	}
	return(avp);
}




function ChangePISalutation()
{
        var SelectedSalutation = document.gpi.PISalutationType.options[document.gpi.PISalutationType.selectedIndex].value;
	var avp = new Array();

	avp = GetCgiAVPs();

	var url = "/cgi/vf.php?action=" + GetCgiValue(avp, "action") + "&PISalutationType=" + SelectedSalutation;
	for (i = 0; i < avp.length; i++)
	{
		key = /(.+)=(.*)/g.exec(avp[i]);
		if (key[1] != "action" && key[1] != "PISalutationType" && key[1] != "curcust" && key[1] != "sid003")
		{
			url += "&";
			url += avp[i];
		}
	}

	window.location = url;
}



function ChangeCIDAnnounceState(j, selected, did, lastActivity, expire, session_id, username, authenticated, valid_session, identifier)
{           
        var currentTime = new Date()
        var tt = currentTime.getTime()

        if ((tt - (lastActivity*1000) <= (expire*1000)) && (authenticated == '1') && (valid_session == '1'))
        {
                xajax_ajaxCIDAnnounceButton(j, selected, did, session_id, username, identifier);
        }
        else
        {
                window.location = 'http://www.VirtuFon.com/cgi/vf.php?action=manage_account';       
        }

}



        
function cartGotoCheckout(doMozillaJavaTest)
{
		var f = document.forms['cart_form'];
		avp = GetCgiAVPsFromForm('cart_form');
		var sid = GetCgiValue(avp, "session_id");
		var username = GetCgiValue(avp, "username");
                if (doMozillaJavaTest == '0')
                {
                        var f = document.forms['cart_form'];
                        f.elements['gotoCheckout'].value = '1';
                        f.submit();
                }
                else if (doMozillaJavaTest == '1')
                {
                        if (navigator.javaEnabled())
                        {
                                var f = document.forms['cart_form'];
                                f.elements['gotoCheckout'].value = '1';
                                f.submit();
                        }
                        else
                        {
                                parent.location="/cgi/vf.php?action=java_required&session_id=" + sid + "&username=" + username;
                        }
                } 
}          




