function isEmailAddr(email)
{
	var result = false;
	var theStr = new String(email);
	var index = theStr.indexOf("@");
	if (index > 0)
	{
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	}
	return result;
}
function CongreeMen(operation,val1,page)
{

	if(val1=='')
	{
		alert("Please select congressmen")
		return false;		
	}
	window.location = "congressmen.php?value="+operation+"&userId="+val1+"&page="+page;
}

function check()
{
//	var phoneRE = /^([a-z]|_([a-z0-9]|$))([a-z0-9]|_([a-z0-9]|$))*$/;
	var phoneRE = /^([a-zA-Z]|_([a-zA-Z0-9]|$))([a-zA-Z0-9]|_([a-zA-Z0-9]|$))*$/;	
	if(document.register.userName.value.match(phoneRE))
	{
	}
	else
	{
		alert("Please use alphabets and numerics and not empty space for screen name ")
		document.register.userName.focus();
		return false;		
	}
	//alert('none');
	if(!isEmailAddr(document.register.email.value))
		{
			alert("Please provide correct email in the form: yourname@yourdomain.com");
			document.register.email.focus();
			return false;
		}
	if(document.register.email.value != document.register.c_email.value)
	{
		alert("Email addresses do not match. Please confirm the email address you have entered.")
		document.register.email.focus();
		return false;		
	}	

	if(document.register.u_password.value=="")
	{
		alert("Please enter password")
		document.register.u_password.focus();
		return false;		
	}
	if(document.register.u_password.value.length<5)
	{
		alert("Password entered is too short. it should be at least 5 charactes in length")
		document.register.u_password.focus();
		return false;		
	}
	if(document.register.u_password.value != document.register.u_password_c.value)
	{
		alert("Your supplied passwords do not match.")
		document.register.u_password_c.focus();
		return false;		
	}	

	if(document.register.zip.value=="")
	{
		alert("Please enter zip code")
		document.register.zip.focus();
		return false;		
	}
}

function checkRadio()
{
//	var phoneRE = /^([a-z]|_([a-z0-9]|$))([a-z0-9]|_([a-z0-9]|$))*$/;
	var phoneRE = /^([a-zA-Z]|_([a-zA-Z0-9]|$))([a-zA-Z0-9]|_([a-zA-Z0-9]|$))*$/;	
	if(document.register.userName.value.match(phoneRE))
	{
	}
	else
	{
		alert("Please use alphabets and numerics and not empty space for screen name ")
		document.register.userName.focus();
		return false;		
	}
	//alert('none');
	if(document.register.u_password.value=="")
	{
		alert("Please enter password")
		document.register.u_password.focus();
		return false;		
	}
	if(document.register.u_password.value.length<5)
	{
		alert("Password entered is too short. it should be at least 5 charactes in length")
		document.register.u_password.focus();
		return false;		
	}
	if(document.register.u_password.value != document.register.u_password_c.value)
	{
		alert("Your supplied passwords do not match.")
		document.register.u_password_c.focus();
		return false;		
	}	
	if(document.register.contactName.value=="")
	{
		alert("Please enter Contact Name")
		document.register.contactName.focus();
		return false;		
	}	
	if(document.register.contactEmail.value=="")
	{
		alert("Please enter Contact Email")
		document.register.contactEmail.focus();
		return false;		
	}	
	if(!isEmailAddr(document.register.contactEmail.value))
		{
			alert("Please provide correct email in the form: yourname@yourdomain.com");
			document.register.contactEmail.focus();
			return false;
		}
	if(document.register.contactPhone.value=="")
	{
		alert("Please enter Contact Phone number")
		document.register.contactPhone.focus();
		return false;		
	}	
	if(document.register.websiteName.value=="")
	{
		alert("Please enter Website Name")
		document.register.websiteName.focus();
		return false;		
	}	
	if(document.register.websiteUrl.value=="")
	{
		alert("Please enter Website URL")
		document.register.websiteUrl.focus();
		return false;		
	}	

}
/*---------------- Add Element to <UL> -------------------*/
function addElement(url,tabName,billId,type){
	// THis is the <ul id="myList"> element that will contains the new elements
							
	var tab_id = document.getElementById('bid_'+billId);
	if(tab_id!=null){
//		alert('tab already opened');
		var tab_a =tab_id.firstChild; 
		activateIt(tab_a,billId);
		return false;
		}
	var container = document.getElementById('tabmenu');
	var billsTab = document.getElementById('congBills');
	var allLi = container.getElementsByTagName("li");
	var tmp_n =document.getElementById('innerRightAds');
	if(tmp_n!=null){
		document.getElementById('innerRightAds').style.display='none';
		document.getElementById('innerLeft').style.width='900px';
	}

	billsTab.removeAttribute("className");
	billsTab.removeAttribute("class");

	for(i=0; i<allLi.length; i++){
			if(allLi[i].id!='congBills'){
			  var olddiv = document.getElementById(allLi[i].id);
			  container.removeChild(olddiv);

			}
		}
	
	// Create a new <li> element for to insert inside <ul id="myList">
	var new_element = document.createElement('li');
	new_element.innerHTML = '<a href="#" onclick="activateIt(this,'+billId+','+type+'); return false;" ><span>'+tabName+'</span> </a>';
	new_element.id = 'bid_'+billId;
	new_element.className = 'current';
	container.appendChild(new_element, container.firstChild);
	container.innerHTML +='\t\n'; 
	document.getElementById('billFrameId').src=url;
	document.getElementById('content').style.display='none';
	document.getElementById('billFrame').style.display='block';
	
	}

