// JavaScript Document

function validate_change_pass(p1,p2)
{
	if(p1.value==p2.value)
	{
		call_validate(p1.form)
		return true;
	}
	else
	{
		alert("Please varify the new password");
		p2.focus();
		p2.select();
		
		return false;
	}
}


function call_validate_range(form,start,end)
{
bool=true;
for(counter=start;counter<=end;counter++)
{
	if(!validate(form[counter]))
	{
	return false;
	}
	
}
form.submit();
}
	
	



function call_validate(form)
{

	bool=true;
	for(counter=0;counter<form.length;counter++)
	{
	if(!validate(form[counter]))
	{
	return false;
	}
	
	}
	form.submit();
}

function  validate(comp)
{
vclass=comp.getAttribute("vclass");
vmessage=comp.getAttribute("vmessage");
if(vclass=="req_select")
{
temp=(comp.options[comp.selectedIndex].text);
	if(temp.toLowerCase()=="select")
	{
		alert(vmessage);
		//comp.select();
		comp.focus();
		return false;
	}
}


if(vclass=="required")
{
req=comp.getAttribute("req")
if(comp.value.length<req)
{
	alert(vmessage);
	comp.focus();
	comp.select();
	return false;
}
}
///////////
if(vclass=="email")
{
	rule=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	email=comp.value;
	if(!rule.test(email))
	{
	alert(vmessage);
	comp.focus();
	comp.select();
	
	return false;
		
	}
	
}
///////////////////////////
if(vclass=="number")
{
	
nos=comp.value;
if(isNaN(nos)||(nos.length<1))
{
	alert(vmessage);
	comp.focus();
	comp.select();
	
	return false;
	
	
}
	
	
}

if(vclass=="integer")


{
	rule=/^[0-9]{1,}$/;
	emails=comp.value;
	if(!rule.test(emails))
	{
	alert(vmessage);
	comp.focus();
	comp.select();
	
	return false;
	}
	
}
	

////////////////va





return true;	
}



function manage_date_chooser(mm,dd,yy)
{
	try
	{
valmm=mm.value;
valdd=dd.value;
valyy=yy.value;
//alert(valyy);
if((valyy%4==0)&&(valmm==2))
{
manage_days(dd,29);	
}
else
{
days_in_months=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
manage_days(dd,days_in_months[valmm-1]);	
}
	}
	catch(d)
	{
		
		alert("manage_cj");
	}
}
			


function manage_days(comp,nos)
{
	try
	{
		temp=comp.selectedIndex;
while(comp.options.length!=0)
{
comp.options.remove(0);
}
for(counter=1;counter<=nos;counter++)
{
	opt=new Option(counter,counter,false,false);
//	opt.value=counter;
	//opt.label=counter;
	comp.options.add(opt,counter-1);
}
	comp.selectedIndex=temp;
	}
	catch(e)
	{
		alert("error manage_days");
	}
}

function getNextComp(me,pos)
{
	try
	{
form=me.form;
myindex=getIndex(form,me);
myindex+=pos;
return form[myindex];
	}
	catch(e)
	{
		alert(e);
	}
}


function getIndex(form,what)
{
	try
	{
	for(counter=0;counter<form.length;counter++)
	{
	if(what==form[counter])
	{
		return counter;
	}
	}
	return false;
	}
	catch(e)
	{
		alert("error getindex"+e);
	}
}




////////////////////////////////



















function does_repeat(arr,ele)
{
	for(counter1=0;counter1<arr.length;counter1++)
	{
	if(arr[counter1]==ele)
	{
		return true;
	}
	}
	return false;
}

/*********************************************************/

function has_duplicates(form)
{
	arrs=new Array();
	for(counter=0;counter<form.length;counter++)
	{
		if(form[counter].getAttribute("vclass")=="integer")
		{
			//alert(form[counter].name);
			if(does_repeat(arrs,form[counter].value))
			{
				alert("no duplicates value in the rank");
				return false;
			}
			else
			{
				
				arrs.push(form[counter].value);
			}
			
		}
		
		
	}
	arrs=null;
	call_validate(form);
}



/*
delete modules
*/

function delete_district(id,name)
{
	bool=confirm("are you sure you want to delete "+name);
	if(bool)
	{
		location.replace("delete_district.php?id="+id);
				
	}
	else
	{
		return false;
	}
	
}




function delete_vdc(id,name)
{
	bool=confirm("are you sure you want to delete "+name);
	if(bool)
	{
		location.replace("delete_vdc.php?id="+id);
				
	}
	else
	{
		return false;
	}
	
}
///////////////////////////////
function delete_local(id,form)
{
bool=confirm("Are you sure you want to delete ::");
if(bool)
{
form.action="delete_local.php?action=5&idents="+id;
form.mode.value='nothing2';
form.submit();		
}
else
{
return false;
}
}
//////////////////////////////////////////

function delete_broker(id)
{
	
	bool=confirm("are you sure you want to delete");
	if(bool)
	{
		location.replace("delete_broker.php?id="+id);
				
	}
	else
	{
		return false;
	}
	
	
}
////////////////////


function delete_terms(id)
{
	bool=confirm("are you sure you want to delete the terms");
	if(bool)
	{
		url="delete_terms.php?id="+id;
		location.replace(url);
			
	}
	else
	{
		
		return false;
	}
	
	
	
}


function delete_owner(id)
{
	bool=confirm("Are you sure you want to delete ?");
	if(bool)
	{
		url="delete_owner.php?id="+id;
		location.replace(url);		
	}
	else
	{
		return false;
	}	
	
}




function delete_home(id)
{
	bool=confirm("Are you sure you want to delete ?");
	if(bool)
	{
		url="delete_home.php?id="+id;
		location.replace(url);		
	}
	else
	{
		return false;
	}	
	
}




function makenumber(component)
{
a=window.event.keyCode;
if((a>=48)&&(a<=59))
{
	return true
}
return false;
}






function delete_client(id)
{
	bool=confirm("Are you sure you want to delete ?");
	if(bool)
	{
		url="delete_client.php?id="+id;
		location.replace(url);		
	}
	else
	{
		return false;
	}	
	
}


function delete_client_home(id)
{
	
	bool=confirm("Are you sure you want to delete ?");
	if(bool)
	{
		url="delete_client_home.php?id="+id;
		location.replace(url);		
	}
	else
	{
		return false;
	}	
	
	
}


