function ge()
{
	var ea;
	for(var i=0;i<arguments.length;i++)
	{
		var e=arguments[i];
		if(typeof e=='string')
			e=document.getElementById(e);
		if(arguments.length==1)
			return e;
		if(!ea)
		ea=new Array();
		ea[ea.length]=e;
	}
return ea;
}
//login
function validate_login()
{
	if(ge('username').value.length<5)	
	{
		alert('Please enter a username more than 5 letter..!');
		ge('username').focus();
		return false;		
	}
	if(ge('password').value.length<5)	
	{
		alert('Please enter a password more than 5 letter..!');
		ge('password').focus();
		return false;		
	}
	return true;
}
//function for checking the limit
function textLimit(ta,count)
{// onkeyup="textLimit('clubs', 1500,'clubs_msg');"
	var text=document.getElementById(ta);
	if(text.value.length>count)
	{
		text.value=text.value.substring(0,count);
		if(arguments.length>2)
		{
			ge(arguments[2]).style.display='block';
		}		
	}
}
function textLimitStrict(text_id,limit,message_id,count_id,submit_id)
{
	var text=ge(text_id);
	var len=text.value.length;
	var diff=len-limit;
	if(diff>0)
	{
		if(diff>25000)
		{
			text.value=text.value.substring(0,limit+25000);
			diff=25000;
		}
		ge(message_id).style.display='block';
		ge(count_id).innerHTML=diff;
		ge(submit_id).disabled=true;
	}
	else if(len==0)
	{
		ge(message_id).style.display='none';
		ge(submit_id).disabled=true;
		ge(count_id).innerHTML=1;
	}
	else
	{
		if(ge(count_id).innerHTML!=0)
		{
			ge(count_id).innerHTML=0;
			ge(message_id).style.display='none';
			ge(submit_id).disabled=false;
		}
	}
}
function addConcentration(concentrate_name)
{
	concentrate_adder=concentrate_name+'_adder';
	concentrate_value_count=concentrate_name+'_value_count';
	if(ge(concentrate_value_count).value==2)
	{
		ge(concentrate_value_count).value=3;
		showTableRow(getParentRow(concentrate_name+'3_name'));
		hide(getParentRow(concentrate_adder));
	}
	else
	{
		ge(concentrate_value_count).value=2;
		showTableRow(getParentRow(concentrate_name+'2_name'));
	}
}
function add_edu_con()
{
	if(document.getElementById('edu_con').value=='1')
	{
		document.getElementById('edu_con').value=2;
		document.getElementById('row_con2').style.display='block';
	}
	else (document.getElementById('edu_con').value=='2')	
	{
		document.getElementById('edu_con').value=3;
		document.getElementById('row_con3').style.display='block';
	}
}
//image validation
extArray = new Array(".jpg", ".jpeg", ".gif", ".png");
function LimitAttach(f_name,form, file)
{//onclick="LimitAttach(file2,this.form, this.form.file2.value);"
	allowSubmit = false;
	if (!file) return;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) 
	{
		if (extArray[i] == ext) 
		{ 
			allowSubmit = true; 
			break; 
		}
	}
	if(!allowSubmit) 
	{
		alert("Please upload only files having the format or types : "+ (extArray.join("  ")) + "\nPlease select a new file to upload and submit again.");
		f_name.value='';
	}	
}
function show()
{
	for(var i=0;i<arguments.length;i++)
	{
		var element=ge(arguments[i]);
		if(element&&element.style)
		element.style.display='';
	}
	return false;
}
function hide()
{
	for(var i=0;i<arguments.length;i++)
	{
		var element=ge(arguments[i]);
		if(element&&element.style)
		element.style.display='none';
	}
	return false;
}
function toggle()
{
	for(var i=0;i<arguments.length;i++)
	{
		var element=ge(arguments[i]);
		element.style.display=(element.style.display=='block'||element.style.display=='')?'none':'block';
	}
	return false;
}
function make_disabled(el)
{
	el=ge(el);
	return(el.disabled=='disabled');
}
function make_enabled(el)
{
	el=ge(el);
	return(el.disabled==false);
}
function shown(el)
{
	el=ge(el);
	return(el.style.display!='none');
}
var popUpWin=0;
function popUpWindow(URLStr)
{
  	if(popUpWin)
  	{
    	if(!popUpWin.closed) popUpWin.close();
  	}
  	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=800,height=700');
}