/*---------------- Add Element to <UL> -------------------*/
/*
function addElement(url,tabName,billId,type){
	// THis is the <ul id="myList"> element that will contains the new elements
							
	var tab_id = document.getElementById('bid_'+billId);
	if(tab_id!=null){
//		alert('tab already opened');
		var tab_a =tab_id.firstChild; 
		activateIt(tab_a,billId);
		return false;
		}
	var container = document.getElementById('tabmenu');
	var allLi = container.getElementsByTagName("li");
	var len = allLi.length;
	if(len>2){
		alert('Limit for Maximum number of opened tabs reached.');		
		return false;
	} else {
		var tmp_n =document.getElementById('innerRightAds');
		if(tmp_n!=null){
			document.getElementById('innerRightAds').style.display='none';
			document.getElementById('innerLeft').style.width='900px';
		}
	}

	for(i=0; i<allLi.length; i++){
		if(allLi[i].className=='current'){
			allLi[i].removeAttribute("className");
			allLi[i].removeAttribute("class");
			}
		}
	
	// Create a new <li> element for to insert inside <ul id="myList">
	var new_element = document.createElement('li');
	new_element.innerHTML = '<a href="#" onclick="activateIt(this,'+billId+','+type+'); return false;" ><span>'+tabName+'</span> </a>';
	new_element.id = 'bid_'+billId;
	new_element.className = 'current';
	container.appendChild(new_element, container.firstChild);
	container.innerHTML +='\t\n'; 
	document.getElementById('billFrameId').src=url;
	document.getElementById('content').style.display='none';
	document.getElementById('billFrame').style.display='block';
	
	}
*/
/*---------------- Show Bill  -------------------*/
function showBill(url,tabName,billId,type){
	document.getElementById('billFrameId').src=url;
	document.getElementById('content').style.display='none';
	document.getElementById('billFrame').style.display='block';
	
	}
/*---------------- End Show Bill ----------------*/

function activateIt(obj,billId,type){
	
	var container = document.getElementById('tabmenu');
	var allLi = container.getElementsByTagName("li");
	var len = allLi.length;
	for(i=0; i<allLi.length; i++){
		if(allLi[i].className=='current'){
			allLi[i].removeAttribute("className");
			allLi[i].removeAttribute("class");
			}
		}
	if(type==2){
		var url = 'billdescription';
		} 
	else  {
		var url = 'billdetail2';
		}
	obj.parentNode.className='current';
	if(billId!=0){
		document.getElementById('billFrameId').src=url+'.php?billid=' + billId;;
		document.getElementById('content').style.display='none';
		document.getElementById('billFrame').style.display='block';
		if(document.getElementById('innerRightAds')!=null){
			document.getElementById('innerRightAds').style.display='none';
			document.getElementById('innerLeft').style.width='900px';
		}
	}
	else 
	{
		document.getElementById('billFrame').style.display='none';
		document.getElementById('content').style.display='block';
		document.getElementById('billFrameId').src='loading.html';
		if(document.getElementById('innerRightAds')!=null){
			document.getElementById('innerRightAds').style.display='block';
			document.getElementById('innerLeft').style.width='';
		}
	}
}


function closeIt(obj){
	var container = document.getElementById('tabmenu');
	var billListObj = document.getElementById('congBills');
	container.removeChild(obj.parentNode);
	document.getElementById('billFrameId').src='loading.html';
	activateIt(billListObj,0);
	}
/*---------------- End : Add Element to <UL> -------------------*/
function toggleLogin(val){
	var obj = document.getElementById('loginMenu');
	if(val==0 && obj.style.display=='block'){
		obj.style.display='none';
		}
	else if(val==1 && obj.style.display!='block'){
		obj.style.display='block';
		}
	}

