/***************************************************************************/
/*     PROGRAMMER     :  SDYA                                              */
/*     SCRIPT NAME    :  admin.js                                          */
/*     CREATED ON     :  11/DEC/2006                                       */
/*     LAST MODIFIED  :  18/DEC/2006  	                                   */
/*                                                                         */
/*     Java Script Functions For the admin area                            */
/***************************************************************************/

	/*----------------------------------------------------------------
	Description   :- function to validate an email id
	Programmer    :- SDYA
	Last Modified :- 11/DEC/2006
	-------------------------------------------------------------------*/
	function isBadEmail(strg) {
		email_array = strg.split('@');
		if (email_array.length != 2) return true;
		if (email_array[1].split(".").length < 2) return true;
		if (email_array[1].split(".")[1].length < 1) return true;
		if (strg.indexOf('@') < 1) return true;
		if (strg.indexOf(' ') != -1) return true;
		if (email_array[1].indexOf('.') < 1) return true;
		if (strg.length < 5) return true;
		return false;
	}
	
	/*----------------------------------------------------------------
	Description   :- function to validate the login form
	Programmer    :- SDYA
	Last Modified :- 11/DEC/2006
	-------------------------------------------------------------------*/
	function validate()
	{
		if(document.frmassigndept.sel_deptname.value=='')
		{
			alert("Please Select a Department");
			return false;
		}
		return true;
	}

	function login_validate(msg,msg2)
	{
		//user name
		if(document.frm_login.txt_uname.value=="")
		{
			alert(msg);
			document.frm_login.txt_uname.focus();
			return false;
		}
		//password
		if(document.frm_login.txt_pwd.value=="")
		{
			alert(msg2);
			document.frm_login.txt_pwd.focus();
			return false;
		}
		return true;
	}

	/*----------------------------------------------------------------
	Description   :- function to confirm the status updating of a record
	Programmer    :- SDYA
	Last Modified :- 11/DEC/2006
	-------------------------------------------------------------------*/
	function updatestatusconfirm(page,name,id,status,mode,flag,searchstr,invflag)
	{ // alert( page+"?name="+name+"&id="+id+"&status="+status+"&mode="+mode+"&action="+flag+"&search="+searchstr+"&invflag="+invflag);
 		//if(confirm("Are you sure to modify the " + status +" status of this " + name + "?"))
		if(confirm("Are you sure to modify the status of this " + name + "?")){
 			window.location = page+"?name="+name+"&id="+id+"&status="+status+"&mode="+mode+"&action="+flag+"&search="+searchstr+"&invflag="+invflag;
		}
	}
	
	/*----------------------------------------------------------------
	Description   :- function to confirm the deletion of a record
	Programmer    :- SDYA
	Last Modified :- 11/DEC/2006
	-------------------------------------------------------------------*/
	function deleteconfirm(page,name,id,mode,searchstr,invflag)
	{   
 		if(confirm("Are you sure you want to delete this " + name + "?\nIf 'OK' all the information associated with this " + name + " will be removed from the system.\nYou cannot UNDO this process."))
		window.location = page + "?id=" + id + "&name=" + name +"&mode=" +mode+"&search="+searchstr+"&invflag="+invflag+"&action="+mode;
	}
	
	/*----------------------------------------------------------------
	Description   :- function to confirm the deletion of a Issued card
	Programmer    :- SBI
	Last Modified :- 18-09-07
	-------------------------------------------------------------------*/
	function deleteissuedcard(name,id,listview)
	{//alert("inner"+listview+id);
		if(confirm("Are you sure you want to delete this " + name + "?\nIf 'OK' all the information associated with this " + name + " will be removed from the system.\nYou cannot UNDO this process."))
		window.location = "index.php?process=issuedcards&action=delete&cardid="+id+"&listview="+listview;
	}
	
	/*----------------------------------------------------------------
	Description   :- function to change change Issued card listing
	Programmer    :- SBI
	Last Modified :- 18-09-07
	-------------------------------------------------------------------*/
	function ChangecardList()
	{ 
		if(document.frm_view.drp_change.value==1){
		
			window.location = "index.php?process=issuedcards&listview=1";
			
		}else{
			window.location = "index.php?process=issuedcards&listview=0";
		}
	 }
 
 
 
 
 /*----------------------------------------------------------------
	Description   :- function to confirm the deletion of a record in dept,operator
	Programmer    :- IKB
	Last Modified :- 01/JAN/2007
	-------------------------------------------------------------------*/
	
	function deleteconfirmaion(page,name,id,mode,msg,msg1,msg3)
	{
		if(confirm(msg+ name + "?\n"+ msg1 + name + msg3))
		window.location = page + "?" +mode;

	}
	function cofirmchatend(page,actions,msg)
	{  
		if(confirm(msg))
		window.location = page + "?" + actions;
	}
	/*----------------------------------------------------------------
	Description   :- function to open a new window
	Programmer    :- ASW
	Last Modified :- 11/DEC/2006
	-------------------------------------------------------------------*/
	function OpenWindow(url)
	{
	nw = open(url,'new','height=450,width=450,scrollbars=yes,resizable=1');
	nw.focus();
	}
	
	/*----------------------------------------------------------------
	Description   :- function to show the help for menu 
	Programmer    :- ASW
	Last Modified :- 11/DEC/2006
	-------------------------------------------------------------------*/
	function showHelp(menu){
	var message;
	switch(menu){
	case 'department': message = 'Manage Departments here '; break;
	case 'operator': message = 'Manage Operator Info here.'; break;
	}
	var help = document.getElementById('help');
	help.innerHTML=message;
	help.style.visibility = 'visible';
	}
	
	/*----------------------------------------------------------------
	Description   :- function to hide the help for menu 
	Programmer    :- ASW
	Last Modified :- 11/DEC/2006
	-------------------------------------------------------------------*/
	function hideHelp(){
		var help = document.getElementById('help');
		help.style.visibility = 'hidden';
	}
	

	/*----------------------------------------------------------------
	Description   :- function to hide the help for menu 
	Programmer    :- ASW
	Last Modified :- 13/DEC/2006
	-------------------------------------------------------------------*/
	function validate_greeting(frm_grt)
	{
		if(frm_grt.txt_geeting.value == "")
		{
			alert("Please enter the greeting");
			frm_grt.txt_geeting.focus();
			return false;
		}
		return true;
	}
	
	/*----------------------------------------------------------------
	Description   :- function to get numbers only for the textbox
	Programmer    :- SDYA
	Last Modified :- 15/DEC/2006
	-------------------------------------------------------------------*/
	function numbersonly(e)
	{
		var key;
		var keychar;
		
		if (window.event)
		key = window.event.keyCode;
		else if (e)
		key = e.which;
		else
		return true;
		
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
		else if ((("0123456789").indexOf(keychar) > -1))
		return true;
		else
		return false;
	}
	
	/*----------------------------------------------------------------
	Description   :- function to validate manage ips
	Programmer    :- SDYA
	Last Modified :- 15/DEC/2006
	-------------------------------------------------------------------*/
	function manageips_validate(msg,msg1,msg2)
	{
		if ( ( document.frmip.ip1.value == "" ) || ( document.frmip.ip2.value == "" )
			|| ( document.frmip.ip3.value == "" ) || ( document.frmip.ip4.value == "" ) )
		{
			alert( msg ) ;
			return false;
		}
		else if ( ( document.frmip.ip1.value > 255 ) || ( document.frmip.ip2.value > 255 )
			|| ( document.frmip.ip3.value > 255 ) || ( document.frmip.ip4.value > 255 ) )
		{
			alert( msg1 ) ;
			return false;
		}
		else
		{
			if ( confirm(msg2) )
				document.frmip.submit() ;
		}
	}	
	
	/*----------------------------------------------------------------
	Description   :- function to validate emailtranscripts page
	Programmer    :- SDYA
	Last Modified :- 16/DEC/2006
	-------------------------------------------------------------------*/
	function emailtranscripts_validate()
	{
		//subject
		if(document.frmemail.txt_subject.value=="")
		{
			alert("Please enter the subject");
			document.frmemail.txt_subject.focus();
			return false;
		}
		//content
		if(document.frmemail.txta_content.value=="")
		{
			alert("Please enter the content of the message");
			document.frmemail.txta_content.focus();
			return false;
		}
	}	
	
	function ShowActiveImage(id)
	{
		image = "../images/b_"+id+"-over.gif";
		document.getElementById(id).src=image;
		div = "div_"+id;
		document.getElementById(div).style.display='block';
		
	}
	function ShowInActiveImage(id)
	{
		image = "../images/b_"+id+".gif";
		document.getElementById(id).src=image;
		div = "div_"+id;
		document.getElementById(div).style.display='none';
	}	
	
