function get$(elementId)
{
  return document.getElementById(elementId);
}

function get$Value(elementId)
{
  var eleValue = '';
  
  if( get$(elementId) != null)
  {
    eleValue = get$(elementId).value;
  }
  return eleValue;
}

function set$Value(elementId, elementValue)
{
  if( get$(elementId) != null)
  {
    get$(elementId).value = elementValue;
  }
}

function get$Name(elementName)
{
  return document.getElementsByName(elementName);
}

function toggleDisplay(objId, displayMode)
{
  if(get$(objId) != null)
  {
    get$(objId).style.display = displayMode;
  }
}

function make_cancel(message_str, url)
{
	if (message_str == "") 
	{
		message_str = "this record";
	}
	else
	{
		message_str = "the " + message_str;
	}
	var r = confirm("Are you sure want to cancel " + message_str + "?")
		if (r==true)
	{
		location.href = url;
	}
}
function make_confirmation(message_str, url)
{
	if (message_str == "") 
	{
		message_str = "this record";
	}
	else
	{
		message_str = "the " + message_str;
	}
	var r = confirm("Are you sure want to confirm " + message_str + "?")
		if (r==true)
	{
		location.href = url;
	}
}
function delete_confirmation(message_str, url)
{
	if (message_str == "") 
	{
		message_str = "this record";
	}
	else
	{
		message_str = "the " + message_str;
	}
	var r = confirm("Are you sure want to delete " + message_str + "?")
		if (r==true)
	{
		location.href = url;
	}
}

function validate_photos_form(obj)
{
	return (checkstr(obj.ccd_photo_caption,'caption') && chkimage(obj.ccd_photo_simage) && chkimage(obj.ccd_photo_image)); // && checkstr(obj.ccd_photo_simage,'image') && checkstr(obj.ccd_photo_image,'image'));
}

function validate_top_banner_form(obj)
{
	return (checkstr(obj.fileimage,'image') && chkimage(obj.fileimage)); 
}

function chkimage(obj)
{
	if (Trim(obj.value).length != 0)
	{
		var ext = getfileext(obj.value);
		if (!(ext == ".jpg" || ext == ".png" || ext == ".bmp" || ext == ".gif"))
		{
			alert('Please provide a valid file format for the image. Valid formats are jpg, png, bmp or gif.');
			obj.value='';
			obj.focus();
			return false;
		}
	}
	return true;
}

function chkpdf(obj)
{
	if (Trim(obj.value).length != 0)
	{
		var ext = getfileext(obj.value);
		if (!(ext == ".pdf"))
		{
			alert('Please provide pdf file only.');
			obj.value='';
			obj.focus();
			return false;
		}
	}
	return true;
}

function validate_prayer_timing_form(obj)
{
	return (checkstr(obj.excelfile,'excelfile') && chk_excel(obj.excelfile)); 
}

function chk_excel(obj)
{
	if (Trim(obj.value).length != 0)
	{
		var ext = getfileext(obj.value);
		if (!(ext == ".xls"))
		{
			alert('Please provide a valid file format for the file. Valid format is xls.');
			obj.focus();
			return false;
		}
	}
	return true;
}

function validate_multimedia_form(obj)
{
	return (checkstr(obj.mult_file,'audio/video file') && chk_mult(obj.mult_file)); 
}

function chk_mult(obj)
{
	if (Trim(obj.value).length != 0)
	{
		var ext = getfileext(obj.value);
		if (!(ext == ".asx"))
		{
			alert('Please provide a valid file format for the file. Valid format is asx.');
			obj.focus();
			return false;
		}
	}
	return true;
}

function getfileext(filename)
{
	return Trim(filename).substr(Trim(filename).length-4).toLowerCase();
}
function LTrim(str)
	{
		if (str==null){return null;}
		for(var i=0;str.charAt(i)==" ";i++);
		return str.substring(i,str.length);
	}
function RTrim(str)
	{
		if (str==null){return null;}
		for(var i=str.length-1;str.charAt(i)==" ";i--);
		return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}

function checkstr(obj,errmsg)
{
	if (Trim(obj.value).length == 0)
	{
		alert('Please enter/select a valid ' + errmsg + '.');
		obj.focus();
		return false;
	}
	return true;
}

function checkcountry(obj,errmsg)
{    
	if (obj.value == "-1")
	{
		alert('Please enter/select a valid ' + errmsg + '.');
		obj.focus();
		return false;
	}
	return true;
}
function validate_contact_form(obj)
{
	return (checkstr(obj.first_name,'First Name') && checkstr(obj.city,'City') && checkstr(obj.state,'State') && checkcountry(obj.country,'Country') && checkstr(obj.email,'Email Id') && echeck(obj.email)); 
}

function validate_feedback_form(obj)
{
	return (checkstr(obj.to_date,'date') && checkstr(obj.from_date,'date')); // && checkstr(obj.ccd_photo_simage,'image') && checkstr(obj.ccd_photo_image,'image'));
}

function popup(url,width,height)
{
	w=window.open(url,"popupwin","width="+width+",height="+height+",position=center")
}

function ValidateFullNumeric(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (((keycode>46) && (keycode<58) )  || (keycode==8)) { return true; }
	else return false;
}

function echeck(str1) 
{
		var str = str1.value; 
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
	    if (str.indexOf(at)==-1)
		{		
		   alert("Invalid E-mail ID");
		   return false;
		}	
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid E-mail ID");
		   return false;
		}
		if (str.indexOf(at,(lat+1))!=-1)
		{
		    alert("Invalid E-mail ID")
		    return false;
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		{
		    alert("Invalid E-mail ID")
		    return false;
		}
		if (str.indexOf(dot,(lat+2))==-1)
	    {
		    alert("Invalid E-mail ID")
		    return false;
		}
		if (str.indexOf(" ")!=-1)
		{
		    alert("Invalid E-mail ID")
		    return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    alert("Invalid E-mail ID")
		    return false;
		} 
 		return true;
}	


//<a href="#" onClick="javascript:delete_confirmation('category with name %s', 'manage_category.aspx?action=delete&category_id=..')"></a>