function optional_drop_down_menu(arrow,link,menu,event,arrow_class,arrow_old_class)
{
	if(menu.style.display=='none')
	{
		menu.style.display='block';
		var old_arrow_classname=arrow_old_class?arrow_old_class:arrow.className;
		if(link)
		{
			link.className='active';
		}
		arrow.className=arrow_class?arrow_class:'global_menu_arrow_active';
		var justChanged=true;
		var shim=ge(menu.id+'_iframe');
		if(shim)
		{
			shim.style.top=menu.style.top;
			shim.style.right=menu.style.right;
			shim.style.display='block';
			shim.style.width=(menu.offsetWidth+2)+'px';
			shim.style.height=(menu.offsetHeight+2)+'px';
		}
		menu.offclick=function(e)
		{
			if(!justChanged)
			{
				hide(this);
				if(link)
				{
					link.className='';
				}
				arrow.className=old_arrow_classname;
				var shim=ge(menu.id+'_iframe');
				if(shim)
				{
					shim.style.display='none';
					shim.style.width=menu.offsetWidth+'px';
					shim.style.height=menu.offsetHeight+'px';
				}
				removeEventBase(document,'click',this.offclick,menu.id);
			}
			else
			{
				justChanged=false;
			}
		}
		.bind(menu);
		addEventBase(document,'click',menu.offclick,menu.id);
	}
return false;
}

function MM_openBrWindow(theURL,winName,features)
{ //v2.0
  window.open(theURL,winName,features);
}
function select_photos(opts)
{
	for(i=0;i<document.forms.length;i++)
	{
		if(document.forms[i].id=='photoselect')
		{
			for(j=0;j<document.forms[i].length;j++)
			{
				if(document.forms[i][j].id.substring(0,4)=='pid_')
				{
					if(opts=='all')
					{
						document.forms[i][j].checked=true;
					}
					else
					{
						document.forms[i][j].checked=false;
					}
				}
			}
		}
	}
}
function check(form) 
{
	var selet=null;
	for (i = 0; i < form.elements.length; i++)
	 {
		var element = form.elements[i];
		if (element.type == 'checkbox')
		{								
			if(element.checked)
			{	
				if(selet==null)
				selet=element.value;
				else
				selet=selet + "," + element.value;							
			}
		}
	}
	document.getElementById('opt_com').value=selet;
	confirm(selet);
}
function group_remove_user(gid)
{
	var ajax=new Ajax();
	ajax.onDone=function(ajax_obj,response_text)
	{
		if(response_text!=='0')
		{
			(new pop_dialog()).show_message('An error occurred.',response_text);
		}
		else
		{
			document.location='groups.php';
		}
	}
	ajax.post('/ajax/group_actions_ajax.php',['gid=',gid,'&remove=1'].join(''));
}
function group_add_user(gid)
{
	var ajax=new Ajax();
	ajax.onDone=function(ajax_obj,response_text)
	{
		if(response_text!=='0')
		{
			(new pop_dialog()).show_message('An error occurred.',response_text);
		}
		else
		{
			document.location='group.php?gid='+gid;
		}
	}
	ajax.post('/ajax/group_actions_ajax.php',['gid=',gid,'&join=1'].join(''));
}
function emoticon(text, desg_text)
{
//    var txtarea = document.post.reply_post;
	var txtarea = desg_text;
    text = ' ' + text + ' ';
    if (txtarea.createTextRange && txtarea.caretPos) 
	{
        var caretPos = txtarea.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
        txtarea.focus();
    } 
	else 
	{
        txtarea.value  += text;
        txtarea.focus();
    }
}
function confirm_group_join(gid)
{
	var ajax=new Ajax();
	ajax.onDone=function(ajax_obj,response_text)
	{
		if(response_text==='0')
		{
			document.location='group.php?gid='+gid;
		}
		else
		{
			(new pop_dialog()).show_message('An error occurred.',response_text);
		}
	}
	ajax.post('/ajax/group_actions_ajax.php',['gid=',gid,'&join=1'].join(''));
}
function create_hidden_input(name,value)
{
	var new_input=document.createElement('input');
	new_input.name=name;
	new_input.value=value;new_input.type='hidden';
	return new_input;
}
function escapeURI(u)
{
	if(encodeURIComponent)
	{
		return encodeURIComponent(u);
	}
	if(escape)
	{
		return escape(u);
	}
}
function goURI(href)
{
	window.location.href=href;
}
function is_email(email)
{
	return/^[\w!.%+]+@[\w]+(?:\.[\w]+)+$/.test(email);
}
function getViewportWidth()
{
	var width=0;
	if(document.documentElement&&document.documentElement.clientWidth)
	{
		width=document.documentElement.clientWidth;
	}
	else if(document.body&&document.body.clientWidth)
	{
		width=document.body.clientWidth;
	}
	else if(window.innerWidth)
	{
		width=window.innerWidth-18;
	}
return width;
}
function getViewportHeight()
{
	var height=0;
	if(window.innerHeight)
	{
		height=window.innerHeight-18;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		height=document.documentElement.clientHeight;
	}
	else if(document.body&&document.body.clientHeight)
	{
		height=document.body.clientHeight;
	}
	return height;
}
function getPageScrollHeight()
{
	var height;
	if(typeof(window.pageYOffset)=='number')
	{
		height=window.pageYOffset;
	}
	else if(document.body&&document.body.scrollTop)
	{
		height=document.body.scrollTop;
	}
	else if(document.documentElement&&document.documentElement.scrollTop)
	{
		height=document.documentElement.scrollTop;
	}
	if(isNaN(height))return 0;return height;
}
function getRadioFormValue(obj)
{
	for(i=0;i<obj.length;i++)
	{
		if(obj[i].checked)
		{
			return obj[i].value;
		}
	}
return null;
}

