//check if the date is valid (non empty)
function checkDate(dayselected, monthselected, yearselected, objFocus)
{
	if (dayselected == "" || monthselected == "" || yearselected == "")
	{
	   	alert("Please select a valid date.");
	   	objFocus.focus() ;
	   	return false;
	}
  	return true; 
}


// check if the character is digit
function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"));
}

// check if the input string is integer number
function isInteger (inputString)
{   
	var i;
	if (isEmpty(inputString))
		return false;
	
	for (i = 0; i < inputString.length; i++)
	{
		var c = inputString.charAt(i);
		if (!isDigit(c))
		{
			return false;
		}
	}
	return true;
}

function isEmpty(inputString)
{   
	//return ((inputString == null) || (inputString.length == 0))
		
	return ((inputString == null) || ((trim(inputString)).length == 0))
}

function isLetter (c)
{   
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c==" "))
}


// EMail Validation
function isValidEmail(email)
{
	invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;"
	if (email == "")			// cannot be empty
	{
		return false;
	}

	for (i=0; i<invalidChars.length; i++)	// does it contain any invalid characters
	{	
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1)
		{
			return false;
		}
	}

	lengthOfEmail = email.length;
	if( (email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == "."))
	{
		return false;
	}

	Pos = email.indexOf("@",1);
	if(email.charAt(Pos + 1) == ".")
	{
		return false;
	}

	while((Pos < lengthOfEmail) && ( Pos != -1))
	{
		Pos = email.indexOf(".",Pos);
		if(email.charAt(Pos + 1) == ".")
		{
			return false;
		}

		if(Pos != -1)
		{
			Pos++	;
		}
	}

	atPos = email.indexOf("@",1);		// there must be one "@" symbol
	if (atPos == -1) 
	{
		return false;
	}

	if (email.indexOf("@",atPos+1) != -1) 	// and only one "@" symbol
	{
		return false;
	}

	periodPos = email.indexOf(".",atPos);
	if (periodPos == -1)			// and at least one "." after the "@"
	{
		return false;
	}

	if (periodPos+3 > email.length)		// must be at least 2  characters after the "."
	{
		return false;
	}

	return true;
}

// trims the spaces on either ends of the input and returns the trimmed value.
function trim(inputString) 
{
	fixedTrim = "";
	lastCh = " ";
	for (x = 0; x < inputString.length; x++)
	{
		ch = inputString.charAt(x);
		if ((ch != " ") || (lastCh != " "))
		{
			fixedTrim +=ch; 
		}
		lastCh = ch;
	}

	if (fixedTrim.charAt(fixedTrim.length - 1) == " ")
	{
		fixedTrim = fixedTrim.substring(0, fixedTrim.length -1); 
	}
	return fixedTrim;
}

// US ZipCode Validation
function isUSZip(inputString)
{
	//**********This function checks for valid length and characters for zip code**********
	if (inputString.length!=5) 
		return (false);

	RefString="1234567890";
	for (Count=0; Count < inputString.length; Count++)
	{
		TempChar= inputString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0) == -1) 
		{
			return (false);
		}
	}
	return (true);
}

// functions to populate the date based on the selection of the month and year
var shortMonth = new Array ("02", "04", "06", "09", "11");
function repopulateDays(day)
{
	var iString;
	for (i=day.options.length; i<=31; i++) {
		iString = i + "";
		day.options[i] = new Option(iString, iString);
	}
}

function datePopulation(month, day, year)
{ 
	var selectedMonth = month.options[month.selectedIndex].value;
	var selectedYear = year.options[year.selectedIndex].value;
	var isLeapYear = ((selectedYear % 4)==0) ? true:false;
	var isShortMonth = false;
	var countBackLimit = 32;
		
	if (day.options.length < countBackLimit) repopulateDays(day)

	if (selectedMonth != "") {
		for (i=0; i<shortMonth.length; i++) {
			if (selectedMonth == shortMonth[i]) {
				isShortMonth = true;
				break;
			}
		}
		if (isShortMonth) {
			if (selectedMonth == "02") {
				countBackLimit = 30;
				if ((selectedYear != "") && !(isLeapYear)) {countBackLimit = 29;}
			} else {
				countBackLimit = 31;
			}
			for (j=31; j>=countBackLimit; j--) {
				day.options[j] = null;
			}
		}
	}
}

// check the maximum length of the input field value
function checkInputLength(inputString, maxLength)
{
	if(inputString.length >= maxLength)
	{
		return false;
	}
	return true;
}

