function openwindow2(url)
{
        win = window.open(url, 'action', 'titlebar=no,menubar=no,resizable=no,scrollbars=yes,width=400,height=400');
        win.focus();
}
function openSoLincWindow(url)
{
  win = window.open(url,'termsWin', 'width=1000, height=650, resizable=yes, scrollbars=yes,titlebar=yes, menubar=yes');
   win.focus();
}

function preload(){
	var imageLocation = '/southernLincWebApp/images/'; // directory where images are stored
	if(document.images){
		for (var i = 0; i< arguments.length; i++){
			//alert(arguments[i] + '_over');
			self[arguments[i] + '_over'] = new Image();
			self[arguments[i] + '_over'].src = imageLocation + arguments[i] + '_over.gif';
			self[arguments[i] + '_off'] = new Image();
			self[arguments[i] + '_off'].src = imageLocation + arguments[i] + '.gif';
		}
	}
}

function rollover(src, state){
	if (document.images && self[src + '_' + state]){
		document.images[src].src = self[src + '_' + state].src;
	}
}

function submitPage(formObj,commandvalue) {
	 try {
	    //var pageoffset = document.all("pager.offset");
	    //alert("0");
	    var pageoffset = document.getElementById("pageroffset");
	    //alert("1");
	    if (pageoffset) {
	    	//document.all("pager.offset").value = 0;
	    	pageoffset.value = 0;
	    	//alert(document.all("pager.offset").value);
	    }
	    //alert("2");
	    if (formObj.pagenumberclicked)
			formObj.pagenumberclicked.value = "0";
		//document.all("command").value=commandvalue;
	    //alert("3");			    
		formObj.command.value=commandvalue;
		//alert(formObj.command.value);
		formObj.submit();
	  }
	  catch(Exception ) {
	  	//alert("inException");

	  }
	 
}

//This function fired when a page number from search results is clicked on .

	function submitsearch(formname,act,commandvalue,ignoreDevice) {
		//var formObj = document.forms['ringtoneForm'];
		//var formObj = document.all(formname);
		var games = "games";
		var app = "app";
		var pos = act.indexOf("?");
		var querystring = act.substr(pos);
		//alert(querystring);
		//alert("ignoreDevice:" +ignoreDevice);
		var formObj = document.forms[formname];
		try {
			if (formObj) {
			    //var a = document.all("pager.offset").value;
			    var action = "";
			    if (formname.indexOf(games)!= -1){
			    	action = "/SouthernLincWebApp/games.do"+querystring;
			    	
			    	if(ignoreDevice != null && ignoreDevice == "true" )
			    	action = action +"&ignoreDevice=true";
			    	
			    }
			    if (formname.indexOf(app) != -1){
			    	action = "/SouthernLincWebApp/applications.do"+querystring;
			    	
			    	if(ignoreDevice != null && ignoreDevice == "true" )
			    	action = action +"&ignoreDevice=true";
			    	
			    }	
			    //alert(action);
			    var a = document.getElementById("pageroffset").value;
			    //alert(a);
				formObj.command.value=commandvalue;
				if (formObj.pagenumberclicked)
					formObj.pagenumberclicked.value = "1";
				//alert(formObj.command.value);
				//formObj.action = act;
				formObj.action = action;
				formObj.submit();
			}
			
		}
		catch(Exception) {
			//alert("InException");
		}
	}

//usage
//<a href="=" onClick="return goTo(document.forms['ringtoneForm'],'/mam/showAccountsforpmamadmin.do?<%=(SessionConstants.COMMAND)%>=<%=(SessionConstants.COMMAND_CONTINUE)%>');return false;">
function goTo(formObj,action) 
{ 
	formObj.action = action; 	
	formObj.submit();return false; 
} 

function CheckPhoneNumber(PhoneNo,TagStr)

{

	// get rid of non-numerics

	var checkOK = new String("0123456789");
	//var strNo = new String(PhoneNo);
	var strNo = PhoneNo;
	
	if (strNo == 'undefined' || strNo == null || strNo.length < 1) {
		alert("Phone Number cannot be blank");
		return false;
	}

	PhoneNo="";
	for ( i = 0; i < strNo.length; i++ )

	{
		ch = strNo.charAt(i);

		for (j = 0;  j < checkOK.length;  j++)

			if (ch == checkOK.charAt(j))

				break;

		if (j != checkOK.length)

		{
			PhoneNo=String(PhoneNo)+String(ch);
		}
	}

	// get rid of leading 1

	if ( ( PhoneNo.length == 11 ) && ( PhoneNo.charAt(0) == 1 ) )

	{

		PhoneNo = PhoneNo.substr(1,10);

	}



	if ( (PhoneNo.length != 0) && (PhoneNo.length < 10) )
	{
		alert("Please enter exactly 10 digits in \"" + TagStr + "\".");
		PhoneNo.focus();
		return false;
	}

	if (PhoneNo.length > 10)
	{
		alert("Please enter exactly 10 digits in \"" + TagStr + "\".");
		PhoneNo.focus();
		return false;
	}

	var checkStr = PhoneNo;
	var allValid = true;
	var decPoints = 0;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}
	if (!allValid)
	{
		alert("Please enter only digits in \"" + TagStr + "\".");

		PhoneNo.focus();

		return false;

	}
	if ( checkStr.length == 10 )
	{
		if ( checkStr.charAt(0) < '2' )
		{
			alert("The first digit of the area code in \"" + TagStr + "\" cannot be a '1' or '0'");

			PhoneNo.focus();

			return false;

		}
		if ( checkStr.charAt(3) < '2' )
		{
			alert("The first digit of the prefix in \"" + TagStr + "\" cannot be a '1' or '0'");

			PhoneNo.focus();

			return false;

		}
		if ( checkStr.substring(0,3) == "900" )
		{
			alert("The area code in \"" + TagStr + "\" cannot be '900'");
			PhoneNo.focus();
			return false;
		}
	}
	
	//else {
		return true;
		//alert("OK");
	//}	
}

