function openPage(url,target,width,height) {
	if (target != "_self" && (width != null && width != "") && (height != null && height != "")) {
			win = window.open(url,target,'scrollbars=1,status=1,location=1,resizable=1,width='+width+',height='+height);
			win.focus();
	}
	else {
		win = window.open(url,"_self");
		win.focus();
	}
}
	
function close_ann(){
	Effect.Pulsate('ann', {duration:0.7}); 
	window.setTimeout(function() {Effect.SlideUp('ann')}, 700);
	window.setTimeout(function() {Effect.SlideUp('ann')}, 700);  
	window.setTimeout(function() {document.getElementById('ann2').style.display="block";}, 1600);
	return;
	//document.getElementById('ann').style.display="none";
	}

function changeImageOv(whichElement){
	document.getElementById(whichElement).src = '$contextPath/resources/web/common/images/home_menu_arrow_pink.gif';
}

function changeImageOut(whichElement){
	document.getElementById(whichElement).src = '$contextPath/resources/web/common/images/home_menu_arrow.gif';
}

function sL(layerName){
	for(var i=1;i<=30;i++){
		hL('submenu'+i);
	}
	if(document.getElementById(layerName).style.display == 'block'){
		hL(layerName);
	}else{
		document.getElementById(layerName).style.display="block";
	}
}

function hL(layerName){
	if(document.getElementById(layerName)){
		document.getElementById(layerName).style.display="none";
	}
}

function showtab(tabn){
	//hide all tab contents
	for(var i=1;i<=8;i++){
		if(document.getElementById('tab'+i)){
			var aux = document.getElementById('tab'+i);
			aux.style.display = 'none';
			
			var aux = document.getElementById('tdtab'+i);
			var aux2 = document.getElementById('tdlink'+i);
			aux.className = 'tabitemgray';
			aux2.className = 'tabitemgray';
			
		}
	}

	//show current tab
	var aux = document.getElementById('tab'+tabn);
	aux.style.display = 'block';
	var aux2 = document.getElementById('tdtab'+tabn);
	var aux3 = document.getElementById('tdlink'+tabn);
	aux2.className = 'tabitemblue';
	aux3.className = 'tabitemblue';
	
	//highlight menu
	count = 1;
	while(document.getElementById('help_tab_'+count)) {
		if (count == tabn) {
		var menuLink = document.getElementById('help_tab_'+tabn);
		menuLink.className = 'submenuselected';
		document.getElementById("help_arrow_"+tabn).src = "/autoforms/resources/web/common/images/submenu_pink_arrow.gif";
		}else {
			document.getElementById('help_tab_'+count).className = 'smenu';
			document.getElementById("help_arrow_"+count).src = "/autoforms/resources/web/common/images/submenu_arrow.gif";
		}
	count++;	
	}
	scroller.init();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//scroller script

var scroller = {
  init:   function() {

//document.getElementById("container").style.height="460px";
    scroller.docH = document.getElementById("content").offsetHeight;
    scroller.contH = document.getElementById("container").offsetHeight;
    scroller.scrollAreaH = document.getElementById("scrollArea").offsetHeight;
	//alert(scroller.scrollAreaH);
     if(scroller.docH > scroller.contH)
	 {
	 document.getElementById("scrollArea").style.visibility='visible';
 scroller.scrollH = (scroller.contH * scroller.scrollAreaH) / scroller.docH;
 //if(scroller.scrollH < 15) scroller.scrollH = 15;
 document.getElementById("scroller").style.height = "32px";

 scroller.scrollDist = Math.round(scroller.scrollAreaH-scroller.scrollH);
 // alert(scroller.scrollDist);

 Drag.init(document.getElementById("scroller"),null,0,0,-1,scroller.scrollDist);
 
 //add ondrag function
 document.getElementById("scroller").onDrag = function (x,y) {
 var scrollY = parseInt(document.getElementById("scroller").style.top);
 var docY = 0 - ((scrollY * (scroller.docH - scroller.contH) / scroller.scrollDist));
 document.getElementById("content").style.top =  docY + "px";
	  } 
    }
  }
}

/*start scroller*/
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
/*end scroller*/

/* Login functions */
function doLogin(){
	if(!window.event) { return; }
   	if(window.event.keyCode == 13) { document.forms.loginForm.submit(); }
}

function validate(form) {
	phone = form.username.value;
	password = form.password.value;
	if (phone == null || phone == "") {
		alert("Phone number is required.")
		return false;
	}
	else if (!isPhone(phone)) {
		alert("Please enter a valid mobile number");
		form.username.focus();
		return false;
	}
	else if (password == null || password == "") {
		alert("Password is required");
		return false;
	}
	return true;
}

function isPhone(sText)

{
   var ValidChars = "0123456789+";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
   function validateSearch(form) {
		q = form.keywords.value;
		if (q.length == 0 || q.replace(/^ +/, '').replace(/ +$/, '') == "") return false;
		else form.submit();
	} 
