<!-- 

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkLongWord(s) {
    var len = s.length;	
    // get the initial position to start checking
    var idx1 = 0;
    while (idx1 < len) {
        // get the next position (delimited by space)
		var idx2 = s.indexOf(" ", idx1+1);
		var t2 = s.indexOf("\n", idx1+1);
		if (idx2 == -1) idx2 = len;
		if (t2 == -1) t2 = len;
		if (idx2 > t2) idx2 = t2;
//		if (idx2 > t2 && t2!= -1) idx2 = t2;
        // if space cannot be found, the entire string is considered one word
//        if (idx2 == -1) {
//            idx2 = len;
//        }
        // the length of one word is assumed to be the number of chars between 2 spaces
        var word_len = idx2 - idx1;
        // maximum word length can be changed here
        if (word_len > 40) {
            var long_word=s.substring(idx1, idx2)
            //alert ("The word, '" + long_word + "' is extraordinarily long! Please shorten it.");
            return false;
        }
        // prepare for next loop
        idx1 = idx2;
    }
    return true;
}

//param Word = the string which you want to check for HTML tags
//return true if Word contains html tag(s), false otherwise
function hasHTML(Word) 
{
	tags = new Array(26);
	tags[1] = "html";	tags[2] = "head";	tags[3] = "body";	
	tags[4] = "title";	tags[5] = "meta";	tags[6] = "applet";
	tags[7] = "font";	tags[8] = "table";	tags[9] = "img";
	tags[10] = "input";	tags[11] = "b";		tags[12] = "i";
	tags[13] = "u";		tags[14] = "a";		tags[15] = "tr";
	tags[16] = "td";	tags[17] = "big";	tags[18] = "small";
	tags[19] = "div";	tags[20] = "li";	tags[21] = "uo";
	tags[22] = "ol";	tags[23] = "option";tags[24] = "select";
	tags[25] = "script";tags[26] = "p";		tags[27] = "h1";
	tags[28] = "h2";	tags[29] = "h3";	tags[30] = "h4";
	tags[31] = "h5";
	
	len = Word.length;
	var pointer = 0;
	
	a = Word.indexOf("<");
	b = Word.indexOf(">");
	while(b<a && pointer<len) //while > doesn't come after <
	{
		pointer = a;
		a = Word.indexOf("<",pointer);
		b = Word.indexOf(">",pointer);
		if ( a==-1 || b==-1 )
			break;				//to break from loop or else infinite
	}
	if (b>a) //if > comes after <	
	{
		inbetween = Word.substring(a+1, b);
		inbetween = inbetween.toLowerCase();
		//alert(inbetween);
		//alert("inbetween='"+inbetween+"'")
		for(i=1; i<=31; i++)
		{
			index = inbetween.indexOf(tags[i]);
			//alert("tag='" + tags[i] + "'");
			//alert("index=" + index);
			if( index != -1 )
			{
				return true;
			}
		}
	}
	return false;
}

// This function will trim leading and/or trailing spaces from a string
// arg = the value you wish to have trimmed..
// func = "left" for trimming left-hand-side spaces, 
//        "right" for trimming right-hand-side spaces, or
//        "both" for trimming both left and right-hand-side spaces
function trim(arg,func) 
{
	var trimvalue = "";
	arglen = arg.length;
	if (arglen < 1) { return trimvalue; }
	if (func == "left" || func== "both") 
	{
		var i = 0;
		pos = -1;
		while (i < arglen) 
		{
			if (arg.charCodeAt(i) != 32 &&
				!isNaN(arg.charCodeAt(i))) 
			{
				pos = i;
				break;
			}
			i++;
		}
	}

	if (func == "right" || func== "both") 
	{
		var lastpos = -1;
		var j = arglen;
		while (j >= 0) 
		{
			if (arg.charCodeAt(j) != 32 &&
				!isNaN(arg.charCodeAt(j))) 
			{
				lastpos = j;
				break;
			}
			j--;
		}
	}

	if (func == "left")  {
		trimvalue = arg.substring(pos,arglen-1);
	}

	if (func == "right") {
		trimvalue = arg.substring(0,lastpos+1);
	}

	if (func == "both") {
		trimvalue = arg.substring(pos,lastpos + 1);
	}
	
	return trimvalue;
}


