function confirmMe(msg)
{
     var ans=confirm(msg);
	 if(ans!=1)
	 {
		 return false;
	 }
	  	return true;
	 
} 

function add_image(id, i) {
	if (document.getElementById(id + '_' + i).innerHTML.search('fileupload') == -1) 
	{
		
		document.getElementById(id + '_' + i).innerHTML = '<dt><label>File Name</label></dt>' +
       													  '<dd><input type="text" name="data[Files][][filedesc]" class="text"/></dd>' +
														  '<dt><label>Upload file' + (i+1) + '</label></dt>' +
														  '<dd><input type="file" name="data[Files][][file]" class="text" ' + 
														  'onchange="return add_image(\'' + id + '\', ' + (i+1) + ');"></dd>' + 
														  '<br /><span id="' + id + '_' + (i+1) + '"><\/span>\n';
	}
}

function add_file(id, i) {
	if (document.getElementById(id + '_' + i).innerHTML.search('fileupload') == -1) 
	{
		
		document.getElementById(id + '_' + i).innerHTML = '<dt><label>File Name</label></dt>' +
       													  '<dd><input type="text" name="data[Resource][][filename]" class="text"/></dd>' +
														  '<dt><label>File Description</label></dt>' +
														  '<dd><input type="text" name="data[Resource][][filedesc]" class="text"/></dd>' +
														  '<dt><label>Upload file' + (i+1) + '</label></dt>' +
														  '<dd><input type="file" name="data[Resource][][file]" class="text" ' + 
														  'onchange="return add_file(\'' + id + '\', ' + (i+1) + ');"></dd>' + 
														  '<br /><span id="' + id + '_' + (i+1) + '"><\/span>\n';
	}
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }

 		 return true;					
	}

function ValidateForm(){
	var emailID=document.enquiry.email;
	var customer=document.enquiry.name;
	
	if ((customer.value == null) || (customer.value =="")){
		alert("Please enter your Name");
		customer.focus();
		return false;
	}
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true;
 }
 
 
 function showProgress()
{

	$(document).ready(function(){
    
		/*$("#roomtype").click(function () { 
									   
			$.post("test.php", {id:rid}, function(data) {
				
				$("#roomno").html(data);
				
				$("#roomno").show("slow");
										});
			}); */
    
		$("#navButton").html('<img src="/img/loader-a.gif">');
		$("#content").submit();
		
  });

	
}

function dipswitch(id){
	$(document).ready(function(){
		var x=$("#item"+id);
		var y=x.attr("controller");
		var z=x.attr("currentstate");
		$.post("/admin/"+y+"/dipswitch/"+id+"/"+z,{},
			function(data){
				x.attr("src",z=="1"?"/img/exclamation.gif":"/img/tick.gif");
				x.attr("currentstate",z=="1"?"0":"1");
			}
		);
	});
}

function processPage(){
	$(document).ready(function() {
		$(".submit").html('<img src="/img/loader-a.gif">');
	});
}

function remove(id) {
    $(document).ready(function(){
        $.blockUI({message:null});
        var i = $("#item"+id);
        var t = i.attr("where");
        $.post("/admin/products/del/"+id+"/"+t,{},
            function(e) {
                i.remove();
                $.unblockUI();
            }
        );
    });
}