function imageConstrainSize(src,maxX,maxY,placeholderid)
{
	var image=new Image();
	image.onload=function()
	{
		if(image.width>0&&image.height>0)
		{
			var width=image.width;
			var height=image.height;
			if(width>maxX||height>maxY)
			{
				var desired_ratio=maxY/maxX;
				var actual_ratio=height/width;
				if(actual_ratio>desired_ratio)
				{
					width=width*(maxY/height);
					height=maxY;
				}
				else
				{
					height=height*(maxX/width);
					width=maxX;
				}
			}
			var placeholder=ge(placeholderid);
			var newimage=document.createElement('img');
			newimage.src=src;
			newimage.width=width;
			newimage.height=height;
			placeholder.parentNode.insertBefore(newimage,placeholder);
			placeholder.parentNode.removeChild(placeholder);
		}
	}
	image.src=src;
}
function set_opacity(obj,opacity)
{
	try
	{
		obj.style.opacity=(opacity==1?'':opacity);
		obj.style.filter=(opacity==1?'':'alpha(opacity='+opacity*100+')');
	}
	catch(e)
	{}
	obj.setAttribute('opacity',opacity);
}
function get_opacity(obj)
{
	return obj.opacity?obj.opacity:1;
}
function setCookie(cookieName,cookieValue,nDays)
{
	var today=new Date();
	var expire=new Date();
	if(nDays==null||nDays==0)nDays=1;
	expire.setTime(today.getTime()+3600000*24*nDays);
	document.cookie=cookieName+"="+escape(cookieValue)+"; expires="+expire.toGMTString()+"; path=/; domain=.facebook.com";
}
function clearCookie(cookieName)
{
	document.cookie=cookieName+"=; expires=Mon, 26 Jul 1997 05:00:00 GMT; path=/; domain=.facebook.com";
}
function getCookie(name)
{
	var nameEQ=name+"=";
	var ca=document.cookie.split(';');
	for(i=0;i<ca.length;i++)
	{
		var c=ca[i];
		while(c.charAt(0)==' ')c=c.substring(1,c.length);
		if(c.indexOf(nameEQ)==0)
		{
			return unescape(c.substring(nameEQ.length,c.length));
		}
	}
	return null;
}
function anchor_set(anchor){window.location=window.location.href.split('#')[0]+'#'+anchor;}
function anchor_get(){return window.location.href.split('#')[1]||null;}
function event_get(e){return e||window.event;}
function event_get_target(e){return(e=event_get(e))&&(e['target']||e['srcElement']);}