// -------------------------------------------------------------------
// tabNext(input_object)
//   Pass an form input object. Will focus() the next field in the form
//   after the passed element.
//   a) Will not focus to hidden or disabled fields
//   b) If end of form is reached, it will loop to beginning
//   c) If it loops through and reaches the original field again without
//      finding a valid field to focus, it stops
// -------------------------------------------------------------------
function tabNext(obj) {
	//alert(" PLatform : " + navigator.platform.toUpperCase());
	if (navigator.platform.toUpperCase().indexOf("SUNOS") != -1) {
		obj.blur(); return; // Sun's onFocus() is messed up
		}
	var theform = obj.form;
	//alert(theform.name);
	var tabtonext = false;
	var i = getElementIndex(obj);
	//alert(i);
	var j=i+1;
	if (j >= theform.elements.length) { j=0; }
	if (i == -1) { return; }
	while (j != i) {
		if ((theform.elements[i].name!="ptn1") && (theform.elements[i].name!="ptn2"))
			return;
		if ((theform.elements[i].name =="ptn1")) {
			var len = theform.elements[i].value.length;
			//alert(len);
			if (len == 3) {
				tabtonext = true;
				//alert("entered");
			}
		}
		if ((theform.elements[i].name =="ptn2")) {
			var len = theform.elements[i].value.length;
			if (len == 3)
				tabtonext = true;
		}
		//alert(tabtonext);
		if ((theform.elements[j].type!="hidden") && 
		    (theform.elements[j].name != theform.elements[i].name) && 
			(!theform.elements[j].disabled) && tabtonext) {
			theform.elements[j].focus();
			break;
			}
		j++;
		if (j >= theform.elements.length) { j=0; }
		}
}

//-------------------------------------------------------------------
// getElementIndex(input_object)
//   Pass an input object, returns index in form.elements[] for the object
//   Returns -1 if error
//-------------------------------------------------------------------
function getElementIndex(obj) {
	var theform = obj.form;
	for (var i=0; i<theform.elements.length; i++) {
		if (obj.name == theform.elements[i].name) {
			return i;
			}
		}
	return -1;
	}

// added in 11/05/06
//-------------------------------------------------------------------

//-------------------------------------------------------------------
function submitTheSearch(appType) {
	  //alert("in submitTheSearch the appType is:" + appType);
		var searchval = '';
		var formName='';
        var action = '';
        
		
		if (appType =='games')
		{
		  formName='gamesForm';
		  action='gamesbytitle';
		   //alert("1");
		  //alert("formname: "+document.forms['form1'].formname.value);
		 document.forms[formName].formname.value=document.forms['form1'].formname.value;
		}
		else if(appType =='applications')
		{
			formName='appForm';
			action='appbytitle';
			document.forms[formName].formname.value=document.forms['form1'].formname.value;
		}
		//alert("2");
		var searchval1 = document.forms['form1'].searchvalue.value;
		//alert("Search Value in Form : " + searchval1);
		if(searchval1 != ''){
		document.forms[formName].searchvalue.value = searchval1;
		}
		// end of add
		if (searchval1 == 'undefined' || searchval1 == '' || searchval1.length < 3 ) {
		
		    alert("Please type at least 3 characters for search");
			return;
		}
	
		document.forms[formName].rowcount.value='';
		document.forms[formName].sortby.value='';
		document.forms[formName].sortorder.value='';
		
        //alert("rowcount:" +  document.forms[formName].rowcount.value +" , formname: "  + formName);
		submitPage(document.forms[formName],action);
	}

// added in 11/05/06
//-------------------------------------------------------------------

//-------------------------------------------------------------------
function submitAdvanceSearch(appType) {
	 // alert("in submitAdvanceSearch the appType is:" + appType);
		var searchval = '';
		var formName='';
        var action = '';
        
		
		if (appType =='games')
		{
		  formName='gamesForm';
		  action='advancedsearch';
		}
		else if(appType =='applications')
		{
			formName='appForm';
			action='advancedsearch';
		}

	
		document.forms[formName].rowcount.value='';
		 //alert("rowcount:" +  document.forms[formName].rowcount.value);
		document.forms[formName].sortby.value='';
		document.forms[formName].sortorder.value='';
		document.forms[formName].formname.value=formName;
        //alert("formname: "  + formName);
		submitPage(document.forms[formName],action);
	}




