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;
		}
	}
}
//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.style.disabled=='disabled');
}
function make_enabled(el)
{
	el=ge(el);
	return(el.style.disabled==false);
}
// JavaScript Document
function _cvcdomain()
{
	var d=document.domain;
	if(d.substring(0,4)=="www.")d=d.substring(4,d.length);
	var a=d.split(".");var len=a.length;
	if(len<3)return d;
	var e=a[len-1];
	if(e.length<3)return d;
	d=a[len-2]+"."+a[len-1];
	return d;
}
function setCookie(cookieName, cookieValue, nDays)
{
	var today=new Date();
	var expire=new Date();
	//var d='.crossvertical.in';
	if(nDays==null||nDays==0)nDays=1;
	expire.setTime(today.getTime()+3600000*24*nDays);
	//document.cookie=cookieName+"="+escape(cookieValue)+"; expires="+expire.toGMTString()+"; path=/; domain="+d;
//	document.cookie=cookieName+"="+escape(cookieValue)+"; expires="+expire.toGMTString()+"; path=/; domain=crossvertical";
	document.cookie=cookieName+"="+escape(cookieValue)+"; expires="+expire.toGMTString()+"; path=/; domain=.crossvertical.in";
}
function clearCookie(cookieName)
{
	var d=_cvcdomain();
	document.cookie=cookieName+"=; expires=Mon, 26 Jul 1997 05:00:00 GMT; path=/; domain="+d;
}
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)
		{//alert(c.substring(nameEQ.length,c.length));
			return unescape(c.substring(nameEQ.length,c.length));
		}
	}
	return null;
}
function shown(el)
{
	el=ge(el);
	return(el.style.display!='none');
}
var popUpWin=0;
function PCB_PopUpWindow(URLStr, WinWidth, WinHeight)
{
  	if(popUpWin)
  	{
    	if(!popUpWin.closed) popUpWin.close();
  	}
	var WinLeft = parseInt(screen.availWidth/2)-200;
	var WinSLeft= parseInt(screen.availWidth/2)-200;
    var WinTop = parseInt(screen.availHeight/2)-200;
	var WinSTop= parseInt(screen.availHeight/2)-200;
  	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+WinWidth+',height='+WinHeight+',left='+WinLeft+', top='+WinTop+',screenX='+WinSLeft+',screenY='+WinSTop+'');
}
function WIN_Story_detail(URLStr, WinWidth, WinHeight)
{
  	if(popUpWin)
  	{
    	if(!popUpWin.closed) popUpWin.close();
  	}
	var WinLeft = parseInt(screen.availWidth/2)-200;
	var WinSLeft= parseInt(screen.availWidth/2)-200;
    var WinTop = parseInt(screen.availHeight/2)-150;
	var WinSTop= parseInt(screen.availHeight/2)-150;
  	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+WinWidth+',height='+WinHeight+',left='+WinLeft+', top='+WinTop+',screenX='+WinSLeft+',screenY='+WinSTop+'');
}
function IsNumeric(strString)
{
	var strValidChars = "0123456789.";
	var strChar;
	var blnResult = true;
	if(strString.length==0)
	return false;
	for(i=0;i<strString.length && blnResult==true; i++)
	{
		strChar=strString.charAt(i);
		if(strValidChars.indexOf(strChar)==-1)
		{
			blnResult = false;
		}
	}
	 return blnResult;
}
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;
	var selectcounted =0;
	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;				
				selectcounted = selectcounted + 1;
			}
		}
	}
	document.getElementById('opt_com').value=selet;
	//confirm(selet);
	if(selectcounted<1)
	{
		alert('Please select some checkboxes...');
		return false;	
	}
	return true;
}
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 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 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);
}
//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;
}
function swap_css(element,class1,class2)
{
//	alert(' ' + element +' css1 '+ class1 +' css2 '+ class2);
	if(element.className==class1)
	{
		element.className=class2;
	}
	else
	{
		element.className=class1;
	}
}
function checkSelected(form)
{
	var selected = false;
	selectedCount = 0;	

	form = document.form;
	var elems = form.elements;

	for( var i=0; i < elems.length; i++) {
		if( elems[i].id.indexOf(':checkbox') !=-1 ) {
			if(elems[i].checked) {
				selected = true;
				selectedCount = selectedCount + 1;
			}
		}
	}
	//alert(selectedCount);
	if(selectedCount<1) 
	{
		alert('Please Select at least One messages to Continue.');
		//return false;
	}
	return selected;
	//return true;
}
function doNothing(oEvent)  
{
	window.focus();	
	if (window.event) 
	{
	  oEvent.cancelBubble = true;	
	  oEvent.returnValue = false;	
	}	
	return false;
}
function TxtAREA_countit(what,err_id,t_limit)
{
	formcontent=what.value;
	ge('displaycount').value=t_limit-formcontent.length;
	if(formcontent.length>t_limit)
	{
		//alert('No more character left');
		show(err_id);
		what.value=what.value.substr(0,t_limit);		
	}
}
function disableImgDownload()
{//disableImgDownload(); disable image download functiom
	var oImgList = document.getElementsByTagName('img');	
	for (var i = 0; i < oImgList.length; i++)	
	{	
		//alert(oImgList[i].oncontextmenu);
		if (window.Event)
			oImgList[i].oncontextmenu = function(event) { return doNothing(event); };	
		else	
			oImgList[i].oncontextmenu = function() { return doNothing(event); };	
	}
}
window.onload=disableImgDownload;
/////start by anuj/////////////
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function showRefineSearch(id1,id2)
{
	elem=document.getElementById(id1);
	elem1=document.getElementById(id2);
	if (elem.style.display=='none') {
		elem.style.display='block';
		//elem1.innerHTML='Hide Refine Search';
		//elem1.checked;
	} else {
		elem.style.display='none';
		//elem1.innerHTML='Click to refine search';
		//elem1.unchecked='false';
	}
	return false;
}