function htmlspecialchars(text)
{
	if(typeof(text)=='undefined'||!text.toString)
	{
		return'';
	}
	if(text===false)
	{
		return'0';
	}
	else if(text===true)
	{
		return'1';
	}
	return text.toString().replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/'/g,'&#039;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}
function escape_js_quotes(text)
{
	if(typeof(text)=='undefined'||!text.toString)
	{
		return'';
	}
	return text.toString().replace(/\\/g,'\\\\').replace(/\n/g,'\\n').replace(/\r/g,'\\r').replace(/"/g,'\\x22').replace(/'/g,'\\\'').replace(/</g,'\\x3c').replace(/>/g,'\\x3e').replace(/&/g,'\\x26');
}

function trim(instr)
{
	var reFirst = /\S/;		// regular expression for first non-white char
	var reLast = /\s+$/;	// regular expression for first white char after last non-white char
	var firstChar = instr.search(reFirst);
	var lastChar = instr.search(reLast);
	
	if( lastChar == -1 ) 
		lastChar = instr.length;    	
	outstr = instr.substring( firstChar, lastChar );
	return outstr;
}

function isEmail(emailIn){
	var isEmailOk = false;
	var filter = /^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9-]+(\.[a-zA-Z][a-zA-Z-]+)+$/

	if(emailIn.search(filter) != -1)
		isEmailOk = true;
	if(emailIn.indexOf("..") != -1)
		isEmailOk = false;
	if(emailIn.indexOf(".@") != -1)
		isEmailOk = false;

	return isEmailOk;
} // Ends 

function nl2br(text)
{
	if(typeof(text)=='undefined'||!text.toString)
	{
		return'';
	}
	return text.toString().replace(/\n/g,'<br />');
}
function checkAgree()
{
	Util.deprecated('checkagree');
	if(document.frm.pic.value)
	{
		if(document.frm.agree.checked)
		{
			document.frm.submit();
		}
		else
		{
			show("error");
		}
	}
}
function select_check(opts,form_id,sub_str)
{
	for(i=0;i<document.forms.length;i++)
	{
		if(document.forms[i].id==form_id)
		{
			for(j=0;j<document.forms[i].length;j++)
			{
				if(document.forms[i][j].id.substring(0,4)==sub_str)
				{
					if(opts=='all')
					{
						document.forms[i][j].checked=true;
					}
					else
					{
						document.forms[i][j].checked=false;
					}
				}
			}
		}
	}
}///----
//select on all chekboxes in form with help of(text link)
function select_checked(form)
{
	var selet=null;
	for (i = 0; i < form.elements.length; i++)
	 {
		var element = form.elements[i];
		if(element.type == 'checkbox')
		{									
			element.checked=true;						
		}
	}
}
function select_unchecked(form)
{
	var selet=null;
	for (i = 0; i < form.elements.length; i++)
	 {
		var element = form.elements[i];
		if (element.type == 'checkbox')
		{											
				element.checked=false;
		}
	}
}

//select on all chekboxes in form with help of(text link)
function select_check(form)
{
	var selet=null;
	for (i = 0; i < form.elements.length; i++)
	 {
		var element = form.elements[i];
		if (element.type == 'checkbox')
		{								
			if(element.checked)
			{	
				element.checked=false;						
			}
			else
			{
				element.checked=true;
			}
		}
	}
}///----
//one clicking on the one checkbox, select or unselect other checkboxes
function selectAllCheckboxes(form)
{
  for (var i=0;i<form.elements.length;i++) 
  {
    var element = form.elements[i];
    if(element.type == 'checkbox')
      element.checked = form.elements['selectAllCheckbox'].checked;	 
  }
}
/*validate the url*/
function share_is_shareable(url){return(/(?:https?:\/\/)?\w+\.\w+/.test(url));}
function on_photo_remove(ajaxObj,responseText)
{
	var textarea=ge('note_content');
	var s=textarea.value.replace("<Photo "+ajaxObj.photo_index+">","");
	textarea.value=s;
	photo_reload_all();
}
function set_photo_align(pid,alignment)
{
	ge('layout_select_'+pid).value=alignment;
	photo_align(pid,alignment);
}
function photo_align(pid,alignment)
{
	toggle_align_icon(pid,alignment,"on");
	for(var i=0;i<=3;i++)
	{
		if(i==alignment)
		{
			continue;
		}
		toggle_align_icon(pid,i,"off");
	}
	ChangeAlign(pid,alignment);
	//var ajax=new Ajax(on_photo_align,function(){});
	//ajax.post('/ajax/notes_upload_ajax.php','a=1&align='+alignment+'&note_id='+_note_id+'&pid='+pid);
}
function toggle_align_icon(pid,alignment,toggle_value)
{
	ge('alignment_icon_'+pid+'_'+alignment).className='alignment_icon align'+alignment+' icon_'+toggle_value;
}
//rating section

function get_color(color_no)
{
if(color_no == 'r1')
    color_num = 1;
if(color_no == 'r2')
    color_num = 2;
if(color_no == 'r3')
    color_num = 3;
if(color_no == 'r4')
    color_num = 4;
if(color_no == 'r5')
    color_num = 5;
if(color_no == 'r6')
    color_num = 6;
if(color_no == 'r7')
    color_num = 7;
if(color_no == 'r8')
    color_num = 8;
if(color_no == 'r9')
    color_num = 9;
if(color_no == 'r10')
    color_num = 10;

var color_up=color_num;
var my_color= new Array(10)
  my_color[1]="#CC0000";
  my_color[2]="#FF0000";
  my_color[3]="#FF6600";
  my_color[4]="#FF9900";
  my_color[5]="#FFCC00";
  my_color[6]="#FFFF00";
  my_color[7]="#CCFF33";
  my_color[8]="#66FF00";
  my_color[9]="#66CC33";
  my_color[10]="#009900";

    for(i=1;i<=color_up;i++){
	rid = "r"+i;
        document.getElementById(rid).style.background=my_color[i];
    }
}
function put_color(color_no)
{
if(color_no == 'r1')
    color_num = 1;
if(color_no == 'r2')
    color_num = 2;
if(color_no == 'r3')
    color_num = 3;
if(color_no == 'r4')
    color_num = 4;
if(color_no == 'r5')
    color_num = 5;
if(color_no == 'r6')
    color_num = 6;
if(color_no == 'r7')
    color_num = 7;
if(color_no == 'r8')
    color_num = 8;
if(color_no == 'r9')
    color_num = 9;
if(color_no == 'r10')
    color_num = 10;

var color_up=color_num;
    for(i=1;i<=color_up;i++){
	rid = "r"+i;
        document.getElementById(rid).style.background="#CCCCCC";
    }
}
//to prevent html tags
function Del(Word) 
{
	a = Word.indexOf("<");
	b = Word.indexOf(">");
	len = Word.length;
	c = Word.substring(0, a);
	if(b == -1)
	b = a;
	d = Word.substring((b + 1), len);
	Word = c + d;
	tagCheck = Word.indexOf("<");
	if(tagCheck != -1)
	Word = Del(Word);
	return Word;
}
function Check_code(txt_ele) 
{//onsubmit="return Check(f_name,txt_ele);"
	ToCheck = document.getElementById(txt_ele).value;
	Checked = Del(ToCheck);
	document.getElementById(txt_ele).value = Checked;
	
	if(document.getElementById(txt_ele).value.length<10)
	{
		alert("Please enter a valid comment..!");
		document.getElementById(txt_ele).focus();
		return false;
	}
return true;
}