

var isIE5 = false;
var isIE4 = false; 
var isIE = false;
if (navigator.appName == "Microsoft Internet Explorer")
{
	isIE = true;
	if ( navigator.appVersion.indexOf("5.")!= -1)
		isIE5 = true;
	else
		if ( navigator.appVersion.indexOf("4.")!= -1)
			isIE4 = true;
}

var isNS = (navigator.appName == "Netscape");
var layerRef = (isNS) ? "document" : "document.all";
var styleRef = (isNS) ? "" : ".style";
var menuTimeOut   = null;
var layerID = "pictframe";
if (isNS)
{
	document.captureEvents(Event.MOUSEMOVE) 
}

document.onmousemove = FindXY;

function FindXY(loc)
{
	if (document.layers)
	{
		xpos = 650;
		ypos = loc.y - 50;
	}
	else
	{
		if (isIE5)
		{
			xpos = 650;
			ypos = document.body.scrollTop + event.clientY - 50;
			
		}
		else if (isIE4)
		{
			xpos = 650;
			ypos = event.y - 50;
		}
	}
}
function showLayer(imgName)
{
	clearTimeout(menuTimeOut);
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.top = ypos');
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.left = xpos');
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.backgroundImage = "URL(' + imgName + ')";');
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.backgroundRepeat = "no-repeat";');
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.visibility = "visible"');	
}

function hideLayer()
{
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.visibility = "hidden"');
	   
}

//used as the onMouseOut handler on the menu. deactivates the menu by hiding it and restoring its
//default buttons. uses old image handling routines
function deactivateMenu()
{
	menuTimeOut = setTimeout('hideLayer()',300);
}
/*
function openWin(URL,width,height,win_name)
{
	aWindow=window.open(URL,win_name,'width='+width+',height='+height+',top=230,left=320');
}
*/
function showPrev(url,p_id)
{
	document.location.href = "\"" + url + "?" + p_id;
}
aWindow = null;

function openWindow(URL,winHeight,winWidth) 
{                                      //leftPos = 0
	var p_height, p_width;
	
	closeWindow();
	
	if(winHeight == null && winWidth == null)
	{
		p_height = p_width = 160;
	}
	else
	{
		p_height = winHeight;
		p_width  = winWidth;
	}  
	if(screen)
	{
           leftPos = screen.width - 440-20
	}
	if(isNS)
	{
		aWindow = window.open(URL,'theWindow','scrollbars=yes,width='+p_width+',height='+p_height+',screenX=50,screenY=100');
	}
	else
	{
		aWindow = window.open(URL,'theWindow','scrollbars=yes,width='+p_width+',height='+p_height+',left=50,top=100');
	}
	return false;
   
}
function closeWindow()
{
	if(aWindow && aWindow.open && !aWindow.closed)
	{
       aWindow.close();
	}
}	
/*function openWindow(url)
{
	var windHeight = 400;
	var windWidth = 600;
   if(screen)
	{
		var windHeight = screen.height - 250;
		var windWidth = screen.width - 200;
	}
	else
	{
		var windHeight = 500;
		var windWidth = 700;
	}
	if(isNS)
	{
		aWin = window.open(url,"links","location=1,height="+windHeight+",menubar,resizable,screenX=150,screenY=50,scrollbars,status,titlebar,toolbar,width="+windWidth)
	}	
	else
	{
		aWin = window.open(url,"links","location=1,height="+windHeight+",menubar,resizable,left=150,top=50,scrollbars,status,titlebar,toolbar,width="+windWidth)
	}
	return false;

}*/
// This function will force reloading frameset from server when user resizing NC browser window.
// Call for this function have to be in BODY tag of rightframe JSP file.

function reload()
{
	if(isNS){
		forceReloadFromServer = true;
		window.location.reload(forceReloadFromServer);
	}	
}
function validForm(form) 
{
  if(!validEmail(form.email.value))
  {
     form.email.focus()
     return false
  }
  if(!validSubject(form.subject.value))
  { 
     form.subject.focus()
     return false
  }
  if(!validMessage(form.message.value))
  {
     form.message.focus()
     return false
   }   
return true
}

function validEmail(email)
{
   if(isBlank(email))                                                  // email blank?
   {
     alert("Enter please your email!")
     return false 
   }
   var atsignPos = email.indexOf("@", 0)                   // check for @  
   if ( atsignPos == -1)
   {
      alert("Enter a valid Email address with an @, please!")
      return false
   }
   if (email.indexOf(".", atsignPos) == -1 )                 // check for . after @
   {
      alert("Enter a valid Email domain after @, please!")
      return false
   }
return true 
}
function validSubject(subject)
{
   if(isBlank(subject))
   {
      alert("Enter please the Subject of your message!")
      return false
   }
return true    
}
function validMessage(message)
{
    if(isBlank(message))
   {
      alert("Enter please message!")
      return false
   }
return true    
}   
function isBlank(testStr)
{
  if(testStr.length == 0)                          // nothing entered? 
    return true
  for (var i = 0; i <= testStr.length-1; i++) // all spaces?     
    if (testStr.charAt(i) != " ")
       return false
  return true
}
function isNum(testStr)
{
	for(var i=0; i < testStr.length; i++)
	{
		var testChar = testStr.charAt(i);
		if(testChar < "0" || testChar > "9")
		   return false;
	}
 return true;
}
function changeAll(form,chkBox)
{
	var checkBox = eval("form." + chkBox);
	if(checkBox.checked == false)
	{
		for(var i=0; i<form.elements.length; i++)
		{
			if(form.elements[i].type == "checkbox")
			{
				form.elements[i].checked = false;
			}			
		}
	}
	else
	{
		for(var i=0; i<form.elements.length; i++)
		{
			if(form.elements[i].type == "checkbox")
			{
				form.elements[i].checked = true;
			}			
		}
	}
}

function validateChecked(formname)
{
   var thisForm = eval("document." + formname);
   for(var i=0; i < thisForm.elements.length; i++)
   {
       if(thisForm.elements[i].type =="checkbox" && thisForm.elements[i].checked)
       {
           return true;
       }
   }
   return false;
}

function casheImages(arrImages, arrNames)
{
	targetframe = parent.casheframe;

	strBody =   "<html>\n" +
               "<head></head>\n" +
               "<body>\n";
   for (var i=0; i<arrImages.length; i++) 
   {
     strBody +="<img name='card" + arrNames[i] + "' src='" + arrImages[i] + "'><br>\n";
   }
      
    strBody +=  "</body>\n" +
               "</html>";
   targetframe.document.open("text/html","replace");
   targetframe.document.write(strBody);
   targetframe.document.close();
}
function trim(strTr)
{
   var resultStr = strTr;
   if(strTr.indexOf(" ") != -1)
   {
      for(var i=0; i<= strTr.length; i++)
      {
         if(strTr.charAt(i) == " ")
         {
            resultStr = strTr.substring(i+1,strTr.length);
            continue;
         }
         strTr = resultStr;
         break;
      }
   }
   if(strTr.indexOf(" ") !=-1)
   {
      for(var j = (strTr.length-1); j >= 0; j--)
      {
         if(strTr.charAt(j) == " ")
         {
            resultStr = strTr.substring(0,j);
            continue;
         }
         strTr = resultStr;
         break;
      }
   }
   return strTr;
}

function checkSelect(selectObj)
{
   userChoice = selectObj.selectedIndex;
   if(selectObj.options[userChoice].value == "")
   {
       return false;
   }
   return true;
}
function getSelectText(selectList)
{
   userChoice = selectList.selectedIndex;
   return selectList.options[userChoice].text;			
}