function getPaintings()
{
	
	var paintingName = document.PaintingForm["PageHeaderControl$PaintingName"].value;
	
	
	var url = "http://www.gemegg.com/search/";
	
	

	if (paintingName == null || paintingName == "")	{
		url = url + ".html";							
	}
	else {
		url = url + encode(paintingName) + ".html";							
	}
	document.location = url;	
}

window.onload=function()
{
	document.onkeypress = cancel_Enter;
};


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 check your previous purchases, change password and retrieve PIN numbers.'
				  + '   </td> '
				  + ' </tr>'
				  + '</table>';
	document.write(content);
}



function addToCart(value)
{
	var str;
	str = location.href;
	str = "http://68.15.119.238:8080/phonecardsmile/ShoppingCart.aspx?";		
	var control = "FeaturedControl:FeatureCard:PhoneCard_" + value;
	window.location.href = str + "Action=Add&PhoneCardID=" + value  
				+ "&Denom=" + document.PhoneCardSmileForm[control].value;
}


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 document.PaintingForm.Sumbit = false;  
	return true;
}


function paintingSearchKeyPressed()
{
	
	var code;
	var e = window.event;
			
	if (e.keyCode == 13 || e.keyCode == 3)	{
		cancel_Enter(e);	
		getPaintings();
			
	}
}
function wirelessSearchKeyPressed()
{
	
	getWirelessCards();
}

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 getWirelessCards()
{
	
	var phoneCardID = document.PhoneCardSmileForm["SearchControl:PhoneCardSelectControl:PhoneCardSelect"].value;
	

	var url = "http://68.15.119.238:8080/phonecardsmile/calling_card/";
		if (phoneCardID != 0)	{
			//url = url + "&PhoneCardID=" + escape(phoneCardID);							
			url = url + encode(phoneCardID) + ".html";							
		}
		else {
			alert("Please select a wireless card.")
		}
		
		document.location = url;	
}


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; 
} 

