// JavaScript Document
// **********************************   common validation functions	 **********************************************
function makeObject(){
	var x; 
	var browser = navigator.appName; 
	//detect the client browser
	if(browser == "Microsoft Internet Explorer"){
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		x = new XMLHttpRequest();
	}
	
	return x;
}
	//call the function makeObject()
		//call the function makeObject()	
	//call the function makeObject()
	var request = makeObject();
    var md="";
    var popupwindow;
function is_selected(cbo){
	if(cbo.value=="EMPTY"){
		var nm=cbo.name.split("_");
		var b_nm=nm[1].toUpperCase();
		alert("The field \'"+b_nm+"\' cannot be empty. Please Select a Value form the drop down");
		cbo.focus();
		return false;
	}
	else{return true;}	
}
function refresh_main_page(){
	opener.location.reload();
	return true;
	
}
function chk_empty(bx){
	if(bx.value==""){
		var nm=bx.name.split("_");
		var b_nm=nm[1].toUpperCase();
		alert("The field \'"+b_nm+"\' cannot be empty. Please enter a valid value");
		bx.focus();
		return false;
	}
	else{return true;}	
}
function checkEmail(cho) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(cho.value)){
return (true);
}
alert("Invalid E-mail Address! Please re-enter.");
cbo.focus();
return (false)
}
///////////////////////////////////
function login_submit(){
	if((document.admin_login.username.value!="")&&(document.admin_login.password.value!="")){
		document.admin_login.action="process.php?val=login";
		document.admin_login.submit();
	}
	else{alert("Username and Password cannot be empty. Please enter valid values");}	
}

