function showAnnouncement()
{							
	var content = '<table width="100%"> '
				  + ' <tr> '
				  +	'	<td class=\"my-account-header-style\">'
				  + ' <font color=\"red\"><b>New!</b></font> <a href=\"https://www.phonecardsmile.com/myaccount.html\">My Account</a> feature is introduced. You may now <b>check previous purchases</b>, <b>change password</b> and <b>retrieve PIN numbers</b>.'
				  + '   </td> '
				  + ' </tr>'
				  + '</table>'
			 + '<table width="100%"> '
				  + ' <tr> '
				  +	'	<td class=\"my-account-header-style\">'
				  + ' <font color=\"red\"><b>Important!</b></font> We have experienced failures in sending PIN numbers to some of our customers\' emails. If you did not receive your PIN number, please retrieve or resend your PIN numbers under <a href=\"https://www.phonecardsmile.com/myaccount.html\">My Account</a>.'
				  + '   [Date Posted: 04/24/2006]</td> '
				  + ' </tr>'
				  + '</table>'
			 + '<table width="100%"> '
				  + ' <tr> '
				  +	'	<td class=\"my-account-header-style\">'
				  + ' <font color=\"red\"><b>Important!</b></font> We have experienced technical problems that send <b>DUPLICATE PIN numbers</b> to some of our customers\' emails. If you have received DUPLICATE PIN numbers, please retrieve or resend your PIN numbers under <a href=\"https://www.phonecardsmile.com/myaccount.html\">My Account</a>. We apologize for any inconveniences.'
				  + ' [Date Posted: 04/28/2006]  </td> '
				  + ' </tr>'
				  + '</table>';
	document.write(content);
}

function showCurrentTime()
{
	// This array holds the "friendly" day names
	var day_names = new Array(7)
	day_names[0] = "Sunday"
	day_names[1] = "Monday"
	day_names[2] = "Tuesday"
	day_names[3] = "Wednesday"
	day_names[4] = "Thursday"
	day_names[5] = "Friday"
	day_names[6] = "Saturday"
	
	// This array holds the "friendly" month names
	var month_names = new Array(12)
	month_names[0] = "January"
	month_names[1] = "February"
	month_names[2] = "March"
	month_names[3] = "April"
	month_names[4] = "May"
	month_names[5] = "June"
	month_names[6] = "July"
	month_names[7] = "August"
	month_names[8] = "September"
	month_names[9] = "October"
	month_names[10] = "November"
	month_names[11] = "December"
	
	// Get the current date
	date_now = new Date()
	
	// Figure out the friendly day name
	day_value = date_now.getDay()
	date_text = day_names[day_value]
	
	// Figure out the friendly month name
	month_value = date_now.getMonth()
	date_text += " " + month_names[month_value]
	
	// Add the day of the month
	date_text += " " + date_now.getDate()
	
	// Add the year
	date_text += ", " + date_now.getFullYear()
	
	// Get the minutes in the hour
	minute_value = date_now.getMinutes()
	if (minute_value < 10) {
	    minute_value = "0" + minute_value
	}
	
	// Get the hour value and use it to customize the greeting
	hour_value = date_now.getHours()
	if (hour_value == 0) {
	   greeting = "Good morning, "
	   time_text = " at " + (hour_value + 12) + ":" + minute_value + " AM"
	}
	else if (hour_value < 12) {
	    greeting = "Good morning!"
	    time_text = " at " + hour_value + ":" + minute_value + " AM"
	}
	else if (hour_value == 12) {
	    greeting = "Good afternoon!"
	    time_text = " at " + hour_value + ":" + minute_value + " PM"
	}
	else if (hour_value < 17) {
	    greeting = "Good afternoon!"
	    time_text = " at " + (hour_value - 12) + ":" + minute_value + " PM"
	}
	else {
	    greeting = "Good evening!"
	    time_text = " at " + (hour_value - 12) + ":" + minute_value + " PM"
	}
	
	document.write(greeting + " It's " + date_text + time_text)
	
	
}

function addToCart(value)
{
	var str;
	str = location.href;
	str = "http://www.pinfly.com/ShoppingCart.aspx?";		
	var control = "PhoneCardDetailControl:ValueSelect";
	
	var element;
	var denom;
	if (document.PinFlyForm[control] != null)	{
		element = document.PinFlyForm[control];
		
	}
	control = "AccessListControl:ValueSelect";	
	if (document.PinFlyForm[control] != null)	{
		element = document.PinFlyForm[control];
		
	}
	control = "TermsControl:ValueSelect";	
	if (document.PinFlyForm[control] != null)	{
		element = document.PinFlyForm[control];
		
	}
	control = "RateListControl:ValueSelect";	
	if (document.PinFlyForm[control] != null)	{
		element = document.PinFlyForm[control];
		
	}
	control = "HowToUseControl:ValueSelect";	
	if (document.PinFlyForm[control] != null)	{
		element = document.PinFlyForm[control];
		
	}
	
	denom =	replaceIt(element.options
					[element.selectedIndex].text, "$", "");
	denom =		replaceIt(denom,  "cards", "");
	window.location.href = str + "Action=Add&PhoneCardID=" + value  
				+ "&Denom=" + denom;
	
}






window.onload=function()
{
	document.onkeypress = cancel_Enter;
};
  

function cancel_Enter(e)
{
	if (!e) var e = window.event;  //for IE
	
	var code;
	if(e.keyCode) code = e.keyCode; //for IE
	if(e.which) code = e.which;  //for other browsers

	if (code == 13) return false;  
	return true;
}


function phonecardSearchKeyPressed()
{
	
	var code;
	var e = window.event;
	
				
	if (e.keyCode == 13 || e.keyCode == 3)	{
		//alert("code: " + e.keyCode);
		getCards();
		cancel_Enter(e);
	}
}

