
//toggle visibility
function toggle_visibility(id)
{
	
	if (document.getElementById(id).style.display == 'none')
			 {
		document.getElementById(id).style.display = '';

	}
	else {
		document.getElementById(id).style.display = 'none';

	}

}

function toggle_visibility_news(id , currid , num)
{
	if (document.getElementById(id).style.display == 'none')
			{
				document.getElementById(id).style.display = '';
	
			}
			else {
				document.getElementById(id).style.display = 'none';
			}
		
	//alert(currid);
	for(i=0;i<num;i++)
	{
		//alert(i); alert(currid);
		if(i != currid)
			document.getElementById('news_'+i).style.display = 'none';
	}

}


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


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


//function to validate number
function number(field)
{
	for(var i=0;i<field.length;i++)
		{
			var str=field.substring(i,i+1);
			if(!(str >= "0" && str <= "9"))
			{
			return false;
			break;
			}
		}
		return true;
}
//function to validate email
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;
	}



// pop up window
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');");
}


/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


/**
*
*  Field reset functions
*  created by sanjay Khadka
*  sanjay.khadka@hotmail.com
*
**/
// my custom field reset functions
function onFocusReset(fField , fValue) {
	//alert(fValue);
	if(trim(document.getElementById(fField).value, '') == fValue) {
		document.getElementById(fField).value = '';	
	}
}

function onBlurReset(fField , fValue , fRequired) { // Field = id of field, value = value to be reset, Required = required or optional field
	if(trim(document.getElementById(fField).value, '') == ''){ 
		if(fRequired == 'required') alert(fField + ' must not be left blank?'); 
		document.getElementById(fField).value=fValue;
	}	
}
// end of field reset functions

/**
*
*  Tab function
*  created by sanjay Khadka
*  sanjay.khadka@hotmail.com
*
**/

function myTab( contentid ) {
	//alert(contentid);
	document.getElementById('default_content').innerHTML = document.getElementById( contentid ).innerHTML;
}


//custom Tab Interface
function customTab(mainDivId,newDivId,id,nooftabs)
{
	var linkid = "link"+id;
	var tabid = "tab"+id;
	//Manage CSS of active tab
	document.getElementById(mainDivId).innerHTML = 	document.getElementById(newDivId).innerHTML;
	document.getElementById(linkid).className = "detail_tabs";
	document.getElementById(tabid).style.background = "";
	document.getElementById(tabid).style.borderBottom = "";
	//number of tabs=4... For each other inactive tabs manage CSS.
	for(i=1;i<=nooftabs;i++)
		{
			if(i!=id)
				{
				linkid = "link"+i;
				tabid = "tab"+i;
				document.getElementById(tabid).style.background= "url(images/bg_tab.jpg) repeat-x";
				document.getElementById(tabid).style.borderBottom= "1px solid #CCDAFF";
				document.getElementById(linkid).className = "";
	
				}
		}

}

function toggle_visibility_LeftNav(id)
{
	for(i=1;i<=6;i++)
	{
		var navid = "nav"+i;
		var maindiv = navid+"main";
		var imagediv = navid+"image";
		var el = document.getElementById(navid);
		var e1main = document.getElementById(maindiv);
		var elimage = document.getElementById(imagediv);
		if(id == i)
			{
				
			if(el.style.display == 'none')
				{
				el.style.display = 'block';
				e1main.className = "tab_current";
				elimage.src = "images/icon_minus.png"
				}
			else
				{
				el.style.display = 'none';
				e1main.className = "tab";
				elimage.src = "images/icon_expand_plus.jpg"
				}
			}
		else
			{
			el.style.display = 'none';
			e1main.className="tab";
			elimage.src = "images/icon_expand_plus.jpg"
			
			}
	}
	
		
}

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

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

// delete confirmation
function confirmDelete() {
	if(confirm('Are you sure you want to delete this record?')) {
		return submit;	
	}
	else {
		return false;
	}
}

//get vlaue of particular id
function getVal(id) {
	return document.getElementById(id).value;
}

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

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

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

// pop up window
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');");
}

//shows alert for no access to modules page.
function showAlert(){
	
	alert('You Are Not Authorized To View This Page.');
	
}

//function to validate number
function number(field)
{
	for(var i=0;i<field.length;i++)
		{
			var str=field.substring(i,i+1);
			if(!(str >= "0" && str <= "9"))
			{
			return false;
			break;
			}
		}
		return true;
}
//function to validate email
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;
	}
//functions to trim
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
