// 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();
		p2.className="errorfield";
		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=="required")
{
req=comp.getAttribute("req")
if(comp.value.length<req)
{
	alert(vmessage);
	comp.focus();
	comp.select();
	comp.className="errorfield";
	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();
	comp.className="errorfield";
	return false;
		
	}
	
}
///////////////////////////
if(vclass=="integer")
{
	rule=/^[0-9]{1,}$/;
	emails=comp.value;
	if(!rule.test(emails))
	{
	alert(vmessage);
	comp.focus();
	comp.select();
	comp.className="errorfield";
	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 delete_event(vent,id)
{
	alert("Event Once deleted are not recovereed");
	bool=confirm("Are you sure you want to delete the "+vent);
	if(bool)
	{
		url="delete_event.php?id="+id;
		location.replace(url);
	
	}
	
}


function delete_pre_photo(id,edit)
{
bool=confirm("Do you want to delete the photo");
	if(bool)
{
url="delete_pre_photo.php?id="+id+"&edit_id="+edit;
location.replace(url);
}

	
	
}


function delete_post_photo(id,edit)
{
bool=confirm("Do you want to delete the photo");
if(bool)
{
url="delete_post_photo.php?id="+id+"&edit_id="+edit;
location.replace(url);
}
}


function delete_visitor(id,name,page)
{
bool=confirm("Do you want to delete the "+name);
if(bool)
{
url="delete_visitor.php?action=3_1&id="+id+"&page_no="+page;
location.replace(url);
}
}

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

function delete_gallery(id,name)
{
	
bool=confirm("Do you want to delete the "+name);
if(bool)
{
url="delete_gallery.php?action=3_1&id="+id
location.replace(url);
}
	
}


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

function delete_gallery_photo(id,edit_id)
{
	
bool=confirm("Do you want to delete the picture");
if(bool)
{
url="delete_gallery_photo.php?action=4_1&id="+id+"&gallery_id="+edit_id;
location.replace(url);
}
	
}


function delete_partner_link(id,what)
{
bool=confirm("Do you want to delete "+what);
if(bool)
{
url="delete_partner.php?action=4_1&id="+id
location.replace(url);
}
}


function delete_acc_link(id,what)
{
bool=confirm("Do you want to delete "+what);
if(bool)
{
url="delete_acc.php?action=4_1&id="+id
location.replace(url);
}
}








function delete_partner_logo(id)
{
bool=confirm("Do you want to delete");
if(bool)
{
url="delete_partner_logo.php?action=9_1&id="+id
location.replace(url);
}
}






function delete_acc_logo(id)
{
bool=confirm("Do you want to delete");
if(bool)
{
url="delete_acc_logo.php?action=9_1&id="+id
location.replace(url);
}
}







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

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);
	
}
/***********************************************/
function does_repeat(arr,ele)
{
	for(counter1=0;counter1<arr.length;counter1++)
	{
	if(arr[counter1]==ele)
	{
		return true;
	}
	}
	return false;
}

/*************************************/
function delete_news(id)
{
bool=confirm("Do you want to delete");
if(bool)
{
url="delete_news.php?action=6_1&id="+id
location.replace(url);
}
}

function delete_application(id,application_by)
{
bool=confirm("Do you want to delete");
if(bool)
{
url="delete_application.php?action=8_1&id="+id+"&application_by="+application_by;
location.replace(url);
}
}




function delete_country(id,what)
{
bool=confirm("Do you want to delete "+what);
if(bool)
{
url="delete_country.php?action=10&edit="+id;
location.replace(url);
}
}

function delete_flag(id)
{
bool=confirm("Do you want to delete");
if(bool)
{
url="delete_flag.php?action=10&id="+id;
location.replace(url);
}
}