
//define constants for javascript in this page
var BASE='/statuehouse/';

function err(display,name)
	{
		alert('Please enter the '+display);
		//alert (name);
		document.getElementById(name).focus();
	}

//###############################################################################



function emailverify(email)
	{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	str=email;
	if(!filter.test(str))
		{
		return false
		}
	else return true;
	}
	
	
//###################################################################################

function getConfirm()
	{
		return confirm('Do you really want to delete?');
			
	}

//###############################################################################	

function getVal(id)
	{
		return document.getElementById(id).value;
	}
	
//###############################################################################

function toggle_visibility(id)
{
	
	var el = document.getElementById(id);
			if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}


function toggle_visibility_search(id,id1,id2,id3)
{
	
	var el = document.getElementById(id);
	var e2 = document.getElementById(id1);
	var e3 = document.getElementById(id2);
	var e4 = document.getElementById(id3);
			if ( el.style.display != 'none' ) {
		el.style.display = '';
	}
	else {
		el.style.display = '';
		e2.style.display = 'none';
		e3.style.display = 'none';
		e4.style.display = 'none';
	}
}
 
function check_search()
	{
		var gg=document.getElementById('search').value;
		if(gg == '')
		{
			alert('Please enter search text');
		}
		document.search1.submit();
	}



//###############################################################################


function redirect(URL)
	{
		top.location=URL;
	}

//###############################################################################


function RedirectWithConfirm(url)
{
	var result=confirm('Are you sure you want to proceed?');
	if(result)	top.location=url;
	else return false;
}


//###########################################################################


function popUp(URL,width,height)
{
day = new Date();
id = day.getTime();
eval("Photo" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+ width +",height="+ height +",left = 312,top = 184');");
}


//#############################################################################
//a should be in merged with comma ','. field name is merged with comma
//divis should be the id of that div where the error message is displayed

function validate_form_div(a,divid)
	{
		var z=a.split(',');
		num_data = z.length;
		var msg = 'Error! The following fields are empty<br>';
		var err=0;
		//alert(a);
		for(var i=0; i<num_data; i++)
			{
				//alert(z[i]);
				if(document.getElementById(z[i]).value=='')
					{
						msg=msg+z[i]+'<br>';
						err++;
					}
			}
		if(err!=0)
			{
				document.getElementById(divid).innerHTML=msg;
				return false;
			}
		else return true;		
		
	}
	


//###################################################################################

function Alert_NoDelete()
	{
		alert('You cannot delete this!');
	}
	
	
	


//##############################CHECK THE NUMERICAL VALUE##########################

function IsNum(amount)
{
var okChars = "0123456789.-";
var xChars = amount;
var allChar = true;
for (i=0; i<xChars.length; i++)
	{
    ch = xChars.charAt(i);
    for (j=0; j<okChars.length; j++)
		{
    	if (ch == okChars.charAt(j)) 
			{
        	allChar==true; 
			j=okChars.length;
      		}
		}	
    if (j == okChars.length)
		{
    	allChar = false;
    	i=xChars.length;
    	}
	}
if (!allChar)return false; else return true;
}
//############################################################


function validate_form(a,type,divId)
	{
		var z=a.split(',');
		num_data = z.length;
		var msg = 'Some of the Required Field Missing!';
		var err=0;
		for(var i=0; i<num_data; i++)
			{
				//alert(z[i]);
				if(document.getElementById(z[i]).value=='')
					{
						err++;
					}
			}
		if(err!=0)
			{
				if(type=='div')document.getElementById(divId).innerHTML=msg;
				else if(type='alert')alert(msg)
				return false;
			}
		else return true;		
	}
	

//###############################################################################

function validate_form_front(a,type,divId)
	{
		var z=a.split(',');
		num_data = z.length;
		var msg = '<img src="images/err.gif" align="absmiddle" /> Error! Required Field/s missing ';
		var err=0;
		for(var i=0; i<num_data; i++)
			{
				//alert(z[i]);
				if(document.getElementById(z[i]).value=='')
					{
						err++;
					}
			}
		if(err!=0)
			{
				if(type=='div')document.getElementById(divId).innerHTML=msg;
				else if(type='alert')alert(msg)
				return false;
			}
		else return true;		
	}
	

//##########################################################################################

function bulkEmailValidation(emails)
	{
	var a = emails;
			
	var z=a.split(',');
	num_data = z.length;
	for(var i=0; i<num_data; i++)
		{
		//alert(z[i]);
		if(!emailverify(z[i]))
			{
			alert(z[i]+ ' is invalid email');
			return false;
			break;
			}
		}
		
		return true;
		
	}
	
	
	function checkDelete()									
{
		
if(confirm("Are you sure you want to delete")==false)								
	{
		
		return false;
	}
	else
	{
		return submit;
	}
	
  }
//###################################################################################

function togglecheck()
{
	
	if(document.getElementById('checkboxall').checked==true)
		{
			
			SetValues('formbulk', 'checkid[]', true);
		
		}
	else if(document.getElementById('checkboxall').checked==false)
		{
			
			SetValues('formbulk', 'checkid[]', false);
		}
	
}
function SetValues(Form, CheckBox, Value)   {  
     var objCheckBoxes = document.forms[Form].elements[CheckBox];  
     var countCheckBoxes = objCheckBoxes.length; 
	
	if(!countCheckBoxes)//this code is for single data check.
	 document.getElementById('checkid[]').checked=Value;	
	 
	 for(var i = 0; i < countCheckBoxes; i++)  
     objCheckBoxes[i].checked = Value;  
 }  
 