/*---------------- Select All user to send email on emailToUsers.php -------------------*/
function cA(field){
for(i=0,n=field.elements.length;i<n;i++)
	if(field.elements[i].name.indexOf('user_mail_id[]') !=-1){
	field.elements[i].checked=true;
	}
}
function uA(fr){
for(i=0,n=fr.elements.length;i<n;i++)
	if(fr.elements[i].name.indexOf('user_mail_id[]') !=-1){
	fr.elements[i].checked=false;
	}
}

function checkRequired_contactus(f,s,chk) {
	var strError = "";
	for (var intLoop = 0; intLoop<f.elements.length; intLoop++){
//		f.elements[intLoop].style.border = 'solid #000000 1px';
		if (null!=f.elements[intLoop].getAttribute("required")) {
			f.elements[intLoop].style.border = 'solid #00FF00 1px';
			if (isEmpty(f.elements[intLoop].value)){
				strError += "  " + f.elements[intLoop].name + "\n";
				f.elements[intLoop].style.border = 'solid #FF0000 2px';}
		}
	} // end of for
	if ("" != strError) 	return false;

	if(chk==true){
	for (var cnt=0; cnt<f[s].length; cnt++){
		if(f[s][cnt].checked==true){
			return true;
			}
	}
	document.getElementById('sizeBoxes').style.color='#FF0000';
	return false;
	}
}
function isEmpty(str) {
	// Check whether string is empty.
	for (var intLoop = 0; intLoop < str.length; intLoop++)
		if (" " != str.charAt(intLoop))
			return false;
	return true;
}
//------------------------------------
function checkSubmit(obj, frmName){
	if(obj.value.length==4){
		document.plus4zip_form.submit();
	}
	else {
		return false;
	}
}
/*-----------------------------------*/
function gotoUrl(url){
	window.location=url;
	return false;
	}
/*------------------------------------*/

function hideBillDetail(divName, divDetail, billId){
	document.getElementById(divName).style.display= 'block';
	document.getElementById(divDetail).style.display= 'none';
	document.getElementById('vr_'+billId).style.display= 'block';
	document.getElementById('bts_'+billId).style.display= 'none';
	}




function sessionOut(url){
alert('Your session has been expired !');
setTimeout(  "sessionOut(url)", 15000);
window.location.href=url;
}

function phpSessionOut(url){
alert('Your session has timed out due to 30 minutes of inactivity.  Please log back in to continue.');
window.location.href=url;
}


function showPopUp(){
document.getElementById('popupAlert').style.display = 'block';
}

function hidePopUp(){
document.getElementById('popupAlert').style.display = 'none';
}
function showLoginBill(bid){
	el = document.getElementById('urld');
	el.value = el.value + '?bid='+bid;
	showPopUp();
}


function checkPopUpForm() {
var check = true;
var checkFocus1 = true;
var checkFocus2 = true;
myLogin = document.getElementById("login1").value;
myPassword = document.getElementById("login2").value;

 
  if (myLogin == "") {
	  document.getElementById('uname').style.display = 'inline';
	  document.getElementById('login1').focus();
	  checkFocus1 = false;
	  check = false;
  }else{
  	  document.getElementById('uname').style.display = 'none';		
  }
   
  if (myPassword == "") {
	  document.getElementById('password').style.display = 'inline';
  	  document.getElementById('login2').focus();
	  checkFocus2 = false;
	  check = false;
  }else{
  	  document.getElementById('password').style.display = 'none';
  }
  if((checkFocus1==false) && (checkFocus2==false)){
  document.getElementById('login1').focus();
  } 
  if(check==false){
	  return false;
  }
  }
///////////////////////////////////////////////////////////////////////

var childWindowHandles = new Array();

function popUp2(URL, WIDTH, HEIGHT, SCROLL, LEFT, TOP, sId)
{
	day = new Date();
	id = day.getTime();
	eval("childWindowHandles["+childWindowHandles.length+"] = window.open(URL, '" + (sId!= '' ? sId : id) + "','scrollbars="+ SCROLL +",width="+ WIDTH +",height="+ HEIGHT +",left = "+ LEFT +",top = "+ TOP +", resizable = yes');");
}

function closeChildWindows() 
{
	for (var loop=0; loop<childWindowHandles.length; loop++) if (!childWindowHandles[loop].closed) childWindowHandles[loop].close();
}




function whichButton(event)
{
	if (event.button==2)//RIGHT CLICK
{

	alert("Not Allow Right Click!");
}

}
function noCTRL(e)
{
	var code = (document.all) ? event.keyCode:e.which;

	var msg = "Sorry, this functionality is disabled.";
	if (parseInt(code)==17) //CTRL
	{
		alert(msg);
		if (window.event){window.event.returnValue = false;}

	}
}