////////////////////////////////
function details(ls,ne,rand){

	if((ls=="add_category")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=215,width=500,scrollbars=yes');}
	if((ls=="add_event")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=400,width=600,scrollbars=yes');}
	if((ls=="add_news")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=400,width=600,scrollbars=yes');}
	if((ls=="add_item")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=400,width=600,scrollbars=yes');}
	if((ls=="add_officials")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=400,width=500,scrollbars=yes');}
	if((ls=="add_com_members")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=400,width=500,scrollbars=yes');}
	if((ls=="add_members")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=400,width=500,scrollbars=yes');}
	if((ls=="add_com_photos")&&(ne=="no")){popupwindow=window.open(ls+'.php?user='+rand,'popup','status=yes,height=300,width=700,scrollbars=yes');}
	if(ls=="edit_category"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=180,width=400,scrollbars=yes');}
	if(ls=="edit_com_member"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=180,width=400,scrollbars=yes');}
	if(ls=="edit_member"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=180,width=500,scrollbars=yes');}
	if(ls=="edit_event"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=400,width=500,scrollbars=yes');}
	if(ls=="edit_news"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=400,width=500,scrollbars=yes');}
	if(ls=="edit_item"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=400,width=500,scrollbars=yes');}
	if(ls=="edit_com_photo"){popupwindow=window.open(ls+'.php?val='+ne+'&user='+rand,'popup','status=yes,height=250,width=400,scrollbars=yes');}
	if((ls=="add_photo")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','status=yes,height=500,width=760,scrollbars=yes');}
	if((ls=="add_message")&&(ne=="no")){popupwindow=window.open(ls+'.php','popup','status=yes,height=400,width=400,scrollbars=yes');}
	if(ls=="delete_photo"){popupwindow=window.open('delete_photo.php?val='+ne+'&mode='+ls+'','popup','height=500,width=550,scrollbars=yes');}
	if(ls=="inactivate_photo"){popupwindow=window.open('inactivate_photo.php?val='+ne+'&mode='+ls+'','popup','height=500,width=550,scrollbars=yes');}
	if(ls=="activate_photo"){popupwindow=window.open('activate_category.php?val='+ne+'&mode='+ls+'','popup','height=200,width=400,scrollbars=yes');}
	if((ls=="view_message")||(ls=="inactivate_message")||(ls=="activate_message")||(ls=="delete_message")){popupwindow=window.open('view_message.php?mode='+ls+'&val='+ne,'popup','height=400,width=400,scrollbars');}
    if((ls=="view_com_member")||(ls=="delete_com_member")){popupwindow=window.open('view_com_member.php?mode='+ls+'&val='+ne,'popup','height=160,width=400,scrollbars');}
	if((ls=="view_member")||(ls=="delete_member")){popupwindow=window.open('view_member.php?mode='+ls+'&val='+ne,'popup','height=160,width=600,scrollbars');}
	if((ls=="view_event")||(ls=="delete_event")){popupwindow=window.open('view_event.php?mode='+ls+'&val='+ne,'popup','height=400,width=600,scrollbars');}
	if((ls=="view_item")||(ls=="delete_item")){popupwindow=window.open('view_item.php?mode='+ls+'&val='+ne,'popup','height=400,width=600,scrollbars');}
	if((ls=="view_news")||(ls=="delete_news")){popupwindow=window.open('view_news.php?mode='+ls+'&val='+ne,'popup','height=400,width=600,scrollbars');}
	if((ls=="view_com_photo")||(ls=="delete_com_photo")){popupwindow=window.open('view_com_photo.php?mode='+ls+'&val='+ne,'popup','height=500,width=600,scrollbars');}
	if(ls=="view_photo"){popupwindow=window.open('view_photo.php?val='+ne+'&mode='+ls+'','popup','height=400,width=450,scrollbars=yes');}	
	if(ls=="view_large"){popupwindow=window.open('view_large.php?val='+ne+'&mode='+ls+'','popup','height=600,width=600,scrollbars=yes');}
popupwindow.focus();
}

/*function show_large(ne){
	popupwindow=window.open('view_large.php?val='+ne,'popup','height=300,width=450');
	popupwindow.focus();
}*/

// **********************************   add functions	 **********************************************
function show_large(ne){
	popupwindow=window.open('view_large.php?val='+ne,'popup','height=600,width=610');
	popupwindow.focus();
}

function add_category(){
	if(chk_empty(document.addcategory.addcategory_name)){
			document.addcategory.action="process.php?val=add_category";
			document.addcategory.submit();
			return true;
	}
	else{return false;}	
}
function add_message(){
	if((chk_empty(document.addmessage.addmessage_title))&&(chk_empty(document.addmessage.addmessage_message))&&(chk_empty(document.addmessage.addmessage_name))&&(checkEmail(document.addmessage.addmessage_email))){
			document.addmessage.action="process.php?val=add_message";
			document.addmessage.submit();
			return true;
	}
	else{return false;}	
}
function add_event(){
	if((chk_empty(document.addevent.addevent_date))&&(chk_empty(document.addevent.addevent_descrip))){
			document.addevent.action="process.php?val=add_event";
			document.addevent.submit();
			return true;
	}
	else{return false;}	
}
function add_news(){
	if((chk_empty(document.addnews.addnews_title))&&(chk_empty(document.addnews.addnews_descrip))){
			document.addnews.action="process.php?val=add_news";
			document.addnews.submit();
			return true;
	}
	else{return false;}	
}

	
function add_item(){
	if((chk_empty(document.additem.additem_title))&&(chk_empty(document.additem.additem_descrip))){
		if (document.getElementById('additem_file').value!=""){
		 var filename = document.getElementById('additem_file').value;
		  var fileext = filename.substring(filename.lastIndexOf('.')+1);
		  var b = String(fileext).toUpperCase();
		   if ((b == 'EXE')) {
			   alert("You can not upload executable files ");
			   return ;
			   
		   }
		    if ((b == 'TXT')) {
			   alert("You can not upload script files ");
			   return ;
			   
		   }
	}
		
			document.additem.action="process.php?val=add_item";
			document.additem.submit();
			return true;
	}
	else{return false;}	
}
function add_officials(){
	var all_empty=1;
	for( x=1; x<11; x++){
		var name='name'+x;
		var post='post'+x;
		if (document.getElementById(name).value!=""){
			all_empty=0;
		}
		if (document.getElementById(post).value!=""){
			all_empty=0;
		}
		
	}
	
	if (all_empty!=0){
			alert("Add a value");
				}
	else{	 
			document.addofficials.action="process.php?val=add_officials";
			document.addofficials.submit();
			return true;	
			}
			
	
}

function add_com_members(){
	var all_empty=1;
	for( x=1; x<11; x++){
		var name='name'+x;
		
		if (document.getElementById(name).value!=""){
			all_empty=0;
		}
		
		
	}
	
	if (all_empty!=0){
			alert("Add a value");
				}
	else{	 
			document.addcommembers.action="process.php?val=add_com_members";
			document.addcommembers.submit();
			return true;	
			}
			
	
}
function add_members(){
	var all_empty=1;
	for( x=1; x<11; x++){
		var name='name'+x;
		
		if (document.getElementById(name).value!=""){
			all_empty=0;
		}
		
		
	}
	
	if (all_empty!=0){
			alert("Add a value");
				}
	else{	 
			document.addmembers.action="process.php?val=add_members";
			document.addmembers.submit();
			return true;	
			}
			
	
}

function add_photo(){
	var i=1;
	if(is_selected(document.addphoto.add_category)){
	var all_empty=1;
	var all_jpg=1;
		for( x=1; x<11; x++){
			var name='img'+x;
					if (document.getElementById(name).value!=""){
					  var filename = document.getElementById(name).value;
					  var fileext = filename.substring(filename.lastIndexOf('.')+1);
						all_empty=0;
						
						var b = String(fileext).toUpperCase();
					 if ((b != 'JPG')) {
						  all_jpg=0;
						alert("You can only upload .jpg & .jpeg images , Image \'"+name+"\' is invalid ");                 	    					}
						 if ((b == 'EXE')) {
			  				 alert("You can not upload executable files ");
			  			 return ;
			   
		  				 }
		   				 if ((b == 'TXT')) {
			  				 alert("You can not upload script files ");
			  			 return ;
			   
		 				  }
						
					} 
			}
	if (all_empty!=0){
			alert("Select a Image to Upload");
				}
	else if (all_jpg!=0){	 
			document.addphoto.action="process.php?val=add_photo";
			document.addphoto.submit();
			return true;	
			}
			
	}
				else{return false;}	
}
function add_com_photo(){
	var i=1;
	var all_empty=1;
	var all_jpg=1;
		for( x=1; x<6; x++){
			var name='img'+x;
					if (document.getElementById(name).value!=""){
					  var filename = document.getElementById(name).value;
					  var fileext = filename.substring(filename.lastIndexOf('.')+1);
						all_empty=0;
						
						var b = String(fileext).toUpperCase();
					 if ((b != 'JPG')) {
						  all_jpg=0;
						alert("You can only upload .jpg & .jpeg images , Image \'"+name+"\' is invalid ");                 	    					}
						 if ((b == 'EXE')) {
			   			alert("You can not upload executable files ");
			 		  return ;
			   
		  				 }
		   			 if ((b == 'TXT')) {
			  		 alert("You can not upload script files ");
			  		 return ;
			   
		  		 }
						
					} 
			}
	if (all_empty!=0){
			alert("Select a Image to Upload");
				}
	else if (all_jpg!=0){	 
			document.addcomphoto.action="process.php?val=add_com_photo";
			document.addcomphoto.submit();
			return true;	
			}
			
	
}
/*function add_photo(){
	if(is_selected(document.addphoto.add_category)){
			document.addphoto.action="process.php?val=add_photo";
			document.addphoto.submit();
			return true;
	}
	else{return false;}	
}*/
function delete_com_member(mde){
	document.viewcommember.action="process.php?val="+mde;
	document.viewcommember.submit();
}
function delete_member(mde){
	document.viewmember.action="process.php?val="+mde;
	document.viewmember.submit();
}
function delete_event(mde){
	document.viewevent.action="process.php?val="+mde;
	document.viewevent.submit();
}
function delete_item(mde){
	document.viewitem.action="process.php?val="+mde;
	document.viewitem.submit();
}
function delete_news(mde){
	document.viewnews.action="process.php?val="+mde;
	document.viewnews.submit();
}
function delete_com_photo(mde){
	document.viewcomphoto.action="process.php?val="+mde;
	document.viewcomphoto.submit();
}
function delete_message(mde){
	document.viewmessage.action="process.php?val="+mde;
	document.viewmessage.submit();
}
function activate_message(mde){
	document.viewmessage.action="process.php?val="+mde;
	document.viewmessage.submit();
}
function inactivate_message(mde){
	document.viewmessage.action="process.php?val="+mde;
	document.viewmessage.submit();
}


// **********************************   edit functions	 **********************************************
function edit_category(){
	document.editcategory.action="process.php?val=EDIT_category";
	document.editcategory.submit();
}

function edit_com_member(){
	if((chk_empty(document.editcommember.commember_post))&&(chk_empty(document.editcommember.commember_name))){
	document.editcommember.action="process.php?val=edit_com_member";
	document.editcommember.submit();
	}
	else{return false;}	
}
function edit_member(){
	document.editmember.action="process.php?val=edit_member";
	document.editmember.submit();
}
function edit_event(){
	document.editevent.action="process.php?val=edit_event";
	document.editevent.submit();
}
function edit_news(){
	document.editnews.action="process.php?val=edit_news";
	document.editnews.submit();
}


function edit_com_photo(){
	var name='image';
	if (document.getElementById(name).value!=""){
		 var filename = document.getElementById(name).value;
		  var fileext = filename.substring(filename.lastIndexOf('.')+1);
		  var b = String(fileext).toUpperCase();
		   if ((b != 'JPG')) {
			   alert("You can only upload .jpg & .jpeg images , Image \'"+name+"\' is invalid ");
			   return ;
			   
		   }	   		 
	}
	
	document.editcomphoto.action="process.php?val=edit_com_photo";
	document.editcomphoto.submit(); 
	
	
}
function edit_item(){
	if((chk_empty(document.edititem.edititem_title))&&(chk_empty(document.edititem.edititem_descrip))){
	var name='edititem_file';
	if (document.getElementById(name).value!=""){
		 var filename = document.getElementById(name).value;
		  var fileext = filename.substring(filename.lastIndexOf('.')+1);
		  var b = String(fileext).toUpperCase();
		    if ((b == 'EXE')) {
			   			alert("You can not upload executable files ");
			 		  return ;
			   
		  				 }
		   			 if ((b == 'TXT')) {
			  		 alert("You can not upload script files ");
			  		 return ;
			   
		  		 }   		 
	}
	
	document.edititem.action="process.php?val=edit_item";
	document.edititem.submit(); 
	}
	
}

/*function add_brand(){
	if(chk_empty(document.addbrand.addbrand_name)){
		
		if (document.getElementById('addbrand_logo').value!=""){
			var filename = document.getElementById('addbrand_logo').value;
			var fileext = filename.substring(filename.lastIndexOf('.')+1);
			var b = String(fileext).toUpperCase();
				if ((b != 'JPG')) {
				alert ("You can only upload .jpg & .jpeg images  brand logo is invalid "); 
				return ;
				} 
		}
			document.addbrand.action="process.php?val=ADD_BRAND";
			document.addbrand.submit();
			return true;
	}
	else{return false;}	
}*/

// **********************************   delete functions	 **********************************************
function delete_category(){

document.deletecategory.action="process.php?val=delete_category";
document.deletecategory.submit();
}
function delete_category_cancel(){

window.close();
}

function inactivate_category(){

document.inactivatecategory.action="process.php?val=inactivate_category";
document.inactivatecategory.submit();
}
function activate_category(){

document.inactivatecategory.action="process.php?val=activate_category";
document.inactivatecategory.submit();
}

function delete_category_cancel(){

window.close();
}

function delete_photo(ls,ne){
	{
		popupwindow=window.open('delete_photo_confirm.php?val='+ne+'&mode='+ls+'','popup','height=50,width=100,scrollbars=yes');	
	//opener.location.reload();
	//return true;
	}
}
function delete_photo_confirm(ne,cid){
	document.deletephoto.action="process.php?val=delete_photo_confirm&id="+ne+"&cid="+cid;
	document.deletephoto.submit();
}
 
function delete_photo_confirm_cancel(cid){
	document.deletephoto.action="process.php?val=delete_photo_confirm_cancel&cid="+cid;
	document.deletephoto.submit();
}
function inactivate_photo(ls,ne){
	{
		popupwindow=window.open('inactivate_photo_confirm.php?val='+ne+'&mode='+ls+'','popup','height=50,width=100,scrollbars=yes');	
	//opener.location.reload();
	//return true;
	}
}
function inactivate_photo_confirm(ne,cid){
	document.inactivatephoto.action="process.php?val=inactivate_photo_confirm&id="+ne+"&cid="+cid;
	document.inactivatephoto.submit();
}
 
function inactivate_photo_confirm_cancel(cid){
	document.inactivatephoto.action="process.php?val=inactivate_photo_confirm_cancel&cid="+cid;
	document.inactivatephoto.submit();
}
 
 function activate_photo(ls,ne){
	{
		popupwindow=window.open('activate_photo_confirm.php?val='+ne+'&mode='+ls+'','popup','height=50,width=100,scrollbars=yes');	
	//opener.location.reload();
	//return true;
	}
}
function activate_photo_confirm(ne,cid){
	document.activatephoto.action="process.php?val=activate_photo_confirm&id="+ne+"&cid="+cid;
	document.activatephoto.submit();
}
 
function activate_photo_confirm_cancel(cid){
	document.activatephoto.action="process.php?val=activate_photo_confirm_cancel&cid="+cid;
	document.activatephoto.submit();
}
function check_duplicate_categoryname(bx){
	request.open('get', 'process.php?val=check_duplicate_categoryname&user='+bx.value);
	request.onreadystatechange = chk_duplicate;
	request.send('');
}

function chk_duplicate(){
	if (request.readyState == 1) {
		document.all.aj_msg.innerHTML="Loading.....";
		document.all.addcategory.addcategory_submit.disabled="Disabled";
	}
	if (request.readyState == 4) {
		document.all.aj_msg.innerHTML="&nbsp;";
		document.all.addcategory.addcategory_submit.disabled=false;
	if (request.status == 200) {
	if(request.responseText!=""){
//document.all.addusers.addusers_person.value="";
//document.all.addindustry.addindustry_name.value="";
	document.all.addcategory.addcategory_submit.disabled="Disabled";
//document.all.editcategory.editcategory_name.value="";
	alert(request.responseText);
}
}
else {
	alert('There was a problem with the request.');
}
}
}
function check_duplicate_categoryname_edit(bx){
	request.open('get', 'process.php?val=check_duplicate_categoryname&user='+bx.value);
	request.onreadystatechange = chk_duplicate_edit;
	request.send('');
}

function chk_duplicate_edit(){
	if (request.readyState == 1) {
		document.all.aj_msg.innerHTML="Loading.....";
		document.all.editcategory.editcategory_submit.disabled="Disabled";
	}
	if (request.readyState == 4) {
		document.all.aj_msg.innerHTML="&nbsp;";
		document.all.editcategory.editcategory_submit.disabled=false;
	if (request.status == 200) {
	if(request.responseText!=""){
//document.all.addusers.addusers_person.value="";
//document.all.addindustry.addindustry_name.value="";
	document.all.editcategory.editcategory_submit.disabled="Disabled";
//document.all.editcategory.editcategory_name.value="";
	alert(request.responseText);
}
}
else {
	alert('There was a problem with the request.');
}
}
}



/*function add_to_home_page(stat,ne){
	if(stat=="R"){
		if(confirm("Are you sure ? Click Ok to Remove")){
			document.home_image.action="process.php?val=ADD_HOME&img="+ne;
			document.home_image.submit();					
		}	
	}			
	if(stat=="P"){alert("Can not add the image. Remove the existing Home image first");}			
	if(stat=="A"){
		if(confirm("Are you sure ? Click Ok to Add")){
			document.home_image.action="process.php?val=ADD_HOME&img="+ne;
			document.home_image.submit();					
		}
	}			
}
*/



// JavaScript Document