function isUserRole()
{
   
   if (document.getElementById('role_id').value==4 || document.getElementById('role_id').value==5 || document.getElementById('role_id').value==6){
      document.getElementById('show_search').style.display="block";
   }
   else {
   		document.getElementById('show_search').style.display="none";
   }
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function OnDelete(oForm, id)
	    {
	    	if (confirm('Are you sure want to delete this?')) {
		    	document.forms['sdds'].elements['cmd'].value = 'delete';	    	
		    	document.forms['sdds'].elements['category_id'].value = id;
		    	document.forms['sdds'].action = 'manage_categories.php';
		    	document.forms['sdds'].submit();
		    }
	    }  
	    
function OnDeleteForum(oForm, id)
        {
            if (confirm('Are you sure want to delete this?')) {
                document.location.href = '?category_id=' + id + '&cmd=delete';
            }
        }       
 
 function popUpResource(res_id)
{
    window.open('show_resource.php?res_id=' + res_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=500');
}
        
function PopUpEventRes(survey_id)
{
    window.open('event_results.php?survey_id=' + survey_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');
}

function popUp(survey_id)
{
    window.open('survey_ask.php?survey_id=' + survey_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');
}

function votePopUp(voting_id)
{
    window.open('voting_ask.php?voting_id=' + voting_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');
}
function popUpS(survey_id)
{
    window.open('survey_ask.php?survey_id=' + survey_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');
}
function popUpSRes(survey_id)
{
    window.open('survey_results.php?survey_id=' + survey_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');
}
function votePopUp(voting_id)
{
    window.open('voting_ask.php?voting_id=' + voting_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');
}
function votePopUpRes(voting_id)
{
    window.open('voting_results.php?voting_id=' + voting_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');
}
function OnDeleteProduct(oForm, id)
	    {
	    	if (confirm('Are you sure want to delete this?')) {
		    	document.forms['sdds'].elements['cmd'].value = 'delete';	    	
		    	document.forms['sdds'].elements['product_id'].value = id;
		    	document.forms['sdds'].action = 'manage_products.php';
		    	document.forms['sdds'].submit();
		    }
	    }  	 
function popupPermis(resource_id)
{
	window.open('upload_permissions.php?cmd=edit&resource_id=' + resource_id, null, 'width=500px, height=500px, scrollbar: no;');
}
function updater(oForm, name, checked)
	{
		if (oForm.elements["extfilter[from][" + name + "]"]) {
			oForm.elements["extfilter[from][" + name + "]"].disabled = !checked;
		}
		if (oForm.elements["extfilter[to][" + name + "]"]) {
			oForm.elements["extfilter[to][" + name + "]"].disabled = !checked;
		}	
	}	
function addAnswer()
{
    document.forms['question'].elements['cmd'].value = 'add_answer';
    document.question.submit();
}
function isUSA()
        {
            if (document.getElementById('country').value != document.getElementById('country').options[0].value){
                document.getElementById('state').options[1].selected = true;
                document.getElementById('state').disabled = true;
            }else{
                if (document.getElementById('state').options[0].selected || document.getElementById('state').options[1].selected) {
                    document.getElementById('state').options[0].selected = true;
                    document.getElementById('state').disabled = false;
                }
            }
        }
        
        function isOutside()
        {
            if (document.getElementById('state').options[1].selected){
                document.getElementById('country').options[1].selected = true;
            }
        }
 function popUpCreate(survey)
{
    window.open('event_manage_questions.php?cmd=create&survey_id=' + survey, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600');
}
function popUpEdit(question_id)
{
    window.open('manage_event_questions.php?cmd=edit&popup=on&question_id=' + question_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600');
}



function selectCategory (){
		var	selCat = document.getElementById('catList').selectedIndex;
		var selCatText = document.getElementById('catList').options[selCat].text;
		document.getElementById('category').value = selCatText;
	}
	
	function saveCategory(){
		var	selCat = document.getElementById('catList').selectedIndex;
		var selCatText = document.getElementById('catList').options[selCat].text;
		document.f1.elements[0].value = 'edit_on';
		
		if (!document.getElementById('catList').options[selCat].value && document.getElementById('category').value == ''){
				alert('Select category or enter new category');
				return false;
		}
		if (document.getElementById('catList').options[selCat].value && document.getElementById('category').value == ''){
				alert('Please change category name');
				return false;
		}
		if (document.getElementById('category').value == selCatText){
				alert('No data has been changed');
				return false;
		}
	}
		
	function deleteCategory(){
		document.f1.elements[0].value = 'delete';
		var	selCat = document.getElementById('catList').selectedIndex;
		var selCatText = document.getElementById('catList').options[selCat].text;
		var catId = document.getElementById('catList').options[selCat].value;
		if (document.getElementById('catList').options[selCat].value){
			confirm("Are you sure what delete category " + selCatText + "?");
			document.getElementById('catId').value = catId;
			return true;
		}
		if(!document.getElementById('catList').options[selCat].value){
			alert('Please select a category');
			return false;
		}
	}
function cancelForm() 
{
for (i=0; i<document.frm.elements.length; i++)
{
	if (document.frm.elements[i].id=='cmd')
	{
		document.frm.elements[i].value='cancel_form';	
	}
	document.frm.submit();
}
}



function checkAll(name)
{
    var regstr = name.substring(1, name.length) + '[\[]';

    if (window.RegExp) {
        var reg = new RegExp(regstr, "i");
        reg.compile(regstr, "i");
        if (document.getElementById(name).checked == true)
        {
            for (i = 0; i < document.defaults.elements.length; i++) {
                if (reg.exec(document.defaults.elements[i].name))
                    document.defaults.elements[i].checked = true;
            }
        } else {
            for (i = 0; i < document.defaults.elements.length; i++) {
                if (reg.exec(document.defaults.elements[i].name))
                    document.defaults.elements[i].checked = false;
            }
        }
    } else {
        alert('Your browser does not support this future.');
    }
}

function checkTotal(group_box_name, user_box_name)
{
    var reg_str = user_box_name;
    var reg = new RegExp(reg_str, "i");
    var edited_user = new Array();
    
    reg.compile(reg_str, "i");
    k = 0;
    for (i = 0; i < document.defaults.elements.length; i++) {
        if (reg.exec(document.defaults.elements[i].name)) {
            name = document.defaults.elements[i].name;
            edited_user[k] = name.substring(reg_str.length + 1, name.length - 1);
            k++;
        }
    }
    
    for (i = 0; i < edited_user.length; i++) {
        if (document.getElementById(reg_str + '[' + edited_user[i] + ']').checked) {
            document.getElementById('TOTAL[' + edited_user[i] + ']').checked = true;
        } else {
            if (document.getElementById(group_box_name + '[' + edited_user[i] + ']').checked) {
                document.getElementById('TOTAL[' + edited_user[i] + ']').checked = true;
            } else {
                document.getElementById('TOTAL[' + edited_user[i] + ']').checked = false;
            }
        }
    }
}

var checkobj;
		function enablerForm(el){
			checkobj=el;
			if (document.all||document.getElementById){
				for (i=0;i<checkobj.form.length;i++){  
				var tempobj=checkobj.form.elements[i];
				if(tempobj.id == 'head')
				tempobj.disabled=!checkobj.checked;
				}
			}
		}
function clickit(cn,clink) {
	  if(document.images) {
	     (new Image()).src="clickstats.php?num="+cn+"&url="+clink+"&val={/literal}{$js_string}{literal}";
	  }
	  return true;
	}
function popupZip(dealer_id)
		{	
			for (i=0; i<document.fum.elements.length; i++)
			{
				if (document.fum.elements[i].name=='f[dealer_id]')
				{
					dealer_id=document.fum.elements[i].value;
				}
			}
			
			window.open('view_zips.php?dealer_id=' + dealer_id, null, 'scrollbars=yes, resizable=yes, width=600px, height=600px');
		}
function popUpQuestion(question_id)
{
    window.open('survey_ask.php?question_id=' + question_id, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');
}
function popCreateSu(survey)
{
    window.open('event_manage_questions.php?cmd=create&survey_id=' + survey, 'myWindow', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600');
}				          