function showWindow(depid,type){
	var text=document.getElementById("linktext").value ;
	if(text != ""){
		mywindow = window.open("generatehtml.php?action=textlink&did="+depid+"&text="+text+"&type="+type,"mywindow","location=NO,status=NO,scrollbars=YES,resize=NO,directories=NO,width=500,height=200");
		mywindow.moveTo(100,200);
		mywindow.focus();	
	}
  }
 
function openChat(deptid,url)
{
	var url = "../chat/index.php?act=chatuser&deptid="+deptid;
	var params = "location=0,status=0,scrollbars=1, width=410,height=450";
	mywindow = window.open (url, "userWindow",params);
	mywindow.moveTo(0,0);	
}

function openChatTranscript(chatId)
{
	var url = "viewTranscript.php?chatId="+chatId;
	var params = "location=0,status=0,scrollbars=0, width=410,height=400";
	mywindow = window.open (url, "ChatTranscript",params);
	mywindow.moveTo(0,0);	
}

function openOperatorChatTranscript(chatId)
{
	var url = "../viewTranscript.php?chatId="+chatId;
	var params = "location=0,status=0,scrollbars=0, width=410,height=500";
	mywindow = window.open (url, "OperatorChatTranscript",params);
	mywindow.moveTo(0,0);	
}