function validate()
{
	var totalPages = document.gotoPage.totalpg.value;
	var num = "01233456789";
	var ok = "yes";
	var pageNo = document.gotoPage.idx.value;

	if(trim(pageNo, 'both') == "")
	{
		alert("Please specify page number.");
			return false;
	}
	else
	{
		for(var m=0; m<pageNo.length; m++) 
		{
			temp = pageNo.substring(m,m+1);
			
			if(num.indexOf(temp) == "-1") ok = "no";
			
		}
		
		if(ok == "no") 
		{
			alert("Page Number is invalid. Use only numbers! ");
			ok = "yes";
			document.gotoPage.idx.value = "";
			document.gotoPage.idx.focus();
			return false;
		}
         totalPages=parseInt(totalPages);
		   pageNo=parseInt(pageNo);
		if( totalPages < pageNo)
		{
			alert("Go to page cannot greater than total number of pages. ");
			return false;
		}
		
		if(pageNo <=0)
		{
			alert("Go to page must be greater than 0. ");
			return false;
		}
		
	}
	return true;

}

/*
$Log: script.js,v $
Revision 1.2  2007/04/26 09:48:45  Yangjer
update from eAsia2u3

Revision 1.1  2007/01/12 22:33:27  wsy
*** empty log message ***

Revision 1.1  2006/10/20 22:49:26  wsy
*** empty log message ***

Revision 1.3  2006/04/26 21:31:31  angelo
checking when use go to page function

Revision 1.2  2006/04/07 18:41:24  angelo
template9 for matta

Revision 1.1  2006/03/10 04:56:06  wsy
*** empty log message ***

Revision 1.4  2002/07/10 02:18:41  lichuen
fix bugs in checkLongWord function. Bug desc: when there's no space (only \n), the validation will return false (should be true)

Revision 1.3  2002/03/21 11:00:56  lichuen
modify checkLongWord to include newline("\n") as delimiter. Previously, the delimiter is only space " ".

Revision 1.2  2002/02/25 10:48:56  lichuen
modify checkLongWord to include newline("\n") as delimiter. Previously, the delimiter is only space " ".

Revision 1.1  2001/12/13 02:21:22  mmang
copy from whatdevice_mpsb

Revision 1.1.1.1  2001/10/05 11:20:34  lousai
Added By kllow

Revision 1.1.1.1  2001/10/04 09:41:48  sina11
no message

Revision 1.1.1.1  2001/10/02 17:06:09  lousai
This is the new structure for MPSB Engine.

Revision 1.1.1.1  2001/10/02 16:34:34  lousai
This is the new structure for MPSB Engine.

Revision 1.7  2001/09/26 08:19:17  kim
edited variable "i" to be local

Revision 1.6  2001/09/26 04:27:57  kim
took out alert("mm")

Revision 1.5  2001/09/25 11:19:30  kim
added a trim() function

Revision 1.4  2001/09/06 07:43:09  kim
added more tags to be checked in hasHTMLL();

Revision 1.3  2001/09/04 02:00:55  kim
fix upper lower case checking (took out alert).

Revision 1.2  2001/09/03 05:58:29  kim
fix upper lower case checking.

Revision 1.1  2001/08/24 14:18:59  lichuen
first installation for whatdevice 2

Revision 1.4  2001/07/18 10:43:05  lichuen
modify method checkLongWord() to change max length fr 30 to 25 and remove the alert message

Revision 1.3  2001/07/12 11:01:50  kim
added function hasHTML()

Revision 1.2  2001/07/12 03:57:06  lichuen
add function checkLongWord to check for long words

*/

// end of script -->
