// JavaScript Document

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];}
}

//Alert message for deleting admin user

function deleteAdmin(id) 
{
	if(confirm("Are you sure you want to delete the Admin?")) {
	    document.form1.action="admin.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

//Alert message for deleting client

function deleteClient(id) 
{
	if(confirm("Are you sure you want to delete the Client?")) {
	    document.form1.action="clients.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteImage(id,clientdelid) 
{
	if(confirm("Are you sure you want to delete the Image?")) {
	    document.form1.action="images.php?action=delete&clientid="+id+"&delid="+clientdelid;
		document.form1.submit();
 	}  
}
// To validate admin form fields
function ImageValidate(action)
{
	if(action == "Modify"){
		document.frmadmin.action = "images.php";
	    document.frmadmin.submit();
	}else{
		if(FileValidate(document.getElementById("images_largefilename"),"please browse the large image for file upload")==false){ return false;}
		document.frmadmin.action = "images.php";
	    document.frmadmin.submit();
	}
}

function adminValidate() 
{
	if(SelectValidate(document.frmadmin.seladminsalutation," salutation")==false) { return false;	}
	if(TextValidate(document.frmadmin.txtadminname," Admin name")==false) { return false;	}
 	if(TextValidate(document.frmadmin.txtadminemail," email")==false) { return false;	}
	if(EmailValidate(document.frmadmin.txtadminemail," email")==false) { return false;	}
	if(TextValidate(document.frmadmin.txtadminusername," username")==false) { return false;	}
	if(TextValidate(document.frmadmin.pwdadminpassword," password")==false) { return false;	}
	if(TextValidate(document.frmadmin.pwdadminconfirmpassword," confrim password")==false) { return false;}
   	if(document.frmadmin.pwdadminconfirmpassword.value != document.frmadmin.pwdadminpassword.value){
		alert("Your password and confirm password does not match.");
		document.frmadmin.pwdadminconfirmpassword.focus();
		return false;
	}
	document.frmadmin.action = "admin.php";
	document.frmadmin.submit();
}

//To validate the client form field

function clientValidate(action)
{
	if(action == "Modify"){
		if(TextValidate(document.frmclient.txtclientname," Client name")==false) { return false;	}
		if(TextValidate(document.frmclient.txtdate," Date")==false) { return false;	}
		if(ValidateForm(document.frmclient.txtdate)==false){return false;}
		if(TextValidate(document.frmclient.txtdescription," Description")==false) { return false;	}		
		document.frmclient.action = "clients.php";
		document.frmclient.submit();		
	}else{
		if(TextValidate(document.frmclient.txtclientname," Client name")==false) { return false;	}
		if(TextValidate(document.frmclient.txtdate," Date")==false) { return false;	}
		if(ValidateForm(document.frmclient.txtdate)==false){return false;}
		if(TextValidate(document.frmclient.txtdescription," Description")==false) { return false;	}
		if(FileValidate(document.getElementById("clients_filename"),"please browse the small image for file upload")==false){ return false;}
		document.frmclient.action = "clients.php";
		document.frmclient.submit();
	}
}


// To validate change password form fields

function changePwdvalidate()
{
	var form_name=document.frmpassword;
	if(TextValidate(form_name.old_password,"Old Password")==false){return false;}
	if(TextValidate(form_name.new_password,"New Password")==false){return false;}
	if(TextValidate(form_name.confirm_password,"Confirm Password")==false){return false;}
	if(Comparetextboxes(form_name.new_password,form_name.confirm_password)==false){return false;}
}

//To validate forgot password form

function forgetValidate()
{
	var form_name=document.frmforget;
	if(TextValidate(form_name.txtemail,"Email")==false){return false;}
	if(TextValidate(form_name.txtusername,"User name")==false){return false;}
	document.frmforget.action = "forgot_password.php?status=submit";
	document.frmforget.submit();
}
// To call the page inside iframe

function callpage(pagename){
	var page=pagename+"?pagename="+pagename;
	//alert(page);
	window.frames.iframecontent.src=page;
	
}


function deleteMenu(id) {
	if(confirm("Are you sure you want to delete the menu?")) {
	    document.form1.action="menu.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}
	
// To validate 

function menuValidate() {
	if(TextValidate(document.frmmenu.txtmenutitle," Menu title")==false) { return false;	}
	if(TextValidate(document.frmmenu.txtmenulink," Menu link")==false) { return false;	}
	document.frmmenu.action = "menu.php";
	document.frmmenu.submit();
}

// To validate newsletter email

function newsletterValidate() {
	if(EmailValidate(document.frmnewsletter.txtemail,"Email Id") == false) { return false; }
	document.frmnewsletter.action = "contact.php";
	document.frmnewsletter.submit();
	
}

