function getCards()
{
	
	var phoneCardName = document.PhoneCardSmileForm["SearchControl:PhoneCardNameTextbox"].value;
	var countryName = document.PhoneCardSmileForm["SearchControl:CountrySelectControl:CountrySelect"].value;
	
	var url = "http://www.phonecardsmile.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 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>';
	var content =  '<br><br><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. The problem has been fixed. 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>. If you need assistance please call 1-800-266-5117'
				  + ' We apologize for the convenience caused. '
				  + '   [Date Posted: 09/16/2006]</td> '
				  + ' </tr>'
				  + '</table>';
	/*var content =   '<table width="100%"> '
				  + ' <tr> '
				  +	'	<td class=\"my-account-header-style\">'
				  + ' <font color=\"red\"><b>Important!</b></font> We have experienced technical problems around 1:30am to 1:45pm today. We have fixed the problem since then. We apologize for any inconveniences.'
				  + ' [Date Posted: 09/2/2006]  </td> '
				  + ' </tr>'
				  + '</table>';*/

	content = '';
	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.phonecardsmile.com/ShoppingCart.aspx?";		
	//str = "http://localhost:8080/pcs/ShoppingCart.aspx?";
	var control = "FeaturedControl:FeatureCard" + value +":PhoneCard_" + value;
	window.location.href = str + "Action=Add&PhoneCardID=" + value  
				+ "&Denom=" + document.PhoneCardSmileForm[control].value;
}






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.phonecardsmile.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 localAccessSearchKeyPressed()
{
	getLocalAccessCards();
}

function getLocalAccessCards()
{
	
	var stateName = document.PhoneCardSmileForm["SearchControl:SearchStateSelect"].value;	

	var url = "http://www.phonecardsmile.com/local_access/";
		if (stateName != 0)	{
			url = url + encode(stateName) + ".html";	
			document.location = url;						
		}
		else {
			alert("Please select state")
		}			
}

function encode(str)
{
    var myStr = replaceIt(str, " ", "_");
    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; 
} 


function showRedeemAd()
{
	
	var content = '<object style=\"float: right;padding-left:16px;margin-left:20px\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ' 
			+	'codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" '
			+		'width=\"251\" height=\"111\" title=\"Rewards Program\">'
			+	      ' <param name=\"movie\" value=\"images/2.swf\">'
			+	      ' <param name=\"quality\" value=\"high\">'
			+	      '<embed style=\"float: right\" src=\"images/2.swf\" quality=\"high\" '
			+		'pluginspage=\"http://www.macromedia.com/go/getflashplayer\" '
			+		'type=\"application/x-shockwave-flash\" width=\"251\" height=\"111\"></embed> </object>'
	//alert(content);
	document.write(content);
}


function showRewards()
{
	
	var content = '<object style=\"float: right;padding-left:0px;margin-left:0px\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ' 
			+	'codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" '
			+		'width=\"200\" height=\"111\" title=\"Rewards Program\">'
			+	      ' <param name=\"movie\" value=\"https://www.phonecardsmile.com/images/RewardsPoints.swf\">'
			+	      ' <param name=\"quality\" value=\"high\">'
			+	      '<embed style=\"float: right\" src=\"https://www.phonecardsmile.com/images/RewardsPoints.swf\" quality=\"high\" '
			+		'pluginspage=\"https://www.macromedia.com/go/getflashplayer\" '
			+		'type=\"application/x-shockwave-flash\" width=\"200\" height=\"111\"></embed> </object>'
	//alert(content);
	document.write(content);
}



/****************************************
	Ajax call for product details.
****************************************/
var xmlHttp; // object for making http requests.
var name;
function showDetails(name)
{
	
	xmlHttp = getXmlHttpObject();
	if (xmlHttp != null)
	{
		var url = "http://www.phonecardsmile.com/ajax/" +  name + "_phone_card.html";
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}
function showSecureDetails(name)
{
	
	xmlHttp = getXmlHttpObject();
	if (xmlHttp != null)
	{
		var url = "https://www.phonecardsmile.com/ajax/" +  name + "_phone_card.html";
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}

function getXmlHttpObject()
{
	var obj;
	obj = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	return obj;
}


/******************************************
	Event method registered for Ajax call completion.
*********************************************/
function stateChanged() 									 
{
	if (xmlHttp.readyState == 4 
		|| xmlHttp.readyState == "complete")
	{
		var str = xmlHttp.responseText;

		if (isIE())	{
			overlib(str, SHADOW, WRAP, SHADOWCOLOR,'#cccccc', STICKY, FULLHTML, 
					//CAPTION, name + 'Phone Card Highlights',
					 BORDER, 1, MOUSEOFF, VAUTO);
		}
		else {
			overlib(str, STICKY, FULLHTML, //CAPTION, 'Best viewed in Internet Explorer',
					 BORDER, 1, MOUSEOFF, VAUTO);
		
		}
	}
}

function isIE()
{
	var ie = false;
	var browserName = navigator.appName;
	if (browserName == "Microsoft Internet Explorer")
	{
		
		ie = true;
		
	}

	return ie;
}