// Validates tbe US Phone Number
function isUSPhoneNumber(phonenumber)
{
	var phone1 = phonenumber.substring(0,3);
	var phone2 = phonenumber.substring(3,6);
	var phone3 = phonenumber.substring(6);

 	if(!isInteger(phone1) || (phone1 == 000)) 
	{
        //alert("Please enter a valid areacode")
		return false;
	}

 	if(!isInteger(phone2) || (phone2 == 000)) 
	{
        //alert("Please enter a valid citycode")
		return false;
	}
 	if(!isInteger(phone3)) 
	{
		//alert("Please enter a valid number.")
		return false;
	}

 	if(!((phone1.length == 3) && (phone2.length == 3) && (phone3.length == 4)))
	{
		//alert("Please enter a valid evening phone.")
		return false;
	}
	return true;
}


function showLoading()
{
		document.writeln("<html><head><title>GE Appliances</title>");
		document.writeln("<SCRIPT language='javascript'>javascript:window.history.forward(1);</SCRIPT></head>");		
		document.writeln("<body><br><br><br><br><br><br><br>");
		document.writeln("<table width=\"400\" border=\"0\"><tr align=\"center\"><td>");
		document.writeln("<img src=\"/images/loading.gif\" border=\"0\" alt=\"Loading... Please wait.\" hspace=\"10\">");
		document.writeln("</td></tr></table></body></html>");
}

//From here for Phase 1 clean up
var nav4 = window.Event ? true : false;
var defaultEmptyOK = false;
var whitespace = " \t\n\r";

function launch(url)
 {
 	remote = open(url, "error", "width=600,height=450,left=50,top=50,menubar=no,toolbar=no,scrollbars=no,resizable=no");
 }

function checkLength3(e, phnObj, nxtPhnObj)
 {
  	var key;
  	var shiftkey;
  	var nav4 = window.Event ? true : false;
	if (nav4)
	{
		key = e.which;
		shiftkey = e.modifiers & Event.SHIFT_MASK;
	}
	else
	{
		key = window.event.keyCode;
		shiftkey = window.event.shiftKey;
	}
	if (!(checkKey(key)))
	{
		if (phnObj.value.length == 3)
		{
			nxtPhnObj.focus();
		}
	}
 }
 

 function checkKey(key)
 {
	if ((key == 16) || (key == 8) || (key == 9) || (key == 0))
	{
		return true;
	}
	else
	{
		return false;
	}
 }

 function checkLength4(e, phnObj, nxtPhnObj)
 {
	var key;
	var shiftkey;
	var nav4 = window.Event ? true : false;
	if (nav4)
	{
		key = e.which;
		shiftkey = e.modifiers & Event.SHIFT_MASK;
	}
	else
	{
		key = window.event.keyCode;
		shiftkey = window.event.shiftKey;
	}
	if (!(checkKey(key)))
	{
		if (phnObj.value.length == 4)
		{
			nxtPhnObj.focus();
		}
	}
}

function checkLength7(e, phnObj, nxtPhnObj)
 {
  var key;
  var shiftkey;
  var nav4 = window.Event ? true : false;
  if (nav4)
  {
	key = e.which;
	shiftkey = e.modifiers & Event.SHIFT_MASK;
  }
  else
  {
	key = window.event.keyCode;
	shiftkey = window.event.shiftKey;
  }
  if (!(checkKey(key)))
  {
  	if (phnObj.value.length == 7)
  	{
		if(nxtPhnObj != null){
		nxtPhnObj.focus();
		}
  	}
  }
}

function checkLength7(e, phnObj)
{
	var key;
	var shiftkey;
	var nav4 = window.Event ? true : false;
	if (nav4)
	{
		key = e.which;
		shiftkey = e.modifiers & Event.SHIFT_MASK;
	}
	else
	{
		key = window.event.keyCode;
		shiftkey = window.event.shiftKey;
	}
	if (!(checkKey(key)))
	{
		if (phnObj.value.length == 7)
		{
			//nxtPhnObj.focus();
		}
	}
}

function selectText(txtobj)
{
  	txtobj.select() ;
}

function isEmpty(s)
{
	return ((s == null) || (s.length == 0));
}

function checkProblemDesc(productLine,problemDesc){
	if(problemDesc!=null){
		if(problemDesc=="RECALL - 1997-2001 Rinse Aid"){
			top.location="http://www.geappliances.com/products/recall/dw07/";
			top.target="_blank";
			return false
		}
		else if(problemDesc=="RECALL - 2007 Micro Oven Combo"){
			top.location="http://www.geappliances.com/products/recall/micro_oven_combo/";
			top.target="_blank";
			return false
		}
		else if(problemDesc=="RECALL - Dual Fuel Range"){
			top.location="";
			top.target="_blank";
			return false
		}else if(trim(problemDesc, ' ') == "2010 Front Load Washer recall"){
			top.location="http://www.geappliances.com/products/recall/";
			top.target="_blank";
			return false;
		}else if(trim(problemDesc, ' ') == "2010 Top Control Dishwasher Recall"){
			top.location="http://www.geappliances.com/products/recall/dishwasher_2010/";
			top.target="_blank";
			return false;
		}		
		else{
			return true;
		}
	}
}
//Till here