function wirelessSearchKeyPressed()
{
	
	getWirelessCards();
}


function getWirelessCards()
{
	
	var phoneCardID = document.PhoneCardSmileForm["SearchControl:PhoneCardSelectControl:PhoneCardSelect"].value;
	

	var url = "http://www.pinfly.com/calling_card/";
		if (phoneCardID != 0)	{
			//url = url + "&PhoneCardID=" + escape(phoneCardID);							
			url = url + encode(phoneCardID) + "_phone_card.html";	
			document.location = url;						
		}
		else {
			alert("Please select a wireless card.")
		}
		
			
}


function encode(str)
{
    var myStr = replaceIt(str, "-", "(dash)");
    myStr = replaceIt(myStr, " ", "-");
    myStr = replaceIt(myStr, "*", "(star)");
    myStr = replaceIt(myStr, "&", "(and)");
    myStr = replaceIt(myStr, ".", "(dot)");
    myStr = replaceIt(myStr, "%", "(percent)");
    myStr = replaceIt(myStr, "?", "(question)");
    myStr = replaceIt(myStr, "/", "(slash)");
    
	return myStr;
	
}

function replaceIt(sString, sReplaceThis, sWithThis) { 
	if (sReplaceThis != "" && sReplaceThis != sWithThis) { 
		var counter = 0; 
		var start = 0; 
		var before = ""; 
		var after = ""; 
		while (counter<sString.length) { 
			start = sString.indexOf(sReplaceThis, counter); 
			if (start == -1) { 
				break; 
			} 
			else { 
				before = sString.substr(0, start); 
				after = sString.substr(start + sReplaceThis.length, sString.length); 
				sString = before + sWithThis + after; 
				counter = before.length + sWithThis.length; 
			} 
		} 
	} 
	return sString; 
} 



/************************************
	change of price 

*************************************/

function onValueChanged(element)
{
	
	var value = element.value;
	var prices = value.split(",");
	
	var element = document.getElementById("PromoPrice");
	element.firstChild.nodeValue = prices[0];
	element = document.getElementById("MemberPrice");
	element.firstChild.nodeValue = prices[1];	
	
	
}

/************************************
	change of price 



function onRateChanged(element)
{

	var value = element.value;
		
	var element = document.getElementById("RateDisplay");
	if (value != "0")	{
		element.firstChild.nodeValue = value;
	}
	else {
		element.firstChild.nodeValue = "--";
	}
	
	
}
*************************************/
/************************************
	change of rate 

*************************************/

function onRateChanged(element)
{

	var values = element.value.split(",");
	
	var rate = values[0];
	var fee = values[1];
	var element = document.getElementById("PhoneCardDetailControl_RateLabel");
	if (rate != "0")	{
		element.firstChild.nodeValue = rate;
	}
	else {
		element.firstChild.nodeValue = "--";
	}
	
	var messageCell = document.getElementById("MessageCell");
	


	var myOptions = document.PinFlyForm["PhoneCardDetailControl:CountrySelectControl:CountrySelect"].options;
	var index =  document.PinFlyForm["PhoneCardDetailControl:CountrySelectControl:CountrySelect"].selectedIndex;
	var option = myOptions[index];

	//alert(index);
	//alert(option.text);

	if (messageCell != null)	
	{
		messageCell.firstChild.nodeValue = option.text;
	}
	
	var hiddenFaceValueStr = document.getElementById("PhoneCardDetailControl_HiddenFaveValues").value;
	
	var facevalues = hiddenFaceValueStr.split(",");
	
	
	var cell = null;
	var id = null;
	
	for (var i = 0; i < facevalues.length; i++)	{
		
		id = "PhoneCardDetailControl_cell_" + facevalues[i];
		cell = document.getElementById(id);
		if (cell != null)	{
			if (rate > 0)	{
				cell.firstChild.nodeValue = Math.round(((facevalues[i] * 100)-fee)/rate);
			}
			else {
				cell.firstChild.nodeValue = "Free/Unlimited";			
			}
		}	 
	}
	  
	
}
/************************************
	get search

*************************************/
function getCards()
{
	
	var phoneCardName;
	
	var countryName;

	if ((document.PinFlyForm["ListTopSearchControl:CountrySelectControl:CountrySelect"]) != null)	{
	
		
		countryName =  document.PinFlyForm["ListTopSearchControl:CountrySelectControl:CountrySelect"].value;
		if (countryName == "0")	{
			alert("Please select a country.");
		}
		document.PinFlyForm["ListTopSearchControl:CountrySelectControl:CountrySelect"];
	}
	else {
		countryName = document.PinFlyForm["MainSearchControl:CountrySelectControl:CountrySelect"].value;
	}
	
	if ((document.PinFlyForm["PhoneCardName"]) != null)	{
	
		phoneCardName = document.PinFlyForm["PhoneCardName"].value;
	}
	
	
	var url = "http://www.pinfly.com/search/";
	
	if (countryName == "0")	{
		url = url + "-/";
	}
	else {
		url = url + escape(encode(countryName)) + "/";	
	}
	//alert (url);	

	if (phoneCardName == null || phoneCardName == "" || phoneCardName == "0")	{
		url = url + "-.html";							
	}
	else {
		url = url + escape(encode(phoneCardName)) + ".html";							
	}
	document.location = url;	
}


function countrySearchKeyPressed()
{
	
	var code;
	var e = window.event;
	
	if (e != null)	{
				
		if (e.keyCode == 13 || e.keyCode == 3)	{
			//alert("code: " + e.keyCode);
			getCards();
			cancel_Enter(e);
		}
	}
	else {
		getCards();
	}  
}