function openNewWindow(url)
{
	//var url = url+ "/admin/html_alldepts.php?cmpid="+<?=$cmpid?>;
	var params = "location=0,status=0,scrollbars=1, width=410,height=400";
	mywindow = window.open (url, "newWin",params);
	mywindow.moveTo(0,0);	
}

function checkEmailTranscript()
{ 
	//alert("jjj");	//validate email id
		if(isBadEmail(document.frm_transcript.email.value))
		{
			alert("Invalid Email Id");
			document.frm_transcript.email.focus();
			return false;
		}
		var message = document.frm_transcript.message.value;
		var newMsg =  message.replace(/ /g,"");
		if(newMsg=="")
		{
			alert("Please enter the message");
			document.frm_transcript.message.focus();
			return false;
		}
		document.frm_transcript.action.value='mail';
		document.frm_transcript.action="viewTranscript.php?chatId="; 
		document.frm_transcript.submit;
		return true;
}


 
function operatorChatWindow(operatorId)
{
	var d = new Date();
	var time = d.getTime();
	var url = "../chat/index.php?act=Operator&oid="+operatorId;
	var params = "location=0,status=0,scrollbars=1, width=600,height=300";
	//window.open (url, "mywindow"+time,params);
	var x = window.open (url, "opmonitor",params);
	x.focus();
}

function open_popups(page,params){
	//alert("here");
	//alert(page+title);
	//var params = "height="+h+",width="+w;
	mywindow=window.open(page,'',params);
	mywindow.moveTo(0,0);
}

	function check_ticket(msg1,msg2)
	{ 

		if ( ( document.sendmail.user.value == "" ) || ( document.sendmail.email.value == "" )
			|| ( document.sendmail.subject.value == "" ) || ( document.sendmail.message.value == "" ) )
			//alert( "Supply Values for all fields" ) ;
			alert(msg1);
		else if(isBadEmail(document.sendmail.email.value)) 
			//alert( "Invalid Email Address" ) ; 
			alert(msg2);
		else
			document.sendmail.submit() ;
	}
	


	/*----------------------------------------------------------------
	Description   :- function to confirm the deletion of a record in dept,operator
	Programmer    :- IKB
	Last Modified :- 01/JAN/2007
	-------------------------------------------------------------------*/
	function confirmStatusUpdate(page,name,id,mode,msg)
	{
		if(confirm(msg+ name + "?"))
		window.location = page + "?" +mode;

	}

   function password_validation(e,error_dis)
	{
		var key;
		var keychar;
		
		if (window.event)
		key = window.event.keyCode;
		else if (e)
		key = e.which;
		else
		return true;
		
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
		else if ((("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_*").indexOf(keychar) > -1) )
		return true;
		else
		{
		alert(error_dis);	
		return false;
		}
	}
	function sortbizcard(id,sortby,sorting,special,searchstr){ 
		var url = "Admin_bizcard_service.php?action=cardsort&sort="+sorting +"&sortby="+sortby;
		if(special) url += "&page="+special+"&search="+searchstr; 
		ajaxpage(url,id);
	}

	function PopulateCategory(type)
	{
		if(type == 'business') {
			document.getElementById('personal').value='';
			receiverId = document.getElementById('business').value;
		} else {
			document.getElementById('business').value='';
			receiverId = document.getElementById('personal').value;
		}
		
		var url = "list_merchant_ticket_category.php?receiverId="+receiverId;
		ajaxpage(url,'TD_category');
	}
	
	function SubmitMerchantTicket()
	{
		document.getElementById('categoryId').value = document.getElementById('category').value;
	}
	
	function SortTicketsByCategory(status)
	{
		categoryId = document.getElementById('category').value;
		window.location.href = "index.php?process=ticket_buyer&action=buyer&categoryId="+categoryId+"&status="+status;
	}	
